Skip to content

Commit

Permalink
feat: disabled option
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmagnus committed Jan 24, 2024
1 parent 51a004e commit df6e774
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/templates/vault-create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SelectCategory } from './select-category'
export interface IOption {
readonly label: string
readonly value: number
readonly disabled: boolean
}

interface IVaultCreateTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ interface ISelectCategory {
clearErrors?(): void
}

const createOption = (label: string, value: number): IOption => ({
const createOption = (
label: string,
value: number,
disabled?: boolean
): IOption => ({
label,
value: value,
disabled: disabled ?? false,
})

export const SelectCategory: React.FC<ISelectCategory> = ({
Expand Down Expand Up @@ -47,10 +52,11 @@ export const SelectCategory: React.FC<ISelectCategory> = ({
}

useEffect(() => {
const ops = vaultCategories?.map(
let ops = vaultCategories?.map(
(vaultCategory: Hooks.UseVaultsTypes.IVaultCategory) =>
createOption(vaultCategory.name, vaultCategory.id)
)
ops = [...(ops || []), createOption('Type to create...', 0, true)]
setOptions(ops || [])
}, [vaultCategories])

Expand All @@ -62,13 +68,18 @@ export const SelectCategory: React.FC<ISelectCategory> = ({
onCreateOption={handleVaultCategory}
options={options}
value={value}
isOptionDisabled={(option): boolean => option.disabled}
onChange={(newValue): void => {
if (clearErrors) clearErrors()
setCategorySelected(newValue)
}}
defaultValue={
categorySelected
? { value: categorySelected.value, label: categorySelected.label }
? {
value: categorySelected.value,
label: categorySelected.label,
disabled: false,
}
: undefined
}
styles={{
Expand All @@ -83,9 +94,10 @@ export const SelectCategory: React.FC<ISelectCategory> = ({
...base,
backgroundColor: colorMode === 'dark' ? '#303448' : undefined,
}),
option: (styles, { isFocused, isSelected }) => ({
option: (styles, { isFocused, isSelected, isDisabled }) => ({
...styles,
color: colorMode === 'dark' ? 'white' : 'black',
opacity: isDisabled ? '0.5' : undefined,
background: isFocused
? colorMode === 'dark'
? '#292d3e'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Form: React.FC<IHeader> = ({
}) => {
const [categorySelected, setCategorySelected] = useState<
IOption | null | undefined
>(category && { label: category?.name, value: category?.id })
>(category && { label: category?.name, value: category?.id, disabled: false })

const [name, setName] = useState<string | undefined>(vault.name)

Expand Down

0 comments on commit df6e774

Please sign in to comment.