Skip to content

Commit

Permalink
feat(redmine 1246959): integration of active fiters zone
Browse files Browse the repository at this point in the history
  • Loading branch information
vapersmile committed Nov 13, 2023
1 parent 0802a4b commit 9d7399a
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 4 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 packages/react-front-kit/src/Components/Filters/Filters.style.tsx
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 packages/react-front-kit/src/Components/Filters/Filters.test.tsx
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 packages/react-front-kit/src/Components/Filters/Filters.tsx
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);

Check warning on line 30 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 38 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 46 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 54 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 62 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 70 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 78 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 86 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
value: 'truck',
},
{
id: 2,
label: 'truck',
onRemove: (filter: ISidebarFilter) => {
console.log(filter);

Check warning on line 94 in packages/react-front-kit/src/Components/Filters/Filters.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
},
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>
);
}
1 change: 1 addition & 0 deletions packages/react-front-kit/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react-refresh/only-export-components */
export * from '@smile/react-front-kit-shared';
// component exports
export * from './Components/Filters/Filters';
export * from './Components/DocumentCard/DocumentCard';
export * from './Components/BitConverter/BitConverter';
export * from './Components/Breadcrumbs/Breadcrumbs';
Expand Down

0 comments on commit 9d7399a

Please sign in to comment.