4 changed files with 200 additions and 97 deletions
@ -0,0 +1,38 @@ |
|||||
|
import React from 'react'; |
||||
|
|
||||
|
type DefaultSelectProps = JSX.IntrinsicElements['select']; |
||||
|
|
||||
|
export interface SelectProps { |
||||
|
options: { |
||||
|
value: string; |
||||
|
label: string; |
||||
|
}[]; |
||||
|
label: string; |
||||
|
} |
||||
|
|
||||
|
export const Select = React.forwardRef< |
||||
|
HTMLSelectElement, |
||||
|
SelectProps & DefaultSelectProps |
||||
|
>(function Select( |
||||
|
{ options, label, id, ...props }: SelectProps & DefaultSelectProps, |
||||
|
ref, |
||||
|
) { |
||||
|
return ( |
||||
|
<div className="space-y-1"> |
||||
|
<label htmlFor={id} className="block text-sm font-medium dark:text-white"> |
||||
|
{label} |
||||
|
</label> |
||||
|
<select |
||||
|
ref={ref} |
||||
|
{...props} |
||||
|
className="block w-full p-2 border dark:border-gray-600 rounded-md shadow-sm dark:bg-secondaryDark" |
||||
|
> |
||||
|
{options.map((option) => ( |
||||
|
<option key={option.value} value={option.value}> |
||||
|
{option.label} |
||||
|
</option> |
||||
|
))} |
||||
|
</select> |
||||
|
</div> |
||||
|
); |
||||
|
}); |
||||
@ -1,26 +1,33 @@ |
|||||
import React from 'react'; |
import React from 'react'; |
||||
|
|
||||
import { Switch } from '@headlessui/react'; |
type DefaultInputProps = JSX.IntrinsicElements['input']; |
||||
|
|
||||
export interface ToggleProps { |
export interface ToggleProps { |
||||
enabled: boolean; |
label: string; |
||||
setEnabled: (state: boolean) => void; |
|
||||
} |
} |
||||
|
|
||||
export const Toggle = ({ enabled, setEnabled }: ToggleProps): JSX.Element => { |
export const Toggle = React.forwardRef< |
||||
|
HTMLInputElement, |
||||
|
ToggleProps & DefaultInputProps |
||||
|
>(function Input( |
||||
|
{ label, id, checked, ...props }: ToggleProps & DefaultInputProps, |
||||
|
ref, |
||||
|
) { |
||||
return ( |
return ( |
||||
<Switch |
<div className="flex flex-col"> |
||||
checked={enabled} |
<span className="block text-sm font-medium dark:text-white">{label}</span> |
||||
onChange={setEnabled} |
<div className="relative w-14 mr-2 ml-auto select-none"> |
||||
className={`${enabled ? 'bg-primary' : 'bg-gray-300 dark:bg-gray-700'} |
<input |
||||
relative inline-flex flex-shrink-0 h-[38px] w-[74px] border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`}
|
ref={ref} |
||||
> |
{...props} |
||||
<span className="sr-only">Use setting</span> |
type="checkbox" |
||||
<span |
className="peer checked:right-0 absolute w-7 h-7 rounded-full bg-white appearance-none cursor-pointer" |
||||
aria-hidden="true" |
/> |
||||
className={`${enabled ? 'translate-x-9' : 'translate-x-0'} |
<label |
||||
pointer-events-none inline-block h-[34px] w-[34px] rounded-full bg-white shadow-lg transform ring-0 transition ease-in-out duration-200`}
|
htmlFor={id} |
||||
/> |
className="block overflow-hidden h-7 rounded-full peer-checked:bg-primary shadow-sm bg-gray-300 dark:bg-gray-700 cursor-pointer" |
||||
</Switch> |
></label> |
||||
|
</div> |
||||
|
</div> |
||||
); |
); |
||||
}; |
}); |
||||
|
|||||
Loading…
Reference in new issue