-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from omnifed/278-feature-update-icon-to-suppo…
…rt-starticon 278 feature update icon to support starticon
- Loading branch information
Showing
11 changed files
with
194 additions
and
19 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
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 |
---|---|---|
@@ -1,38 +1,49 @@ | ||
'use client' | ||
|
||
import type { InputHTMLAttributes } from 'react' | ||
import type { InputHTMLAttributes, ReactNode } from 'react' | ||
import { WarningFilled } from '@cerberus/icons' | ||
import { input } from '@cerberus/styled-system/recipes' | ||
import { cx, type RecipeVariantProps } from '@cerberus/styled-system/css' | ||
import { useFieldContext } from '../context/field' | ||
import { Show } from './Show' | ||
|
||
export type InputRecipeProps = RecipeVariantProps<typeof input> | ||
|
||
export interface InputBaseProps | ||
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'size'> { | ||
describedBy?: string | ||
id: string | ||
startIcon?: ReactNode | ||
endIcon?: ReactNode | ||
} | ||
export type InputProps = InputBaseProps & InputRecipeProps | ||
|
||
export function Input(props: InputProps) { | ||
const { describedBy, size, ...nativeProps } = props | ||
const { describedBy, size, startIcon, endIcon, ...nativeProps } = props | ||
const inputStyles = input({ size }) | ||
const { invalid, ...fieldStates } = useFieldContext() | ||
const hasEndIcon = Boolean(endIcon) | ||
|
||
return ( | ||
<div className={inputStyles.root}> | ||
<Show when={Boolean(startIcon)}> | ||
<span className={inputStyles.startIcon}>{startIcon}</span> | ||
</Show> | ||
|
||
<input | ||
{...nativeProps} | ||
{...fieldStates} | ||
{...(describedBy && { 'aria-describedby': describedBy })} | ||
{...(invalid && { 'aria-invalid': true })} | ||
data-start-icon={Boolean(startIcon)} | ||
className={cx('peer', nativeProps.className, inputStyles.input)} | ||
/> | ||
|
||
<Show when={invalid}> | ||
<WarningFilled className={inputStyles.icon} /> | ||
</Show> | ||
<Show when={hasEndIcon && !invalid}> | ||
<span className={inputStyles.icon}>{endIcon}</span> | ||
</Show> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.