-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from DagsHub/feature/grouped-display-filters
Feature | grouped display filters
- Loading branch information
Showing
9 changed files
with
267 additions
and
19 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/components/elements/controlledDisplayFiltersGroup/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState } from 'react'; | ||
import { Box } from '@mui/material'; | ||
import { DisplayFilter, DisplayFilterProps } from '../displayFilter'; | ||
import React from 'react'; | ||
import { LabeledSwitch } from '../../forms'; | ||
|
||
export interface ControlledDisplayFiltersGroupProps { | ||
filters: DisplayFilterProps[]; | ||
label?: string; | ||
toggleShowAll: (show: boolean) => void; | ||
onFilterChange: (name: string, show: boolean) => void; | ||
} | ||
|
||
export function ControlledDisplayFiltersGroup({ | ||
filters, | ||
onFilterChange, | ||
toggleShowAll, | ||
label | ||
}: ControlledDisplayFiltersGroupProps) { | ||
const [showAll, setShowAll] = useState<boolean>(false); | ||
|
||
const toggleAll = () => { | ||
setShowAll(!showAll); | ||
toggleShowAll(!showAll); | ||
}; | ||
|
||
const updateFilter = (name: string, show: boolean) => { | ||
onFilterChange(name, show); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<Box> | ||
<LabeledSwitch label={label} onChange={toggleAll} /> | ||
</Box> | ||
{filters.map((item) => { | ||
return ( | ||
<DisplayFilter | ||
value={showAll} | ||
label={item.label} | ||
onChange={(show) => updateFilter(item.label, show)} | ||
/> | ||
); | ||
})} | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Stack, Typography } from '@mui/material'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Icon } from '../../icons'; | ||
|
||
export interface DisplayFilterProps { | ||
label: string; | ||
onChange: (show: boolean) => void; | ||
value: boolean; | ||
} | ||
export function DisplayFilter({ label, onChange, value }: DisplayFilterProps) { | ||
const [show, setShow] = useState<boolean>(false); | ||
|
||
const filterClicked = () => { | ||
const currentShow = show; | ||
setShow(!currentShow); | ||
onChange(!currentShow); | ||
}; | ||
|
||
useEffect(() => { | ||
setShow(value); | ||
}, [value]); | ||
|
||
return ( | ||
<Stack | ||
gap={1} | ||
direction={'row'} | ||
sx={{ cursor: 'pointer', width: 'fit-content' }} | ||
display={'flex'} | ||
justifyContent={'space-between'} | ||
alignItems={'center'} | ||
onClick={filterClicked} | ||
role={'button'} | ||
> | ||
<Typography | ||
sx={{ | ||
padding: 1, | ||
lineHeight: '20px', | ||
color: '#172D32', | ||
fontFamily: 'Inter', | ||
fontSize: '14px', | ||
fontWeight: 500, | ||
width: '144px' | ||
}} | ||
> | ||
{label} | ||
</Typography> | ||
|
||
<Icon icon={show ? 'eye' : 'eye-off'} height={16} width={16} fill={'#94A3B8'} /> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as React from 'react'; | ||
import { styled } from '@mui/material/styles'; | ||
import FormGroup from '@mui/material/FormGroup'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Switch, { SwitchProps } from '@mui/material/Switch'; | ||
|
||
const StyledSwitch = styled((props: SwitchProps) => ( | ||
<Switch focusVisibleClassName=".Mui-focusVisible" disableRipple {...props} /> | ||
))(({ theme }) => ({ | ||
width: 48, | ||
height: 24, | ||
padding: 0, | ||
'& .MuiSwitch-switchBase': { | ||
padding: 0, | ||
margin: '2px', | ||
transitionDuration: '300ms', | ||
'&.Mui-checked': { | ||
transform: 'translateX(24px)', | ||
color: '#fff', | ||
'& + .MuiSwitch-track': { | ||
backgroundColor: theme.palette.mode === 'dark' ? '#2ECA45' : '#65C466', | ||
opacity: 1, | ||
border: 0 | ||
}, | ||
'&.Mui-disabled + .MuiSwitch-track': { | ||
opacity: 0.5 | ||
} | ||
}, | ||
'&.Mui-focusVisible .MuiSwitch-thumb': { | ||
color: '#33cf4d', | ||
border: '6px solid #fff' | ||
}, | ||
'&.Mui-disabled .MuiSwitch-thumb': { | ||
color: theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[600] | ||
}, | ||
'&.Mui-disabled + .MuiSwitch-track': { | ||
opacity: theme.palette.mode === 'light' ? 0.7 : 0.3 | ||
} | ||
}, | ||
'& .MuiSwitch-thumb': { | ||
boxSizing: 'border-box', | ||
width: 20, | ||
height: 20 | ||
}, | ||
'& .MuiSwitch-track': { | ||
borderRadius: 23 / 2, | ||
backgroundColor: theme.palette.mode === 'light' ? '#E9E9EA' : '#39393D', | ||
opacity: 1, | ||
transition: theme.transitions.create(['background-color'], { | ||
duration: 500 | ||
}) | ||
} | ||
})); | ||
|
||
export function LabeledSwitch({ onChange, label }: { onChange: () => void; label?: string }) { | ||
return ( | ||
<FormGroup> | ||
<FormControlLabel | ||
onChange={onChange} | ||
control={<StyledSwitch sx={{ m: 1 }} defaultChecked />} | ||
label={label} | ||
/> | ||
</FormGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/stories/elements/controlledDisplayFiltersGroup/ControlledDisplayFiltersGroup.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import React from 'react'; | ||
import { | ||
ControlledDisplayFiltersGroup, | ||
ControlledDisplayFiltersGroupProps | ||
} from '../../../components'; | ||
|
||
const meta: Meta<ControlledDisplayFiltersGroupProps> = { | ||
title: 'Elements/Display filter group', | ||
component: ControlledDisplayFiltersGroup | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: StoryFn<typeof ControlledDisplayFiltersGroup> = (args) => ( | ||
<ControlledDisplayFiltersGroup {...args} /> | ||
); | ||
|
||
export const ControlledDisplayFilterBasic: StoryFn<typeof ControlledDisplayFiltersGroup> = | ||
Template.bind({}); | ||
ControlledDisplayFilterBasic.args = { | ||
filters: [ | ||
{ | ||
label: 'test label1', | ||
onChange: (value) => console.log('changed', value), | ||
value: false | ||
}, | ||
{ | ||
label: 'test label2', | ||
onChange: (value) => console.log('changed', value), | ||
value: false | ||
}, | ||
{ | ||
label: 'test label3 ', | ||
onChange: (value) => console.log('changed', value), | ||
value: false | ||
} | ||
], | ||
onFilterChange: (value) => console.log('show all', value), | ||
toggleShowAll: (value) => console.log('toggle show all', value), | ||
label: 'Grouped display filters example', | ||
}; |
18 changes: 18 additions & 0 deletions
18
src/stories/elements/displayFilter/DisplayFilter.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DisplayFilter, DisplayFilterProps } from '../../../components'; | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
const meta: Meta<DisplayFilterProps> = { | ||
title: 'Elements/Display filter', | ||
component: DisplayFilter | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: StoryFn<typeof DisplayFilter> = (args) => <DisplayFilter {...args} />; | ||
|
||
export const DisplayFilterBasic: StoryFn<typeof DisplayFilter> = Template.bind({}); | ||
DisplayFilterBasic.args = { | ||
label: 'test label', | ||
onChange: () => console.log('changed') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters