forked from cerc-io/snowballtools-base
⚡️ 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 { 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 { Value } from 'react-calendar/dist/cjs/shared/types';
|
||||
import { Select, SelectOption } from 'components/shared/Select';
|
||||
@ -43,10 +50,25 @@ const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
||||
setDateRange(value.updateAtRange);
|
||||
}, [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)
|
||||
.map((status) => ({
|
||||
label: status,
|
||||
value: status,
|
||||
leftIcon: getOptionIcon(status),
|
||||
}))
|
||||
.filter((status) => status.value !== StatusOptions.ALL_STATUS);
|
||||
|
||||
@ -78,6 +100,7 @@ const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
||||
</div>
|
||||
<div className="col-span-2 flex items-center">
|
||||
<Select
|
||||
leftIcon={getOptionIcon(selectedStatus as StatusOptions)}
|
||||
options={statusOptions}
|
||||
clearable
|
||||
placeholder="All status"
|
||||
|
@ -10,7 +10,7 @@ import React, {
|
||||
import { useMultipleSelection, useCombobox } from 'downshift';
|
||||
import { SelectTheme, selectTheme } from './Select.theme';
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ChevronGrabberHorizontal,
|
||||
CrossCircleIcon,
|
||||
WarningIcon,
|
||||
} from 'components/shared/CustomIcon';
|
||||
@ -293,10 +293,13 @@ export const Select = ({
|
||||
const renderLeftIcon = useMemo(() => {
|
||||
return (
|
||||
<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>
|
||||
);
|
||||
}, [cloneIcon, theme, leftIcon]);
|
||||
}, [cloneIcon, theme, leftIcon, selectedItem]);
|
||||
|
||||
const renderRightIcon = useMemo(() => {
|
||||
return (
|
||||
@ -310,7 +313,7 @@ export const Select = ({
|
||||
{rightIcon ? (
|
||||
cloneIcon(rightIcon, { className: theme.icon(), 'aria-hidden': true })
|
||||
) : (
|
||||
<ChevronDownIcon className={theme.icon()} />
|
||||
<ChevronGrabberHorizontal className={theme.icon()} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@ -356,7 +359,7 @@ export const Select = ({
|
||||
onClick={() => !dropdownOpen && openMenu()}
|
||||
>
|
||||
{/* Left icon */}
|
||||
{leftIcon && renderLeftIcon}
|
||||
{renderLeftIcon}
|
||||
|
||||
{/* Multiple input values */}
|
||||
{isMultipleHasValue &&
|
||||
@ -387,6 +390,8 @@ export const Select = ({
|
||||
'w-6': isMultipleHasValueButNotSearchable && !hideValues,
|
||||
// Add margin to the X icon
|
||||
'ml-6': isMultipleHasValueButNotSearchable && clearable,
|
||||
// Add padding if there's a left icon
|
||||
'pl-6': leftIcon,
|
||||
},
|
||||
)}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user