feat: add preview to icon picker (#914)
This commit is contained in:
@@ -16,6 +16,7 @@ interface IconPickerProps {
|
|||||||
export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: IconPickerProps) => {
|
export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: IconPickerProps) => {
|
||||||
const [value, setValue] = useState<string>(initialValue ?? "");
|
const [value, setValue] = useState<string>(initialValue ?? "");
|
||||||
const [search, setSearch] = useState(initialValue ?? "");
|
const [search, setSearch] = useState(initialValue ?? "");
|
||||||
|
const [previewUrl, setPreviewUrl] = useState<string | null>(initialValue ?? null);
|
||||||
|
|
||||||
const t = useScopedI18n("common");
|
const t = useScopedI18n("common");
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
|
|||||||
<Combobox
|
<Combobox
|
||||||
onOptionSubmit={(value) => {
|
onOptionSubmit={(value) => {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
|
setPreviewUrl(value);
|
||||||
setSearch(value);
|
setSearch(value);
|
||||||
onChange(value);
|
onChange(value);
|
||||||
combobox.closeDropdown();
|
combobox.closeDropdown();
|
||||||
@@ -62,12 +64,15 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
|
|||||||
<Combobox.Target>
|
<Combobox.Target>
|
||||||
<InputBase
|
<InputBase
|
||||||
rightSection={<Combobox.Chevron />}
|
rightSection={<Combobox.Chevron />}
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
|
leftSection={previewUrl ? <img src={previewUrl} alt="" style={{ width: 20, height: 20 }} /> : null}
|
||||||
value={search}
|
value={search}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
combobox.openDropdown();
|
combobox.openDropdown();
|
||||||
combobox.updateSelectedOptionIndex();
|
combobox.updateSelectedOptionIndex();
|
||||||
setSearch(event.currentTarget.value);
|
setSearch(event.currentTarget.value);
|
||||||
setValue(event.currentTarget.value);
|
setValue(event.currentTarget.value);
|
||||||
|
setPreviewUrl(null);
|
||||||
onChange(event.currentTarget.value);
|
onChange(event.currentTarget.value);
|
||||||
}}
|
}}
|
||||||
onClick={() => combobox.openDropdown()}
|
onClick={() => combobox.openDropdown()}
|
||||||
@@ -78,6 +83,7 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
|
|||||||
onBlur={(event) => {
|
onBlur={(event) => {
|
||||||
onBlur?.(event);
|
onBlur?.(event);
|
||||||
combobox.closeDropdown();
|
combobox.closeDropdown();
|
||||||
|
setPreviewUrl(value);
|
||||||
setSearch(value || "");
|
setSearch(value || "");
|
||||||
}}
|
}}
|
||||||
rightSectionPointerEvents="none"
|
rightSectionPointerEvents="none"
|
||||||
|
|||||||
Reference in New Issue
Block a user