-
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.
feat(redmine 1246959): integration of active fiters zone
- Loading branch information
vapersmile
committed
Nov 13, 2023
1 parent
0802a4b
commit 9d7399a
Showing
6 changed files
with
212 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/react-front-kit/src/Components/Filters/Filters.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,16 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Filters as Cmp } from './Filters'; | ||
|
||
const meta = { | ||
component: Cmp, | ||
tags: ['autodocs'], | ||
title: '3-custom/Components/Filters', | ||
} satisfies Meta<typeof Cmp>; | ||
|
||
export default meta; | ||
type IStory = StoryObj<typeof meta>; | ||
|
||
export const Filters: IStory = { | ||
args: {}, | ||
}; |
44 changes: 44 additions & 0 deletions
44
packages/react-front-kit/src/Components/Filters/Filters.style.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,44 @@ | ||
import { createStyles } from '@mantine/styles'; | ||
|
||
export const useStyles = createStyles((theme) => ({ | ||
activeFilters: { | ||
display: 'flex', | ||
flexWrap: 'nowrap', | ||
marginTop: '16px', | ||
}, | ||
badgeInner: { | ||
fontWeight: 600, | ||
position: 'relative', | ||
right: '4px', | ||
}, | ||
badgeRight: { | ||
position: 'relative', | ||
right: '4px', | ||
top: '1px', | ||
}, | ||
badgeRoot: { | ||
border: '2px solid white', | ||
color: 'white', | ||
cursor: 'pointer', | ||
fontSize: '12px', | ||
fontWeight: 'normal', | ||
marginBottom: '8px', | ||
marginRight: '8px', | ||
textTransform: 'capitalize', | ||
}, | ||
buttonRemoveRoot: { color: 'white', fontSize: '14px', padding: '0' }, | ||
root: { | ||
backgroundColor: 'white', | ||
borderRadius: '16px', | ||
}, | ||
title: { | ||
fontWeight: 600, | ||
}, | ||
top: { | ||
background: theme.colors.cyan[9], | ||
border: '8px solid white', | ||
borderRadius: '16px 16px 0px 0px', | ||
color: 'white', | ||
padding: '24px', | ||
}, | ||
})); |
10 changes: 10 additions & 0 deletions
10
packages/react-front-kit/src/Components/Filters/Filters.test.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,10 @@ | ||
import { renderWithProviders } from '@smile/react-front-kit-shared/src/test-utils'; | ||
|
||
import { Filters } from './Filters'; | ||
|
||
describe('Filters', () => { | ||
it('matches snapshot', () => { | ||
const { container } = renderWithProviders(<Filters />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
137 changes: 137 additions & 0 deletions
137
packages/react-front-kit/src/Components/Filters/Filters.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,137 @@ | ||
'use client'; | ||
|
||
import type { ReactElement, ReactNode } from 'react'; | ||
|
||
import { Badge, Box, Button, Group } from '@mantine/core'; | ||
import { TrashSimple, X } from '@phosphor-icons/react'; | ||
|
||
import { useStyles } from './Filters.style'; | ||
|
||
export interface ISidebarFilter { | ||
id: number | string; | ||
label: string; | ||
onRemove: (filter: ISidebarFilter) => void; | ||
value: unknown; | ||
} | ||
|
||
export interface IFiltersProps { | ||
activeFilters?: ISidebarFilter[] | []; | ||
deleteButtonLabel?: string; | ||
title?: ReactNode; | ||
} | ||
|
||
export function Filters(props: IFiltersProps): ReactElement { | ||
const { | ||
activeFilters = [ | ||
{ | ||
id: 1, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
{ | ||
id: 2, | ||
label: 'truck', | ||
onRemove: (filter: ISidebarFilter) => { | ||
console.log(filter); | ||
}, | ||
value: 'truck', | ||
}, | ||
], | ||
title = 'Active filters', | ||
deleteButtonLabel = 'Remove all', | ||
} = props; | ||
const { classes } = useStyles(); | ||
return ( | ||
<Box className={classes.root}> | ||
<div className={classes.top}> | ||
<Group position="apart"> | ||
<span className={classes.title}>{title}</span> | ||
<Button | ||
className={classes.buttonRemoveRoot} | ||
leftIcon={<TrashSimple size={12} />} | ||
variant="transparent" | ||
> | ||
{deleteButtonLabel} | ||
</Button> | ||
</Group> | ||
<div className={classes.activeFilters} /> | ||
{activeFilters.map((filter) => ( | ||
<Badge | ||
key={filter.id} | ||
classNames={{ | ||
inner: classes.badgeInner, | ||
rightSection: classes.badgeRight, | ||
root: classes.badgeRoot, | ||
}} | ||
onClick={() => filter.onRemove(filter)} | ||
pr={3} | ||
rightSection={<X size={10} />} | ||
size="xl" | ||
variant="outline" | ||
> | ||
{filter.label} | ||
</Badge> | ||
))} | ||
</div> | ||
</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