mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-12 23:36:00 +00:00
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
import InformationCircleIcon from '@heroicons/react/24/outline/InformationCircleIcon'
|
|
import { useState } from 'react'
|
|
|
|
type SelectBoxProps = {
|
|
labelTitle?: string
|
|
labelStyle?: string
|
|
type?: string
|
|
containerStyle?: string
|
|
defaultValue: string
|
|
placeholder?: string
|
|
|
|
updateFormValue: (value: string) => void
|
|
|
|
options: { name: string; value: string }[]
|
|
labelDescription?: string
|
|
}
|
|
|
|
export function SelectBox(props: SelectBoxProps) {
|
|
const {
|
|
labelTitle,
|
|
labelDescription,
|
|
defaultValue,
|
|
containerStyle,
|
|
placeholder,
|
|
labelStyle,
|
|
options,
|
|
updateFormValue,
|
|
} = props
|
|
|
|
const [value, setValue] = useState(defaultValue || '')
|
|
|
|
const updateValue = (newValue: string) => {
|
|
updateFormValue(newValue)
|
|
setValue(newValue)
|
|
}
|
|
|
|
return (
|
|
<div className={`tw-inline-block ${containerStyle}`}>
|
|
{labelTitle ? (
|
|
<label className={`tw-label ${labelStyle}`}>
|
|
<div className='tw-label-text'>
|
|
{labelTitle}
|
|
{labelDescription && (
|
|
<div className='tw-tooltip tw-tooltip-right' data-tip={labelDescription}>
|
|
<InformationCircleIcon className='tw-w-4 tw-h-4' />
|
|
</div>
|
|
)}
|
|
</div>
|
|
</label>
|
|
) : (
|
|
''
|
|
)}
|
|
<select
|
|
className='tw-select tw-select-bordered tw-w-full'
|
|
value={value}
|
|
onChange={(e) => updateValue(e.target.value)}
|
|
>
|
|
<option disabled value='PLACEHOLDER'>
|
|
{placeholder}
|
|
</option>
|
|
{options.map((o, k) => {
|
|
return (
|
|
<option value={o.value || o.name} key={k}>
|
|
{o.name}
|
|
</option>
|
|
)
|
|
})}
|
|
</select>
|
|
</div>
|
|
)
|
|
}
|