Skip to content

Commit

Permalink
chore: refactor - move stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDinh committed Mar 14, 2024
1 parent 49aef9a commit 23ea2a3
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 198 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
src/components/*
src/lib/*
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'react-refresh/only-export-components': 'off',
},
}
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
src/components/*
src/lib/*
7 changes: 4 additions & 3 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
"components": "@/features/primitive/components",
"ui": "@/features/primitive/components",
"utils": "@/features/primitive/utils"
}
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './App.css'
import { routes } from './App.routes'
import { RouterProvider, createBrowserRouter } from 'react-router-dom'
import { ThemeProvider } from './components/theme-provider'
import { ThemeProvider } from './features/theme/context/theme-provider'

const router = createBrowserRouter(routes)

Expand Down
56 changes: 0 additions & 56 deletions src/components/ui/button.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions src/components/ui/input.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/features/layout/pages/layout-page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ReactNode } from 'react'
import { TemplatedNavLink } from '../../routing/components/templated-nav-link/templated-nav-link'
import { Urls } from '../../../routes/urls'
import { NavigationMenu, NavigationMenuItem, NavigationMenuLink, NavigationMenuList } from '@/components/ui/navigation-menu'
import { cn } from '@/lib/utils'
import { ThemeToggle } from '@/components/theme-toggle'
import { NavigationMenu, NavigationMenuItem, NavigationMenuLink, NavigationMenuList } from '@/features/primitive/components/navigation-menu'
import { cn } from '@/features/primitive/utils'
import { ThemeToggle } from '@/features/theme/components/theme-toggle'
import { Header } from '../components/header'

export interface LayoutPageProps {
Expand Down
29 changes: 29 additions & 0 deletions src/features/primitive/components/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react'
import { cva, type VariantProps } from 'class-variance-authority'

import { cn } from '@/features/primitive/utils'

const badgeVariants = cva(
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
{
variants: {
variant: {
default: 'border-transparent bg-primary text-primary-foreground hover:bg-primary/80',
secondary: 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',
destructive: 'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',
outline: 'text-foreground',
},
},
defaultVariants: {
variant: 'default',
},
}
)

export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return <div className={cn(badgeVariants({ variant }), className)} {...props} />
}

export { Badge, badgeVariants }
43 changes: 43 additions & 0 deletions src/features/primitive/components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'

import { cn } from '@/features/primitive/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 }
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from "react"
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
import { Check, ChevronRight, Circle } from "lucide-react"
import * as React from 'react'
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
import { Check, ChevronRight, Circle } from 'lucide-react'

import { cn } from "@/lib/utils"
import { cn } from '@/features/primitive/utils'

const DropdownMenu = DropdownMenuPrimitive.Root

Expand All @@ -25,8 +25,8 @@ const DropdownMenuSubTrigger = React.forwardRef<
<DropdownMenuPrimitive.SubTrigger
ref={ref}
className={cn(
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
inset && "pl-8",
'focus:bg-accent data-[state=open]:bg-accent flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none',

Check warning on line 28 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `ocus:bg-accent·data-[state=open]:bg-accent·flex·cursor-default·select-none·items-center·rounded-sm·px-2·py-1.5·text-sm·outline-none` with `lex·cursor-default·select-none·items-center·rounded-sm·px-2·py-1.5·text-sm·outline-none·focus:bg-accent·data-[state=open]:bg-accent`
inset && 'pl-8',
className
)}
{...props}
Expand All @@ -35,8 +35,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
<ChevronRight className="ml-auto h-4 w-4" />
</DropdownMenuPrimitive.SubTrigger>
))
DropdownMenuSubTrigger.displayName =
DropdownMenuPrimitive.SubTrigger.displayName
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName

const DropdownMenuSubContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
Expand All @@ -45,14 +44,13 @@ const DropdownMenuSubContent = React.forwardRef<
<DropdownMenuPrimitive.SubContent
ref={ref}
className={cn(
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-lg',

Check warning on line 47 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `bg-popover·text-popover-foreground·data-[state=open]:animate-in·data-[state=closed]:animate-out·data-[state=closed]:fade-out-0·data-[state=open]:fade-in-0·data-[state=closed]:zoom-out-95·data-[state=open]:zoom-in-95·data-[side=bottom]:slide-in-from-top-2·data-[side=left]:slide-in-from-right-2·data-[side=right]:slide-in-from-left-2·data-[side=top]:slide-in-from-bottom-2·z-50·min-w-[8rem]·overflow-hidden·rounded-md·border·p-1·shadow-lg` with `z-50·min-w-[8rem]·overflow-hidden·rounded-md·border·bg-popover·p-1·text-popover-foreground·shadow-lg·data-[state=open]:animate-in·data-[state=closed]:animate-out·data-[state=closed]:fade-out-0·data-[state=open]:fade-in-0·data-[state=closed]:zoom-out-95·data-[state=open]:zoom-in-95·data-[side=bottom]:slide-in-from-top-2·data-[side=left]:slide-in-from-right-2·data-[side=right]:slide-in-from-left-2·data-[side=top]:slide-in-from-bottom-2`
className
)}
{...props}
/>
))
DropdownMenuSubContent.displayName =
DropdownMenuPrimitive.SubContent.displayName
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName

const DropdownMenuContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
Expand All @@ -63,7 +61,7 @@ const DropdownMenuContent = React.forwardRef<
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-md',

Check warning on line 64 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `bg-popover·text-popover-foreground·data-[state=open]:animate-in·data-[state=closed]:animate-out·data-[state=closed]:fade-out-0·data-[state=open]:fade-in-0·data-[state=closed]:zoom-out-95·data-[state=open]:zoom-in-95·data-[side=bottom]:slide-in-from-top-2·data-[side=left]:slide-in-from-right-2·data-[side=right]:slide-in-from-left-2·data-[side=top]:slide-in-from-bottom-2·z-50·min-w-[8rem]·overflow-hidden·rounded-md·border·p-1·shadow-md` with `z-50·min-w-[8rem]·overflow-hidden·rounded-md·border·bg-popover·p-1·text-popover-foreground·shadow-md·data-[state=open]:animate-in·data-[state=closed]:animate-out·data-[state=closed]:fade-out-0·data-[state=open]:fade-in-0·data-[state=closed]:zoom-out-95·data-[state=open]:zoom-in-95·data-[side=bottom]:slide-in-from-top-2·data-[side=left]:slide-in-from-right-2·data-[side=right]:slide-in-from-left-2·data-[side=top]:slide-in-from-bottom-2`
className
)}
{...props}
Expand All @@ -81,8 +79,8 @@ const DropdownMenuItem = React.forwardRef<
<DropdownMenuPrimitive.Item
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
inset && "pl-8",
'focus:bg-accent focus:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50',

Check warning on line 82 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `focus:bg-accent·focus:text-accent-foreground·relative·flex·cursor-default·select-none·items-center·rounded-sm·px-2·py-1.5·text-sm·outline-none·transition-colors·` with `relative·flex·cursor-default·select-none·items-center·rounded-sm·px-2·py-1.5·text-sm·outline-none·transition-colors·focus:bg-accent·focus:text-accent-foreground·`
inset && 'pl-8',
className
)}
{...props}
Expand All @@ -97,7 +95,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
<DropdownMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
'focus:bg-accent focus:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50',

Check warning on line 98 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `focus:bg-accent·focus:text-accent-foreground·relative·flex·cursor-default·select-none·items-center·rounded-sm·py-1.5·pl-8·pr-2·text-sm·outline-none·transition-colors` with `relative·flex·cursor-default·select-none·items-center·rounded-sm·py-1.5·pl-8·pr-2·text-sm·outline-none·transition-colors·focus:bg-accent·focus:text-accent-foreground`
className
)}
checked={checked}
Expand All @@ -111,8 +109,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
{children}
</DropdownMenuPrimitive.CheckboxItem>
))
DropdownMenuCheckboxItem.displayName =
DropdownMenuPrimitive.CheckboxItem.displayName
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName

const DropdownMenuRadioItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
Expand All @@ -121,7 +118,7 @@ const DropdownMenuRadioItem = React.forwardRef<
<DropdownMenuPrimitive.RadioItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
'focus:bg-accent focus:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50',

Check warning on line 121 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `focus:bg-accent·focus:text-accent-foreground·relative·flex·cursor-default·select-none·items-center·rounded-sm·py-1.5·pl-8·pr-2·text-sm·outline-none·transition-colors` with `relative·flex·cursor-default·select-none·items-center·rounded-sm·py-1.5·pl-8·pr-2·text-sm·outline-none·transition-colors·focus:bg-accent·focus:text-accent-foreground`
className
)}
{...props}
Expand All @@ -142,42 +139,22 @@ const DropdownMenuLabel = React.forwardRef<
inset?: boolean
}
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Label
ref={ref}
className={cn(
"px-2 py-1.5 text-sm font-semibold",
inset && "pl-8",
className
)}
{...props}
/>
<DropdownMenuPrimitive.Label ref={ref} className={cn('px-2 py-1.5 text-sm font-semibold', inset && 'pl-8', className)} {...props} />
))
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName

const DropdownMenuSeparator = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.Separator
ref={ref}
className={cn("-mx-1 my-1 h-px bg-muted", className)}
{...props}
/>
<DropdownMenuPrimitive.Separator ref={ref} className={cn('bg-muted -mx-1 my-1 h-px', className)} {...props} />

Check warning on line 150 in src/features/primitive/components/dropdown-menu.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `bg-muted·-mx-1·my-1·h-px` with `-mx-1·my-1·h-px·bg-muted`
))
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName

const DropdownMenuShortcut = ({
className,
...props
}: React.HTMLAttributes<HTMLSpanElement>) => {
return (
<span
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
{...props}
/>
)
const DropdownMenuShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {
return <span className={cn('ml-auto text-xs tracking-widest opacity-60', className)} {...props} />
}
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
DropdownMenuShortcut.displayName = 'DropdownMenuShortcut'

export {
DropdownMenu,
Expand Down
22 changes: 22 additions & 0 deletions src/features/primitive/components/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react'

import { cn } from '@/features/primitive/utils'

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

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

Check warning on line 12 in src/features/primitive/components/input.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

Replace `border-input·bg-background·ring-offset-background·placeholder:text-muted-foreground·focus-visible:ring-ring·flex·h-10·w-full·rounded-md·border·px-3·py-2·text-sm·file:border-0·file:bg-transparent·file:text-sm·file:font-medium·focus-visible:outline-none·focus-visible:ring-2` with `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`
className
)}
ref={ref}
{...props}
/>
)
})
Input.displayName = 'Input'

export { Input }
Loading

0 comments on commit 23ea2a3

Please sign in to comment.