Skip to content

Commit

Permalink
feat(ui/website): render shadcn component from lib
Browse files Browse the repository at this point in the history
  • Loading branch information
MFarabi619 committed Nov 19, 2024
1 parent 193bb42 commit 8784418
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 940 deletions.
869 changes: 0 additions & 869 deletions apps/website/app/nx-welcome.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion apps/website/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const links: LinksFunction = () => [

export default function App() {
return (
<html lang="en">
<html
lang="en"
className="dark"
>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
33 changes: 29 additions & 4 deletions apps/website/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import type { MetaFunction } from '@netlify/remix-runtime'
import NxWelcome from '../nx-welcome'
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '@shadcn/ui/accordion'
import { Calendar } from '@shadcn/ui/calendar'

import { useState } from 'react'

export const meta: MetaFunction = () => {
return [
{ title: 'cuHacking 2025' },
{ name: 'description', content: 'Carleton University\'s Official Hackathon.' },
]
}

export default function Index() {
const [date, setDate] = useState<Date | undefined>(new Date())

return (
<div>
<NxWelcome title="Website" />
<div className="container mx-auto flex justify-center">
<div className="max-w-lg">
<Calendar
mode="single"
selected={date}
onSelect={setDate}
className="rounded-md border shadow"
/>

<Accordion type="single" collapsible>
<AccordionItem value="item-1">
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionContent>
Yes. It adheres to the WAI-ARIA design pattern.
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
</div>
)
}
Binary file modified apps/website/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cssVariables": true
},
"aliases": {
"components": "@cuhacking/ui",
"components": "@shadcn",
"utils": "@cuhacking/utils"
}
}
5 changes: 4 additions & 1 deletion libs/shared/ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"tags": [],
"targets": {
"add-component": {
"executor": "@nx-extend/shadcn-ui:add"
"executor": "@nx-extend/shadcn-ui:add",
"options": {
"cwd": "libs/shared/ui/src/shadcn"
}
}
}
}
56 changes: 56 additions & 0 deletions libs/shared/ui/src/shadcn/accordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { cn } from '@cuhacking/utils'
import * as AccordionPrimitive from '@radix-ui/react-accordion'
import { ChevronDown } from 'lucide-react'

import * as React from 'react'

const Accordion = AccordionPrimitive.Root

const AccordionItem = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
className={cn('border-b', className)}
{...props}
/>
))
AccordionItem.displayName = 'AccordionItem'

const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Header className="flex">
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
'flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180',
className,
)}
{...props}
>
{children}
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
))
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName

const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
{...props}
>
<div className={cn('pb-4 pt-0', className)}>{children}</div>
</AccordionPrimitive.Content>
))

AccordionContent.displayName = AccordionPrimitive.Content.displayName

export { Accordion, AccordionContent, AccordionItem, AccordionTrigger }
56 changes: 56 additions & 0 deletions libs/shared/ui/src/shadcn/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { cn } from '@cuhacking/utils'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'

import * as React from 'react'

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 }
66 changes: 66 additions & 0 deletions libs/shared/ui/src/shadcn/calendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { cn } from '@cuhacking/utils'
import { buttonVariants } from '@shadcn/ui/button'
import { ChevronLeft, ChevronRight } from 'lucide-react'

import * as React from 'react'
import { DayPicker } from 'react-day-picker'

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={{
// eslint-disable-next-line react/no-nested-components, unused-imports/no-unused-vars
IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" />,
// eslint-disable-next-line react/no-nested-components, unused-imports/no-unused-vars
IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" />,
}}
{...props}
/>
)
}
Calendar.displayName = 'Calendar'

export { Calendar }
2 changes: 1 addition & 1 deletion libs/shared/ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
"lint:inspect-build": "pnpx @eslint/config-inspector build --outDir dist/config-inspector"
},
"dependencies": {
"@radix-ui/react-accordion": "^1.2.1",
"@radix-ui/react-slot": "^1.1.0",
"@remix-run/node": "2.14.0",
"@remix-run/react": "2.14.0",
"@remix-run/serve": "2.14.0",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"isbot": "^4.4.0",
"next": "14.2.3",
"react": "^18.3.1",
"react-day-picker": "8.10.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 8784418

Please sign in to comment.