diff --git a/src/front/Components/DesignSystem/Autocomplete/classes.module.scss b/src/front/Components/DesignSystem/Autocomplete/classes.module.scss index 452fdaad..0a331a1d 100644 --- a/src/front/Components/DesignSystem/Autocomplete/classes.module.scss +++ b/src/front/Components/DesignSystem/Autocomplete/classes.module.scss @@ -1,41 +1,7 @@ @import "@Themes/constants.scss"; .root { - cursor: pointer; - height: 56px; - - display: flex; - align-items: center; - - padding: var(--spacing-2, 16px) var(--spacing-sm, 8px); - gap: var(--spacing-2, 16px); - - border-radius: var(--input-radius, 0px); - border: 1px solid var(--dropdown-input-border-default, #d7dce0); - background: var(--dropdown-input-background, #fff); - - .content { - width: 100%; - display: flex; + .label { padding: 0px var(--spacing-2, 16px); - align-items: center; - flex: 1 0 0; - } - - &:hover { - border-color: var(--dropdown-input-border-hovered); - } - - &.active { - border-color: var(--dropdown-input-border-filled); - } - - &.open { - border-color: var(--dropdown-input-border-expanded); - } - - &.disabled { - opacity: var(--opacity-disabled, 0.3); - pointer-events: none; } } diff --git a/src/front/Components/DesignSystem/Autocomplete/index.tsx b/src/front/Components/DesignSystem/Autocomplete/index.tsx index d95a7a47..8ecfc3db 100644 --- a/src/front/Components/DesignSystem/Autocomplete/index.tsx +++ b/src/front/Components/DesignSystem/Autocomplete/index.tsx @@ -1,18 +1,24 @@ import useOpenable from "@Front/Hooks/useOpenable"; -import { useState, useEffect, useCallback } from "react"; +import { useCallback, useEffect, useState } from "react"; + import DropdownMenu from "../Dropdown/DropdownMenu"; import { IOption } from "../Dropdown/DropdownMenu/DropdownOption"; import SearchBar from "../SearchBar"; +import Typography, { ETypo, ETypoColor } from "../Typography"; +import classes from "./classes.module.scss"; type IProps = { options: IOption[]; - placeholder: string; + placeholder?: string; disabled?: boolean; + label?: string; + onSelect?: (option: IOption) => void; + selectedOption?: IOption | null; }; export default function Autocomplete(props: IProps) { - const { options, placeholder, disabled } = props; - const [selectedOption, setSelectedOption] = useState(null); + const { options, placeholder, disabled, label, selectedOption: selectedOptionProps } = props; + const [selectedOption, setSelectedOption] = useState(selectedOptionProps ?? null); const [searchValue, setSearchValue] = useState(""); const [filteredOptions, setFilteredOptions] = useState(options); const openable = useOpenable({ defaultOpen: false }); @@ -40,6 +46,10 @@ export default function Autocomplete(props: IProps) { [openable], ); + useEffect(() => { + setSelectedOption(selectedOptionProps ?? null); + }, [selectedOptionProps]); + const handleSelectOption = useCallback( (option: IOption) => { setSelectedOption(option); @@ -59,6 +69,13 @@ export default function Autocomplete(props: IProps) { return ( +
+ {label && ( + + {label} + + )} +
); diff --git a/src/front/Components/DesignSystem/Dropdown/index.tsx b/src/front/Components/DesignSystem/Dropdown/index.tsx index 31d3116d..a3875994 100644 --- a/src/front/Components/DesignSystem/Dropdown/index.tsx +++ b/src/front/Components/DesignSystem/Dropdown/index.tsx @@ -18,7 +18,7 @@ type IProps = { }; export default function Dropdown(props: IProps) { - const { options, placeholder, disabled, onSelect, selectedOption: selectedOptionProps } = props; + const { options, placeholder, disabled, onSelect, selectedOption: selectedOptionProps, label } = props; const [selectedOption, setSelectedOption] = useState(selectedOptionProps ?? null); const openable = useOpenable({ defaultOpen: false }); @@ -37,9 +37,9 @@ export default function Dropdown(props: IProps) { return (
- {props.label && ( + {label && ( - {props.label} + {label} )}
void; + options: IOption[]; + selectedOption?: IOption | null; + label?: string; +}; + +type IState = IBaseFieldState & { + selectedOption: IOption | null; +}; + +export default class AutocompleteField extends BaseField { + constructor(props: IProps) { + super(props); + this.state = { + selectedOption: this.props.selectedOption ?? null, + ...this.getDefaultState(), + }; + + this.handleOnChange = this.handleOnChange.bind(this); + } + + private handleOnChange = (option: IOption) => { + this.setState({ selectedOption: option }); + this.props.onSelect?.(option); + }; + + public override componentDidUpdate(prevProps: IProps): void { + if (prevProps.selectedOption !== this.props.selectedOption) { + this.setState({ selectedOption: this.props.selectedOption ?? null }); + } + } + + public override render(): ReactNode { + return ( +
+ + {this.state.selectedOption && ( + + )} + {this.hasError() &&
{this.renderErrors()}
} +
+ ); + } +} diff --git a/src/front/Components/DesignSystem/Form/SelectField/index.tsx b/src/front/Components/DesignSystem/Form/SelectField/index.tsx index 6a8ae219..3a79d80c 100644 --- a/src/front/Components/DesignSystem/Form/SelectField/index.tsx +++ b/src/front/Components/DesignSystem/Form/SelectField/index.tsx @@ -10,6 +10,7 @@ export type IProps = IBaseFieldProps & { onSelect?: (option: IOption) => void; options: IOption[]; selectedOption?: IOption | null; + label?: string; }; type IState = IBaseFieldState & { @@ -46,6 +47,7 @@ export default class SelectField extends BaseField { placeholder={this.props.placeholder} onSelect={this.handleOnChange} selectedOption={this.state.selectedOption} + label={this.props.label} /> {this.state.selectedOption && ( Dropdown