Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezryr committed Dec 7, 2024
1 parent bb14659 commit d004b03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
10 changes: 4 additions & 6 deletions components/FilterDropdownMultiple/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ export default function FilterDropdownMultiple<T>({
placeholder,
disabled = false,
}: FilterDropdownProps<T>) {
const handleChange = (
selectedOptions: MultiValue<DropdownOption<T>>,
_actionMeta: ActionMeta<DropdownOption<T>>,
) => {
const handleChange = (selectedOptions: MultiValue<DropdownOption<T>>) => {
setStateAction(selectedOptions as DropdownOption<T>[]);
};

Expand All @@ -38,7 +35,6 @@ export default function FilterDropdownMultiple<T>({
// StyledMultiValue appears for each selected option, so if more than 1 is selected,
// the rest of the selected options are not shown, instead the + n is shown as part of the first option
const StyledMultiValue = ({
children,
...props
}: MultiValueProps<
DropdownOption<T>,
Expand Down Expand Up @@ -101,10 +97,12 @@ export default function FilterDropdownMultiple<T>({
placeholder={placeholder}
onChange={handleChange}
closeMenuOnSelect={false}
styles={customSelectStyles}
styles={customSelectStyles<T>()}
isSearchable={false}
hideSelectedOptions={false}
// can bring this back if we want an 'x' to clear filters for each dropdown
isClearable={false}
// use custom styled components instead of default components
components={{ MultiValue: StyledMultiValue, Option: CustomOption }}
/>
);
Expand Down
22 changes: 14 additions & 8 deletions components/FilterDropdownMultiple/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export const StyledOption = styled.div`
`;

// custom styles for react-select component
export const customSelectStyles: StylesConfig<DropdownOption<any>, true> = {
// Option type is DropdownOption<T> and isMulti is true
export const customSelectStyles = <T>(): StylesConfig<
DropdownOption<T>,
true
> => ({
// container
control: (baseStyles, state) => ({
...baseStyles,
borderRadius: '57px',
Expand All @@ -18,49 +23,50 @@ export const customSelectStyles: StylesConfig<DropdownOption<any>, true> = {
padding: '8px 14px',
color: COLORS.midgray,
}),
// placeholder text
placeholder: baseStyles => ({
...baseStyles,
color: COLORS.midgray,
fontSize: '0.75rem',
padding: '0px',
margin: '0px',
}),
input: baseStyles => ({
...baseStyles,
margin: '0px',
padding: '0px',
}),
// hide vertical bar between arrow and text
indicatorSeparator: baseStyles => ({
...baseStyles,
display: 'none',
}),
// 'x' to clear selected option(s)
clearIndicator: baseStyles => ({
...baseStyles,
padding: '0px',
}),
// dropdown arrow
dropdownIndicator: baseStyles => ({
...baseStyles,
padding: '0px',
marginLeft: '-4px', // move the dropdown indicator to the left cant override text styles
marginLeft: '-4px', // move the dropdown indicator to the left, cant override text styles
color: COLORS.midgray,
}),
// container for selected multi option
multiValue: baseStyles => ({
...baseStyles,
backgroundColor: '#fff',
border: '0px',
padding: '0px',
margin: '0px',
}),
// multi option display text
multiValueLabel: baseStyles => ({
...baseStyles,
fontSize: '0.75rem',
color: `${COLORS.black} !important`,
padding: '0px',
paddingLeft: '0px',
}),
// hide 'x' next to each multi option
multiValueRemove: baseStyles => ({
...baseStyles,
display: 'none',
}),
};
});
4 changes: 2 additions & 2 deletions components/FilterDropdownSingle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default function FilterDropdownSingle<T>({
selectedOptions:
| SingleValue<DropdownOption<T>>
| MultiValue<DropdownOption<T>>,
_actionMeta: ActionMeta<DropdownOption<T>>,
) => {
if (!Array.isArray(selectedOptions)) {
setStateAction(selectedOptions as DropdownOption<T>);
Expand All @@ -43,9 +42,10 @@ export default function FilterDropdownSingle<T>({
placeholder={placeholder}
onChange={handleChange}
closeMenuOnSelect={false}
styles={customSelectStyles(small)}
styles={customSelectStyles<T>(small)}
isSearchable={false}
hideSelectedOptions={false}
// can bring this back if we want an 'x' to clear filters for each dropdown
isClearable={false}
/>
);
Expand Down
17 changes: 9 additions & 8 deletions components/FilterDropdownSingle/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const FilterDropdownInput = styled.select<{ $hasValue: boolean }>`
`;

// custom styles for react-select component
export const customSelectStyles = (
// Option type is DropdownOption<T>
export const customSelectStyles = <T>(
$isSmall: boolean,
): StylesConfig<DropdownOption<any>, true> => ({
): StylesConfig<DropdownOption<T>, true> => ({
// container
control: (baseStyles, state) => ({
...baseStyles,
borderRadius: '57px',
Expand All @@ -30,6 +32,7 @@ export const customSelectStyles = (
// if small is true, set min width to 150px, if undefined don't set min width
...($isSmall && { minWidth: '150px' }),
}),
// placeholder text
placeholder: baseStyles => ({
...baseStyles,
color: COLORS.midgray,
Expand All @@ -38,26 +41,24 @@ export const customSelectStyles = (
margin: '0px',
justifySelf: 'center',
}),
input: baseStyles => ({
...baseStyles,
margin: '0px',
padding: '0px',
}),
// hide vertical bar between arrow and text
indicatorSeparator: baseStyles => ({
...baseStyles,
display: 'none',
}),
// 'x' to clear selected option(s)
clearIndicator: baseStyles => ({
...baseStyles,
padding: '0px',
}),
// dropdown arrow
dropdownIndicator: baseStyles => ({
...baseStyles,
padding: '0px',
marginLeft: '-4px', // move the dropdown indicator to the left cant override text styles
marginLeft: '-4px', // move the dropdown indicator to the left, cant override text styles
color: COLORS.midgray,
}),
// selected option display text
singleValue: baseStyles => ({
...baseStyles,
backgroundColor: '#fff',
Expand Down

0 comments on commit d004b03

Please sign in to comment.