Skip to content

Commit

Permalink
feat: expose a class name utility that can be consumed
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILLIPS71 committed Jun 19, 2024
1 parent 3f75e54 commit 591b65f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
"dependencies": {
"@giantnodes/theme": "workspace:*",
"@react-aria/utils": "^3.24.1",
"clsx": "^2.1.1",
"class-variance-authority": "^0.7.0",
"next-themes": "^0.3.0",
"react-aria": "^3.33.1",
"react-aria-components": "^1.2.1",
"tailwind-merge": "^2.3.0",
"tailwindcss-react-aria-components": "^1.1.3"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/form/FormFeedback.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client'

import React from 'react'
import clsx from 'clsx'

import type * as Polymophic from '~/utilities/polymorphic'
import { useFormGroupContext } from '~/components/form/use-form-group.hook'
import { cn } from '~/utilities'

const __ELEMENT_TYPE__ = 'span'

Expand Down Expand Up @@ -37,7 +37,7 @@ const Component: ComponentType = React.forwardRef(
const component = React.useMemo<React.ComponentPropsWithoutRef<typeof __ELEMENT_TYPE__>>(
() => ({
className: context?.slots.feedback({
class: clsx(className, { hidden: type !== context.feedback }),
class: cn(className, { hidden: type !== context.feedback }),
status: context.status,
}),
...rest,
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import type { InputVariantProps } from '@giantnodes/theme'
import type { InputProps } from 'react-aria-components'
import React from 'react'
import clsx from 'clsx'
import { Input } from 'react-aria-components'

import type * as Polymophic from '~/utilities/polymorphic'
import { useFormGroupContext } from '~/components/form/use-form-group.hook'
import { useInput, useInputContext } from '~/components/input/use-input.hook'
import { cn } from '~/utilities'

const __ELEMENT_TYPE__ = 'input'

Expand Down Expand Up @@ -47,7 +47,7 @@ const Component: ComponentType = React.forwardRef(
name: group?.name,
onChange: group?.onChange,
onBlur: group?.onBlur,
className: slots.input({ className: clsx(className) }),
className: slots.input({ className: cn(className) }),
...group?.fieldProps,
...rest,
}),
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/utilities/class-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { cx } from 'class-variance-authority'
import { twMerge } from 'tailwind-merge'

export const cn = (...inputs: Parameters<typeof cx>) => twMerge(cx(inputs))
1 change: 1 addition & 0 deletions packages/react/src/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from '~/utilities/class-name'
export * from '~/utilities/types'
33 changes: 30 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit 591b65f

Please sign in to comment.