⚡️ feat: update select input default icon and options icon
This commit is contained in:
parent
d9bae720d7
commit
18dde52c9a
@ -1,7 +1,14 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Input } from 'components/shared/Input';
|
import { Input } from 'components/shared/Input';
|
||||||
import { CrossCircleIcon, SearchIcon } from 'components/shared/CustomIcon';
|
import {
|
||||||
|
CheckRadioOutlineIcon,
|
||||||
|
CrossCircleIcon,
|
||||||
|
LoaderIcon,
|
||||||
|
SearchIcon,
|
||||||
|
TrendingIcon,
|
||||||
|
WarningTriangleIcon,
|
||||||
|
} from 'components/shared/CustomIcon';
|
||||||
import { DatePicker } from 'components/shared/DatePicker';
|
import { DatePicker } from 'components/shared/DatePicker';
|
||||||
import { Value } from 'react-calendar/dist/cjs/shared/types';
|
import { Value } from 'react-calendar/dist/cjs/shared/types';
|
||||||
import { Select, SelectOption } from 'components/shared/Select';
|
import { Select, SelectOption } from 'components/shared/Select';
|
||||||
@ -43,10 +50,25 @@ const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
|||||||
setDateRange(value.updateAtRange);
|
setDateRange(value.updateAtRange);
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
|
const getOptionIcon = (status: StatusOptions) => {
|
||||||
|
switch (status) {
|
||||||
|
case StatusOptions.BUILDING:
|
||||||
|
return <LoaderIcon />;
|
||||||
|
case StatusOptions.READY:
|
||||||
|
return <CheckRadioOutlineIcon />;
|
||||||
|
case StatusOptions.ERROR:
|
||||||
|
return <WarningTriangleIcon />;
|
||||||
|
case StatusOptions.ALL_STATUS:
|
||||||
|
default:
|
||||||
|
return <TrendingIcon />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const statusOptions = Object.values(StatusOptions)
|
const statusOptions = Object.values(StatusOptions)
|
||||||
.map((status) => ({
|
.map((status) => ({
|
||||||
label: status,
|
label: status,
|
||||||
value: status,
|
value: status,
|
||||||
|
leftIcon: getOptionIcon(status),
|
||||||
}))
|
}))
|
||||||
.filter((status) => status.value !== StatusOptions.ALL_STATUS);
|
.filter((status) => status.value !== StatusOptions.ALL_STATUS);
|
||||||
|
|
||||||
@ -78,6 +100,7 @@ const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="col-span-2 flex items-center">
|
<div className="col-span-2 flex items-center">
|
||||||
<Select
|
<Select
|
||||||
|
leftIcon={getOptionIcon(selectedStatus as StatusOptions)}
|
||||||
options={statusOptions}
|
options={statusOptions}
|
||||||
clearable
|
clearable
|
||||||
placeholder="All status"
|
placeholder="All status"
|
||||||
|
@ -10,7 +10,7 @@ import React, {
|
|||||||
import { useMultipleSelection, useCombobox } from 'downshift';
|
import { useMultipleSelection, useCombobox } from 'downshift';
|
||||||
import { SelectTheme, selectTheme } from './Select.theme';
|
import { SelectTheme, selectTheme } from './Select.theme';
|
||||||
import {
|
import {
|
||||||
ChevronDownIcon,
|
ChevronGrabberHorizontal,
|
||||||
CrossCircleIcon,
|
CrossCircleIcon,
|
||||||
WarningIcon,
|
WarningIcon,
|
||||||
} from 'components/shared/CustomIcon';
|
} from 'components/shared/CustomIcon';
|
||||||
@ -293,10 +293,13 @@ export const Select = ({
|
|||||||
const renderLeftIcon = useMemo(() => {
|
const renderLeftIcon = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<div className={theme.iconContainer({ class: 'left-0 pl-4' })}>
|
<div className={theme.iconContainer({ class: 'left-0 pl-4' })}>
|
||||||
{cloneIcon(leftIcon, { className: theme.icon(), 'aria-hidden': true })}
|
{cloneIcon(selectedItem?.leftIcon ? selectedItem.leftIcon : leftIcon, {
|
||||||
|
className: theme.icon(),
|
||||||
|
'aria-hidden': true,
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}, [cloneIcon, theme, leftIcon]);
|
}, [cloneIcon, theme, leftIcon, selectedItem]);
|
||||||
|
|
||||||
const renderRightIcon = useMemo(() => {
|
const renderRightIcon = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
@ -310,7 +313,7 @@ export const Select = ({
|
|||||||
{rightIcon ? (
|
{rightIcon ? (
|
||||||
cloneIcon(rightIcon, { className: theme.icon(), 'aria-hidden': true })
|
cloneIcon(rightIcon, { className: theme.icon(), 'aria-hidden': true })
|
||||||
) : (
|
) : (
|
||||||
<ChevronDownIcon className={theme.icon()} />
|
<ChevronGrabberHorizontal className={theme.icon()} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -356,7 +359,7 @@ export const Select = ({
|
|||||||
onClick={() => !dropdownOpen && openMenu()}
|
onClick={() => !dropdownOpen && openMenu()}
|
||||||
>
|
>
|
||||||
{/* Left icon */}
|
{/* Left icon */}
|
||||||
{leftIcon && renderLeftIcon}
|
{renderLeftIcon}
|
||||||
|
|
||||||
{/* Multiple input values */}
|
{/* Multiple input values */}
|
||||||
{isMultipleHasValue &&
|
{isMultipleHasValue &&
|
||||||
@ -387,6 +390,8 @@ export const Select = ({
|
|||||||
'w-6': isMultipleHasValueButNotSearchable && !hideValues,
|
'w-6': isMultipleHasValueButNotSearchable && !hideValues,
|
||||||
// Add margin to the X icon
|
// Add margin to the X icon
|
||||||
'ml-6': isMultipleHasValueButNotSearchable && clearable,
|
'ml-6': isMultipleHasValueButNotSearchable && clearable,
|
||||||
|
// Add padding if there's a left icon
|
||||||
|
'pl-6': leftIcon,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user