-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add form legend and fieldset components
- Loading branch information
1 parent
48fcddc
commit 2a8ef78
Showing
11 changed files
with
146 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
import { form } from '@giantnodes/theme' | ||
|
||
import type * as Polymophic from '~/utilities/polymorphic' | ||
|
||
const __ELEMENT_TYPE__ = 'fieldset' | ||
|
||
type ComponentOwnProps = unknown | ||
|
||
type ComponentProps<TElement extends React.ElementType = typeof __ELEMENT_TYPE__> = Polymophic.ComponentPropsWithRef< | ||
TElement, | ||
ComponentOwnProps | ||
> | ||
|
||
type ComponentType = <TElement extends React.ElementType = typeof __ELEMENT_TYPE__>( | ||
props: ComponentProps<TElement> | ||
) => React.ReactNode | ||
|
||
const Component: ComponentType = React.forwardRef( | ||
<TElement extends React.ElementType = typeof __ELEMENT_TYPE__>( | ||
props: ComponentProps<TElement>, | ||
ref: Polymophic.Ref<TElement> | ||
) => { | ||
const { as, children, className, ...rest } = props | ||
|
||
const Element = as ?? __ELEMENT_TYPE__ | ||
|
||
const slots = React.useMemo(() => form({}), []) | ||
|
||
const component = React.useMemo( | ||
() => ({ | ||
className: slots.fieldset({ className }), | ||
...rest, | ||
}), | ||
[className, slots, rest] | ||
) | ||
|
||
return ( | ||
<Element {...component} ref={ref}> | ||
{children} | ||
</Element> | ||
) | ||
} | ||
) | ||
|
||
export type { ComponentOwnProps as FormFieldSetOwnProps, ComponentProps as FormFieldSetProps } | ||
export default Component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
import { form } from '@giantnodes/theme' | ||
|
||
import type * as Polymophic from '~/utilities/polymorphic' | ||
|
||
const __ELEMENT_TYPE__ = 'legend' | ||
|
||
type ComponentOwnProps = unknown | ||
|
||
type ComponentProps<TElement extends React.ElementType = typeof __ELEMENT_TYPE__> = Polymophic.ComponentPropsWithRef< | ||
TElement, | ||
ComponentOwnProps | ||
> | ||
|
||
type ComponentType = <TElement extends React.ElementType = typeof __ELEMENT_TYPE__>( | ||
props: ComponentProps<TElement> | ||
) => React.ReactNode | ||
|
||
const Component: ComponentType = React.forwardRef( | ||
<TElement extends React.ElementType = typeof __ELEMENT_TYPE__>( | ||
props: ComponentProps<TElement>, | ||
ref: Polymophic.Ref<TElement> | ||
) => { | ||
const { as, children, className, ...rest } = props | ||
|
||
const Element = as ?? __ELEMENT_TYPE__ | ||
|
||
const slots = React.useMemo(() => form({}), []) | ||
|
||
const component = React.useMemo( | ||
() => ({ | ||
className: slots.legend({ className }), | ||
...rest, | ||
}), | ||
[className, slots, rest] | ||
) | ||
|
||
return ( | ||
<Element {...component} ref={ref}> | ||
{children} | ||
</Element> | ||
) | ||
} | ||
) | ||
|
||
export type { ComponentOwnProps as FormLegendOwnProps, ComponentProps as FormLegendSetProps } | ||
export default Component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export { default as Root } from '~/components/form/Form' | ||
export { default as Caption } from '~/components/form/FormCaption' | ||
export { default as Feedback } from '~/components/form/FormFeedback' | ||
export { default as FieldSet } from '~/components/form/FormFieldSet' | ||
export { default as Group } from '~/components/form/FormGroup' | ||
export { default as Label } from '~/components/form/FormLabel' | ||
export { default as Legend } from '~/components/form/FormLegend' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export type * from '~/components/form/Form' | ||
export type * from '~/components/form/FormCaption' | ||
export type * from '~/components/form/FormFeedback' | ||
export type * from '~/components/form/FormFieldSet' | ||
export type * from '~/components/form/FormGroup' | ||
export type * from '~/components/form/FormLabel' | ||
export type * from '~/components/form/FormLegend' | ||
|
||
export * as Form from '~/components/form/component.parts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters