mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-23 01:16:27 +02:00
feat: filter chips icons (#5658)
This commit is contained in:
parent
864ae4530b
commit
d429f51cbd
@ -8,7 +8,8 @@ const getDate = (option: string) => screen.getByText(option);
|
|||||||
const setup = (initialState: FilterItemParams | null) => {
|
const setup = (initialState: FilterItemParams | null) => {
|
||||||
const recordedChanges: FilterItemParams[] = [];
|
const recordedChanges: FilterItemParams[] = [];
|
||||||
const mockProps: IFilterDateItemProps = {
|
const mockProps: IFilterDateItemProps = {
|
||||||
label: 'Test Label',
|
name: 'Test Label',
|
||||||
|
label: 'irrelevant',
|
||||||
onChange: (value: FilterItemParams) => {
|
onChange: (value: FilterItemParams) => {
|
||||||
recordedChanges.push(value);
|
recordedChanges.push(value);
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Box } from '@mui/material';
|
import { Box } from '@mui/material';
|
||||||
import React, { FC, useEffect, useRef, useState } from 'react';
|
import React, { FC, ReactNode, useEffect, useRef, useState } from 'react';
|
||||||
import { StyledPopover } from 'component/filter/FilterItem/FilterItem.styles';
|
import { StyledPopover } from 'component/filter/FilterItem/FilterItem.styles';
|
||||||
import { FilterItemChip } from 'component/filter/FilterItem/FilterItemChip/FilterItemChip';
|
import { FilterItemChip } from 'component/filter/FilterItem/FilterItemChip/FilterItemChip';
|
||||||
import { DateCalendar, LocalizationProvider } from '@mui/x-date-pickers';
|
import { DateCalendar, LocalizationProvider } from '@mui/x-date-pickers';
|
||||||
@ -10,7 +10,8 @@ import { getLocalizedDateString } from '../util';
|
|||||||
import { FilterItemParams } from 'component/filter/FilterItem/FilterItem';
|
import { FilterItemParams } from 'component/filter/FilterItem/FilterItem';
|
||||||
|
|
||||||
export interface IFilterDateItemProps {
|
export interface IFilterDateItemProps {
|
||||||
label: string;
|
name: string;
|
||||||
|
label: ReactNode;
|
||||||
onChange: (value: FilterItemParams) => void;
|
onChange: (value: FilterItemParams) => void;
|
||||||
onChipClose: () => void;
|
onChipClose: () => void;
|
||||||
state: FilterItemParams | null | undefined;
|
state: FilterItemParams | null | undefined;
|
||||||
@ -18,6 +19,7 @@ export interface IFilterDateItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const FilterDateItem: FC<IFilterDateItemProps> = ({
|
export const FilterDateItem: FC<IFilterDateItemProps> = ({
|
||||||
|
name,
|
||||||
label,
|
label,
|
||||||
onChange,
|
onChange,
|
||||||
onChipClose,
|
onChipClose,
|
||||||
@ -72,6 +74,7 @@ export const FilterDateItem: FC<IFilterDateItemProps> = ({
|
|||||||
<Box ref={ref}>
|
<Box ref={ref}>
|
||||||
<FilterItemChip
|
<FilterItemChip
|
||||||
label={label}
|
label={label}
|
||||||
|
name={name}
|
||||||
selectedDisplayOptions={selectedOptions}
|
selectedDisplayOptions={selectedOptions}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
onClick={open}
|
onClick={open}
|
||||||
|
@ -8,7 +8,8 @@ const getOption = (option: string) =>
|
|||||||
const setup = (initialState: FilterItemParams | null) => {
|
const setup = (initialState: FilterItemParams | null) => {
|
||||||
const recordedChanges: FilterItemParams[] = [];
|
const recordedChanges: FilterItemParams[] = [];
|
||||||
const mockProps: IFilterItemProps = {
|
const mockProps: IFilterItemProps = {
|
||||||
label: 'Test Label',
|
name: 'Test Label',
|
||||||
|
label: 'irrelevant',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
label: 'Option 1',
|
label: 'Option 1',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Search } from '@mui/icons-material';
|
import { Search } from '@mui/icons-material';
|
||||||
import { Box, InputAdornment, List, ListItemText } from '@mui/material';
|
import { Box, InputAdornment, List, ListItemText } from '@mui/material';
|
||||||
import { FC, useEffect, useRef, useState } from 'react';
|
import { FC, ReactNode, useEffect, useRef, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
StyledCheckbox,
|
StyledCheckbox,
|
||||||
StyledDropdown,
|
StyledDropdown,
|
||||||
@ -11,7 +11,8 @@ import {
|
|||||||
import { FilterItemChip } from './FilterItemChip/FilterItemChip';
|
import { FilterItemChip } from './FilterItemChip/FilterItemChip';
|
||||||
|
|
||||||
export interface IFilterItemProps {
|
export interface IFilterItemProps {
|
||||||
label: string;
|
name: string;
|
||||||
|
label: ReactNode;
|
||||||
options: Array<{ label: string; value: string }>;
|
options: Array<{ label: string; value: string }>;
|
||||||
onChange: (value: FilterItemParams) => void;
|
onChange: (value: FilterItemParams) => void;
|
||||||
onChipClose: () => void;
|
onChipClose: () => void;
|
||||||
@ -26,6 +27,7 @@ export type FilterItemParams = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const FilterItem: FC<IFilterItemProps> = ({
|
export const FilterItem: FC<IFilterItemProps> = ({
|
||||||
|
name,
|
||||||
label,
|
label,
|
||||||
options,
|
options,
|
||||||
onChange,
|
onChange,
|
||||||
@ -101,6 +103,7 @@ export const FilterItem: FC<IFilterItemProps> = ({
|
|||||||
<>
|
<>
|
||||||
<Box ref={ref}>
|
<Box ref={ref}>
|
||||||
<FilterItemChip
|
<FilterItemChip
|
||||||
|
name={name}
|
||||||
label={label}
|
label={label}
|
||||||
selectedDisplayOptions={selectedDisplayOptions}
|
selectedDisplayOptions={selectedDisplayOptions}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ComponentProps, FC } from 'react';
|
import { ComponentProps, FC, ReactNode } from 'react';
|
||||||
import { ArrowDropDown, Close, TopicOutlined } from '@mui/icons-material';
|
import { ArrowDropDown, Close } from '@mui/icons-material';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { Chip, IconButton, styled } from '@mui/material';
|
import { Chip, IconButton, styled } from '@mui/material';
|
||||||
import { FilterItemOperator } from './FilterItemOperator/FilterItemOperator';
|
import { FilterItemOperator } from './FilterItemOperator/FilterItemOperator';
|
||||||
@ -32,13 +32,6 @@ const StyledLabel = styled('div')(({ theme }) => ({
|
|||||||
fontWeight: theme.typography.fontWeightBold,
|
fontWeight: theme.typography.fontWeightBold,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const StyledCategoryIconWrapper = styled('div')(({ theme }) => ({
|
|
||||||
marginRight: theme.spacing(0.5),
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
fontSize: theme.spacing(2),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledOptions = styled('button')(({ theme }) => ({
|
const StyledOptions = styled('button')(({ theme }) => ({
|
||||||
color: theme.palette.text.primary,
|
color: theme.palette.text.primary,
|
||||||
fontWeight: theme.typography.fontWeightRegular,
|
fontWeight: theme.typography.fontWeightRegular,
|
||||||
@ -75,7 +68,8 @@ const Arrow = () => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
interface IFilterItemChipProps {
|
interface IFilterItemChipProps {
|
||||||
label: string;
|
name: string;
|
||||||
|
label: ReactNode;
|
||||||
selectedDisplayOptions?: string[];
|
selectedDisplayOptions?: string[];
|
||||||
operatorOptions: string[];
|
operatorOptions: string[];
|
||||||
operator: string;
|
operator: string;
|
||||||
@ -85,6 +79,7 @@ interface IFilterItemChipProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const FilterItemChip: FC<IFilterItemChipProps> = ({
|
export const FilterItemChip: FC<IFilterItemChipProps> = ({
|
||||||
|
name,
|
||||||
label,
|
label,
|
||||||
selectedDisplayOptions = [],
|
selectedDisplayOptions = [],
|
||||||
operatorOptions,
|
operatorOptions,
|
||||||
@ -104,7 +99,7 @@ export const FilterItemChip: FC<IFilterItemChipProps> = ({
|
|||||||
|
|
||||||
trackEvent('search-filter', {
|
trackEvent('search-filter', {
|
||||||
props: {
|
props: {
|
||||||
label: label,
|
label: name,
|
||||||
operator: operator,
|
operator: operator,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -115,9 +110,6 @@ export const FilterItemChip: FC<IFilterItemChipProps> = ({
|
|||||||
isActive={hasSelectedOptions}
|
isActive={hasSelectedOptions}
|
||||||
label={
|
label={
|
||||||
<StyledLabel>
|
<StyledLabel>
|
||||||
<StyledCategoryIconWrapper>
|
|
||||||
<TopicOutlined fontSize='inherit' />
|
|
||||||
</StyledCategoryIconWrapper>
|
|
||||||
{label}
|
{label}
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={!hasSelectedOptions}
|
condition={!hasSelectedOptions}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState, VFC } from 'react';
|
import { useEffect, useState, VFC } from 'react';
|
||||||
import { Box, styled } from '@mui/material';
|
import { Box, Icon, styled } from '@mui/material';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { AddFilterButton } from '../AddFilterButton';
|
import { AddFilterButton } from '../AddFilterButton';
|
||||||
import { FilterDateItem } from 'component/common/FilterDateItem/FilterDateItem';
|
import { FilterDateItem } from 'component/common/FilterDateItem/FilterDateItem';
|
||||||
@ -44,6 +44,19 @@ type IDateFilterItem = IBaseFilterItem & {
|
|||||||
|
|
||||||
export type IFilterItem = ITextFilterItem | IDateFilterItem;
|
export type IFilterItem = ITextFilterItem | IDateFilterItem;
|
||||||
|
|
||||||
|
const StyledCategoryIconWrapper = styled('div')(({ theme }) => ({
|
||||||
|
marginRight: theme.spacing(0.5),
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
fontSize: theme.spacing(2),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledIcon = styled(Icon)(({ theme }) => ({
|
||||||
|
'&.material-symbols-outlined': {
|
||||||
|
fontSize: theme.spacing(2),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
export const Filters: VFC<IFilterProps> = ({
|
export const Filters: VFC<IFilterProps> = ({
|
||||||
state,
|
state,
|
||||||
onChange,
|
onChange,
|
||||||
@ -105,10 +118,20 @@ export const Filters: VFC<IFilterProps> = ({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const label = (
|
||||||
|
<>
|
||||||
|
<StyledCategoryIconWrapper>
|
||||||
|
<StyledIcon>{filter.icon}</StyledIcon>
|
||||||
|
</StyledCategoryIconWrapper>
|
||||||
|
{filter.label}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
if ('dateOperators' in filter) {
|
if ('dateOperators' in filter) {
|
||||||
return (
|
return (
|
||||||
<FilterDateItem
|
<FilterDateItem
|
||||||
label={filter.label}
|
label={label}
|
||||||
|
name={filter.label}
|
||||||
state={state[filter.filterKey]}
|
state={state[filter.filterKey]}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
onChange({ [filter.filterKey]: value })
|
onChange({ [filter.filterKey]: value })
|
||||||
@ -122,7 +145,8 @@ export const Filters: VFC<IFilterProps> = ({
|
|||||||
return (
|
return (
|
||||||
<FilterItem
|
<FilterItem
|
||||||
key={filter.label}
|
key={filter.label}
|
||||||
label={filter.label}
|
label={label}
|
||||||
|
name={filter.label}
|
||||||
state={state[filter.filterKey]}
|
state={state[filter.filterKey]}
|
||||||
options={filter.options}
|
options={filter.options}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user