Skip to content

Commit

Permalink
feat: add sheet (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
gularsson authored Oct 31, 2023
1 parent dd47bb3 commit e796781
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"css": "src/style/index.css",
"baseColor": "zinc",
"cssVariables": true
},
"aliases": {
"components": "src/components",
"utils": "@/lib/utils"
}
}
}
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"dependencies": {
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
140 changes: 140 additions & 0 deletions src/components/ui/sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"use client"

import * as React from "react"
import * as SheetPrimitive from "@radix-ui/react-dialog"
import { cva, type VariantProps } from "class-variance-authority"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"

const Sheet = SheetPrimitive.Root

const SheetTrigger = SheetPrimitive.Trigger

const SheetClose = SheetPrimitive.Close

const SheetPortal = SheetPrimitive.Portal

const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
ref={ref}
/>
))
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName

const sheetVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
bottom:
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
right:
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
},
},
defaultVariants: {
side: "right",
},
}
)

interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {}

const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(sheetVariants({ side }), className)}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
))
SheetContent.displayName = SheetPrimitive.Content.displayName

const SheetHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className
)}
{...props}
/>
)
SheetHeader.displayName = "SheetHeader"

const SheetFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
SheetFooter.displayName = "SheetFooter"

const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold text-foreground", className)}
{...props}
/>
))
SheetTitle.displayName = SheetPrimitive.Title.displayName

const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
SheetDescription.displayName = SheetPrimitive.Description.displayName

export {
Sheet,
SheetPortal,
SheetOverlay,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
}
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ export { Input, type InputProps } from '@/components/ui/input'
export { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
export { Checkbox } from '@/components/ui/checkbox'
export { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'
export {
Sheet,
SheetPortal,
SheetOverlay,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
} from '@/components/ui/sheet'
2 changes: 2 additions & 0 deletions src/showroom/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { AlertExample } from './components/alert'
import { ButtonExample } from './components/button'
import { InputExample } from './components/input'
import { PopoverExample } from './components/popover'
import { SheetExample } from './components/sheet'

export function App() {
return <div className="grid grid-cols-2 gap-4 gap-y-8 max-w-[900px] m-10">
<ButtonExample />
<InputExample />
<PopoverExample />
<AlertExample />
<SheetExample />
</div >
}
2 changes: 1 addition & 1 deletion src/showroom/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export function Code({ code }: { code: string | string[] }) {
{code}
</SyntaxHighlighter>
</div>
}
}
4 changes: 3 additions & 1 deletion src/showroom/components/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function AlertExample() {
<Alert>
<Waves className="h-4 w-4" />
<AlertTitle>Alert!</AlertTitle>
<AlertDescription>Place content of alertment here!</AlertDescription>
<AlertDescription>
Place content of alertment here!
</AlertDescription>
</Alert>`} />
</>
}
6 changes: 4 additions & 2 deletions src/showroom/components/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export function PopoverExample() {
</div>
<Code code={`<Popover>
<PopoverTrigger>Open</PopoverTrigger>
<PopoverContent>Place content for the popover here.</PopoverContent>
<PopoverContent>
Place content for the popover here.
</PopoverContent>
</Popover>`} />
</>
}
}
66 changes: 66 additions & 0 deletions src/showroom/components/sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Button } from '@/components/ui/button'
import { Header } from '../header'
import { Code } from '../code'
import { Menu } from 'lucide-react'

import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet"

export function SheetExample() {
return <>
<Header>Sheet</Header>

<div>
<Sheet>
<SheetTrigger asChild>
<Menu />
</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Title</SheetTitle>
<SheetDescription>
Descriptiontext
</SheetDescription>
</SheetHeader>
<div className="grid gap-4 py-4">
Body
</div>
<SheetFooter>
<SheetClose asChild>
<Button type="submit">Close</Button>
</SheetClose>
</SheetFooter>
</SheetContent>
</Sheet>
</div>
<Code code={`import { Menu } from '@ttab/elephant-ui/icons'
import { Button } from '@ttab/elephant-ui'
<Sheet>
<SheetTrigger asChild>
<Menu />
</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Title</SheetTitle>
<SheetDescription>
Description text
</SheetDescription>
</SheetHeader>
Body
<SheetFooter>
<SheetClose asChild>
<Button type="submit">Close</Button>
</SheetClose>
</SheetFooter>
</SheetContent>
</Sheet>`} />
</>
}

0 comments on commit e796781

Please sign in to comment.