-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,45 @@ | ||
import { cva, VariantProps } from 'class-variance-authority' | ||
|
||
export const inputStyles = cva( | ||
[ | ||
'h-sz-44', | ||
'box-border', | ||
'outline-none', | ||
'text-ellipsis', | ||
'peer', | ||
'text-body-1', | ||
'cursor-auto', | ||
'caret-neutral', | ||
'appearance-none', | ||
'autofill:shadow-surface', | ||
'autofill:shadow-[inset_0_0_0px_1000px]', | ||
'bg-surface', | ||
'text-on-surface', | ||
'disabled:bg-on-surface/dim-5', | ||
'disabled:text-on-surface/dim-3', | ||
'disabled:cursor-not-allowed', | ||
'disabled:border-on-surface/dim-3', | ||
], | ||
{ | ||
variants: { | ||
intent: { | ||
none: [''], | ||
neutral: [ | ||
'border-sm', | ||
'border-outline', | ||
'ring-outline-high', | ||
'hover:border-outline-high', | ||
'focus:ring-1', | ||
'focus:border-outline-high', | ||
], | ||
success: ['border-sm', 'border-success', 'ring-success', 'focus:ring-1'], | ||
alert: ['border-sm', 'border-alert', 'ring-alert', 'focus:ring-1'], | ||
error: ['border-sm', 'border-error', 'ring-error', 'focus:ring-1'], | ||
}, | ||
isLeftElementVisible: { | ||
true: ['pl-3xl'], | ||
false: [], | ||
}, | ||
isRightElementVisible: { | ||
true: ['pr-3xl'], | ||
false: [], | ||
}, | ||
isLeftAddonVisible: { | ||
true: ['pl-md', 'border-l-none', 'rounded-l-none'], | ||
false: ['rounded-l-lg'], | ||
}, | ||
isRightAddonVisible: { | ||
true: ['pr-md', 'border-r-none', 'rounded-r-none'], | ||
false: ['rounded-r-lg'], | ||
}, | ||
export const inputStyles = cva([], { | ||
variants: { | ||
intent: { | ||
neutral: [], | ||
success: [], | ||
alert: [], | ||
error: [], | ||
}, | ||
isGrouped: { | ||
true: [], | ||
false: ['border-sm', 'focus:ring-1'], | ||
}, | ||
}, | ||
compoundVariants: [ | ||
{ | ||
intent: 'neutral', | ||
isGrouped: false, | ||
class: [ | ||
'border-outline', | ||
'ring-outline-high', | ||
'hover:border-outline-high', | ||
'focus:border-outline-high', | ||
], | ||
}, | ||
{ | ||
intent: 'success', | ||
isGrouped: false, | ||
class: ['border-success', 'ring-success'], | ||
}, | ||
compoundVariants: [ | ||
{ | ||
isLeftElementVisible: false, | ||
isLeftAddonVisible: false, | ||
class: 'pl-lg', | ||
}, | ||
{ | ||
isRightElementVisible: false, | ||
isRightAddonVisible: false, | ||
class: 'pr-lg', | ||
}, | ||
], | ||
} | ||
) | ||
{ | ||
intent: 'alert', | ||
isGrouped: false, | ||
class: ['border-alert', 'ring-alert'], | ||
}, | ||
{ | ||
intent: 'error', | ||
isGrouped: false, | ||
class: ['border-error', 'ring-error'], | ||
}, | ||
], | ||
}) | ||
|
||
export type InputStylesProps = VariantProps<typeof inputStyles> |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { cva, VariantProps } from 'class-variance-authority' | ||
|
||
export const inputGroupStyles = cva(['relative', 'inline-flex']) | ||
export const inputGroupStyles = cva(['relative', 'inline-flex', 'w-full']) | ||
|
||
export type InputGroupStylesProps = VariantProps<typeof inputGroupStyles> |
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,58 @@ | ||
import { cva, VariantProps } from 'class-variance-authority' | ||
|
||
export const inputPrimitiveStyles = cva( | ||
[ | ||
'peer', | ||
'box-border', | ||
'h-sz-44', | ||
'w-full', | ||
'outline-none', | ||
'appearance-none', | ||
'bg-surface', | ||
'text-on-surface', | ||
'text-body-1', | ||
'text-ellipsis', | ||
'cursor-auto', | ||
'caret-neutral', | ||
'autofill:shadow-surface', | ||
'autofill:shadow-[inset_0_0_0px_1000px]', | ||
'disabled:bg-on-surface/dim-5', | ||
'disabled:text-on-surface/dim-3', | ||
'disabled:cursor-not-allowed', | ||
'disabled:border-on-surface/dim-3', | ||
], | ||
{ | ||
variants: { | ||
isLeftElementVisible: { | ||
true: ['pl-3xl'], | ||
false: [], | ||
}, | ||
isRightElementVisible: { | ||
true: ['pr-3xl'], | ||
false: [], | ||
}, | ||
isLeftAddonVisible: { | ||
true: ['pl-md', 'border-l-none', 'rounded-l-none'], | ||
false: ['rounded-l-lg'], | ||
}, | ||
isRightAddonVisible: { | ||
true: ['pr-md', 'border-r-none', 'rounded-r-none'], | ||
false: ['rounded-r-lg'], | ||
}, | ||
}, | ||
compoundVariants: [ | ||
{ | ||
isLeftElementVisible: false, | ||
isLeftAddonVisible: false, | ||
class: 'pl-lg', | ||
}, | ||
{ | ||
isRightElementVisible: false, | ||
isRightAddonVisible: false, | ||
class: 'pr-lg', | ||
}, | ||
], | ||
} | ||
) | ||
|
||
export type InputPrimitiveStylesProps = VariantProps<typeof inputPrimitiveStyles> |
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 @@ | ||
import { useFormFieldState } from '@spark-ui/form-field' | ||
import { ComponentPropsWithoutRef, forwardRef } from 'react' | ||
|
||
import { useInputGroup } from './InputGroupContext' | ||
import { inputPrimitiveStyles, InputPrimitiveStylesProps } from './InputPrimitive.styles' | ||
|
||
export interface InputPrimitiveProps | ||
extends ComponentPropsWithoutRef<'input'>, | ||
Omit< | ||
InputPrimitiveStylesProps, | ||
| 'isLeftAddonVisible' | ||
| 'isRightAddonVisible' | ||
| 'isLeftElementVisible' | ||
| 'isRightElementVisible' | ||
> {} | ||
|
||
export const InputPrimitive = forwardRef<HTMLInputElement, InputPrimitiveProps>( | ||
({ className, disabled: disabledProp, ...others }, ref) => { | ||
const field = useFormFieldState() | ||
const group = useInputGroup() || {} | ||
|
||
const { isLeftAddonVisible, isRightAddonVisible, isLeftElementVisible, isRightElementVisible } = | ||
group | ||
const { id, name, isInvalid, isRequired, description } = field | ||
const isDisabled = group.isDisabled ?? disabledProp | ||
|
||
return ( | ||
<input | ||
ref={ref} | ||
id={id} | ||
name={name} | ||
className={inputPrimitiveStyles({ | ||
className, | ||
isLeftAddonVisible: !!isLeftAddonVisible, | ||
isRightAddonVisible: !!isRightAddonVisible, | ||
isLeftElementVisible: !!isLeftElementVisible, | ||
isRightElementVisible: !!isRightElementVisible, | ||
})} | ||
disabled={isDisabled} | ||
required={isRequired} | ||
aria-describedby={description} | ||
aria-invalid={isInvalid} | ||
{...others} | ||
/> | ||
) | ||
} | ||
) | ||
|
||
InputPrimitive.displayName = 'InputPrimitive' |
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