Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: add shadcn components and stories #120

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/design-system/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"aliases": {
"components": "@/ui",
"utils": "@/lib/utils"
"utils": "@/lib/utils",
"ui": "@/ui"
}
}
12 changes: 8 additions & 4 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@
],
"dependencies": {
"@radix-ui/react-accordion": "1.2.0",
"@radix-ui/react-checkbox": "1.0.4",
"@radix-ui/react-checkbox": "1.1.1",
"@radix-ui/react-collapsible": "1.0.3",
"@radix-ui/react-dialog": "1.0.4",
"@radix-ui/react-dropdown-menu": "2.0.5",
"@radix-ui/react-label": "2.0.2",
"@radix-ui/react-navigation-menu": "1.1.3",
"@radix-ui/react-label": "2.1.0",
"@radix-ui/react-navigation-menu": "1.2.0",
"@radix-ui/react-popover": "1.1.1",
"@radix-ui/react-progress": "1.0.3",
"@radix-ui/react-select": "1.2.2",
"@radix-ui/react-slider": "1.1.2",
"@radix-ui/react-slot": "1.1.0",
"@radix-ui/react-switch": "1.0.3",
"@radix-ui/react-tabs": "1.0.4",
"@radix-ui/react-toast": "1.1.4",
"@radix-ui/react-tooltip": "1.0.6",
"date-fns": "3.6.0",
"react-colorful": "5.6.1",
"react-countdown": "2.3.5"
"react-countdown": "2.3.5",
"react-day-picker": "8.10.1"
},
"devDependencies": {
"@ladle/react": "4.1.0",
Expand Down
19 changes: 13 additions & 6 deletions packages/design-system/src/ui/accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ import {
AccordionTrigger,
} from '@/ui/accordion'

export const Default = () => (
<Accordion type="single" collapsible>
import type { Story, StoryDefault } from '@ladle/react'

export default {
title: 'Shadcn/Accordion',
} satisfies StoryDefault

export const Default: Story = () => (
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="item-1">
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionContent>
Yes. It adheres to the WAI-ARIA design pattern.
</AccordionContent>
</AccordionItem>
<AccordionItem value="item-2">
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionTrigger>Is it styled?</AccordionTrigger>
<AccordionContent>
Yes. It adheres to the WAI-ARIA design pattern.
Yes. It comes with default styles that matches the other
components&apos; aesthetic.
</AccordionContent>
</AccordionItem>
<AccordionItem value="item-3">
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionTrigger>Is it animated?</AccordionTrigger>
<AccordionContent>
Yes. It adheres to the WAI-ARIA design pattern.
Yes. It's animated by default, but you can disable it if you prefer.
</AccordionContent>
</AccordionItem>
</Accordion>
Expand Down
9 changes: 9 additions & 0 deletions packages/design-system/src/ui/button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Button } from '@/ui/button'

import type { Story, StoryDefault } from '@ladle/react'

export default {
title: 'Shadcn/Button',
} satisfies StoryDefault

export const Default: Story = () => <Button>Button</Button>
56 changes: 56 additions & 0 deletions packages/design-system/src/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import * as React from 'react'

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

const buttonVariants = cva(
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
{
variants: {
variant: {
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
destructive:
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
outline:
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
secondary:
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
},
size: {
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
}
)

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'button'
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
}
)
Button.displayName = 'Button'

export { Button, buttonVariants }

Check warning on line 56 in packages/design-system/src/ui/button.tsx

View workflow job for this annotation

GitHub Actions / Lint

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
20 changes: 20 additions & 0 deletions packages/design-system/src/ui/calendar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Calendar } from '@/ui/calendar'
import type { Story, StoryDefault } from '@ladle/react'
import React from 'react'

export default {
title: 'Shadcn/Calendar',
} satisfies StoryDefault

export const Default: Story = () => {
const [date, setDate] = React.useState<Date | undefined>(new Date())

return (
<Calendar
mode="single"
selected={date}
onSelect={setDate}
className="rounded-md border shadow"
/>
)
}
64 changes: 64 additions & 0 deletions packages/design-system/src/ui/calendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as React from "react"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { DayPicker } from "react-day-picker"

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/ui/button"

export type CalendarProps = React.ComponentProps<typeof DayPicker>

function Calendar({
className,
classNames,
showOutsideDays = true,
...props
}: CalendarProps) {
return (
<DayPicker
showOutsideDays={showOutsideDays}
className={cn("p-3", className)}
classNames={{
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
month: "space-y-4",
caption: "flex justify-center pt-1 relative items-center",
caption_label: "text-sm font-medium",
nav: "space-x-1 flex items-center",
nav_button: cn(
buttonVariants({ variant: "outline" }),
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
),
nav_button_previous: "absolute left-1",
nav_button_next: "absolute right-1",
table: "w-full border-collapse space-y-1",
head_row: "flex",
head_cell:
"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]",
row: "flex w-full mt-2",
cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
day: cn(
buttonVariants({ variant: "ghost" }),
"h-9 w-9 p-0 font-normal aria-selected:opacity-100"
),
day_range_end: "day-range-end",
day_selected:
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
day_today: "bg-accent text-accent-foreground",
day_outside:
"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
day_disabled: "text-muted-foreground opacity-50",
day_range_middle:
"aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible",
...classNames,
}}
components={{
IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" />,
IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" />,
}}
{...props}
/>
)
}
Calendar.displayName = "Calendar"

export { Calendar }
18 changes: 18 additions & 0 deletions packages/design-system/src/ui/checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Checkbox } from '@/ui/checkbox'
import type { Story, StoryDefault } from '@ladle/react'

export default {
title: 'Shadcn/Checkbox',
} satisfies StoryDefault

export const Default: Story = () => (
<div className="flex items-center space-x-2">
<Checkbox id="terms" />
<label
htmlFor="terms"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
>
Accept terms and conditions
</label>
</div>
)
28 changes: 28 additions & 0 deletions packages/design-system/src/ui/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { Check } from "lucide-react"

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

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
className={cn("flex items-center justify-center text-current")}
>
<Check className="h-4 w-4" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = CheckboxPrimitive.Root.displayName

export { Checkbox }
9 changes: 9 additions & 0 deletions packages/design-system/src/ui/input.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Input } from '@/ui/input'

import type { Story, StoryDefault } from '@ladle/react'

export default {
title: 'Shadcn/Input',
} satisfies StoryDefault

export const Default: Story = () => <Input type="email" placeholder="Email" />
25 changes: 25 additions & 0 deletions packages/design-system/src/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react"

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

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = "Input"

export { Input }
17 changes: 17 additions & 0 deletions packages/design-system/src/ui/label.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Checkbox } from '@/ui/checkbox'
import { Label } from '@/ui/label'

import type { Story, StoryDefault } from '@ladle/react'

export default {
title: 'Shadcn/Label',
} satisfies StoryDefault

export const Default: Story = () => (
<div>
<div className="flex items-center space-x-2">
<Checkbox id="terms" />
<Label htmlFor="terms">Accept terms and conditions</Label>
</div>
</div>
)
24 changes: 24 additions & 0 deletions packages/design-system/src/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority"

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

const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
)

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName

export { Label }
Loading
Loading