@omniumretail/component-library 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/main.js +2 -7
- package/.storybook/preview.js +1 -0
- package/dist/bundle.js +7457 -0
- package/dist/main.css +263 -0
- package/dist/types/components/Button/Button.stories.d.ts +6 -0
- package/dist/types/components/Button/index.d.ts +6 -0
- package/dist/types/components/Header/Header.stories.d.ts +5 -0
- package/dist/types/components/Header/index.d.ts +6 -0
- package/dist/types/components/Input/Input.stories.d.ts +5 -0
- package/dist/types/components/Input/index.d.ts +7 -0
- package/dist/types/components/InputCountryCode/index.d.ts +8 -0
- package/dist/types/components/InputCountryCode/inputCountryCode.stories.d.ts +5 -0
- package/dist/types/components/Label/Label.stories.d.ts +6 -0
- package/dist/types/components/Label/index.d.ts +5 -0
- package/dist/types/components/Link/Link.stories.d.ts +7 -0
- package/dist/types/components/Link/index.d.ts +6 -0
- package/dist/types/components/Select/Select.stories.d.ts +6 -0
- package/dist/types/components/Select/index.d.ts +2 -0
- package/dist/types/components/Separator/Separator.stories.d.ts +6 -0
- package/dist/types/components/Separator/index.d.ts +11 -0
- package/dist/types/components/Table/Table.stories.d.ts +7 -0
- package/dist/types/components/Table/index.d.ts +19 -0
- package/dist/types/components/Tag/Tag.stories.d.ts +5 -0
- package/dist/types/components/Tag/index.d.ts +5 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/constants/i18n.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +125 -16
- package/src/assets/scss/_global.scss +2 -2
- package/src/components/Button/Button.stories.tsx +1 -1
- package/src/components/Button/{Button.tsx → index.tsx} +0 -0
- package/src/components/Button/styles.module.scss +1 -3
- package/src/components/Header/Header.stories.tsx +1 -1
- package/src/components/Header/{Header.tsx → index.tsx} +2 -2
- package/src/components/Input/Input.stories.tsx +13 -0
- package/src/components/Input/index.tsx +21 -0
- package/src/components/Input/styles.module.scss +8 -0
- package/src/components/InputCountryCode/index.tsx +65 -0
- package/src/components/InputCountryCode/inputCountryCode.stories.tsx +33 -0
- package/src/components/InputCountryCode/styles.module.scss +3 -0
- package/src/components/Label/Label.stories.tsx +1 -1
- package/src/components/Label/{Label.tsx → index.tsx} +0 -0
- package/src/components/Link/Link.stories.tsx +1 -2
- package/src/components/Link/{Link.tsx → index.tsx} +0 -0
- package/src/components/Select/Select.stories.tsx +1 -1
- package/src/components/Select/{Select.tsx → index.tsx} +2 -1
- package/src/components/Select/styles.module.scss +3 -0
- package/src/components/Separator/Separator.stories.tsx +1 -1
- package/src/components/Separator/{Separator.tsx → index.tsx} +0 -0
- package/src/components/Table/Table.stories.tsx +152 -0
- package/src/components/Table/index.tsx +127 -0
- package/src/components/Table/styles.module.scss +63 -0
- package/src/components/Tag/Tag.stories.tsx +1 -1
- package/src/components/Tag/{Tag.tsx → index.tsx} +0 -0
- package/src/components/index.tsx +10 -0
- package/src/constants/i18n.ts +22 -0
- package/src/index.ts +1 -0
- package/src/locales/en.json +10 -0
- package/src/locales/es.json +10 -0
- package/src/locales/pt.json +10 -0
- package/src/types/Global.d.ts +4 -0
- package/tsconfig.json +4 -1
- package/webpack.config.js +48 -0
- package/.storybook/scss-presets.js +0 -61
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/src/App.css +0 -38
- package/src/App.test.tsx +0 -9
- package/src/App.tsx +0 -26
- package/src/index.css +0 -13
- package/src/index.js +0 -11
- package/src/index.tsx +0 -19
- package/src/logo.svg +0 -1
- package/src/react-app-env.d.ts +0 -1
- package/src/reportWebVitals.ts +0 -15
- package/src/setupTests.ts +0 -5
- package/storybook-static/229.99f6e327a87e983c7389.manager.bundle.js +0 -1
- package/storybook-static/229.f45c6d90.iframe.bundle.js +0 -1
- package/storybook-static/273.a2543f76.iframe.bundle.js +0 -2
- package/storybook-static/273.a2543f76.iframe.bundle.js.LICENSE.txt +0 -14
- package/storybook-static/295.872d37b80366654037c8.manager.bundle.js +0 -1
- package/storybook-static/409.1f5bfb7f7210fda2e343.manager.bundle.js +0 -2
- package/storybook-static/409.1f5bfb7f7210fda2e343.manager.bundle.js.LICENSE.txt +0 -97
- package/storybook-static/51.055af41355d551455300.manager.bundle.js +0 -2
- package/storybook-static/51.055af41355d551455300.manager.bundle.js.LICENSE.txt +0 -8
- package/storybook-static/51.69587a88.iframe.bundle.js +0 -2
- package/storybook-static/51.69587a88.iframe.bundle.js.LICENSE.txt +0 -8
- package/storybook-static/548.2c621cac.iframe.bundle.js +0 -2
- package/storybook-static/548.2c621cac.iframe.bundle.js.LICENSE.txt +0 -102
- package/storybook-static/551.1647eb5d.iframe.bundle.js +0 -1
- package/storybook-static/551.7bddf628ac2ec1b17e0f.manager.bundle.js +0 -1
- package/storybook-static/701.d0c6e7bf.iframe.bundle.js +0 -1
- package/storybook-static/745.50b11d25.iframe.bundle.js +0 -1
- package/storybook-static/807.5048a3e40f1d1f1e3d8f.manager.bundle.js +0 -2
- package/storybook-static/807.5048a3e40f1d1f1e3d8f.manager.bundle.js.LICENSE.txt +0 -31
- package/storybook-static/807.899ed15a.iframe.bundle.js +0 -2
- package/storybook-static/807.899ed15a.iframe.bundle.js.LICENSE.txt +0 -31
- package/storybook-static/897.71aad9b5e10ae8334ffb.manager.bundle.js +0 -2
- package/storybook-static/897.71aad9b5e10ae8334ffb.manager.bundle.js.LICENSE.txt +0 -12
- package/storybook-static/897.e263bb0b.iframe.bundle.js +0 -2
- package/storybook-static/897.e263bb0b.iframe.bundle.js.LICENSE.txt +0 -12
- package/storybook-static/935.1d59a0f5d5ffadecc0db.manager.bundle.js +0 -1
- package/storybook-static/935.a9f48572.iframe.bundle.js +0 -1
- package/storybook-static/favicon.ico +0 -0
- package/storybook-static/iframe.html +0 -364
- package/storybook-static/index.html +0 -59
- package/storybook-static/logo192.png +0 -0
- package/storybook-static/logo512.png +0 -0
- package/storybook-static/main.bfef8ba6.iframe.bundle.js +0 -1
- package/storybook-static/main.dd12082b9ec45829986e.manager.bundle.js +0 -1
- package/storybook-static/manifest.json +0 -25
- package/storybook-static/project.json +0 -1
- package/storybook-static/robots.txt +0 -3
- package/storybook-static/runtime~main.1f97ee70.iframe.bundle.js +0 -1
- package/storybook-static/runtime~main.4332445a1662821dad2a.manager.bundle.js +0 -1
- package/storybook-static/static/css/main.f5f2ee7f.css +0 -10
- package/storybook-static/static/css/main.f5f2ee7f.css.map +0 -1
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
&:hover {
|
|
19
19
|
background-color: var(--button-default-background-hover-color);
|
|
20
|
-
//override ANTD default colors
|
|
21
20
|
color: var(--button-default-text-hover-color) !important;
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -39,14 +38,13 @@
|
|
|
39
38
|
flex-direction: row-reverse;
|
|
40
39
|
gap: 5px;
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
|
|
43
42
|
&--style1 {
|
|
44
43
|
background-color: var(--button-style-1-background);
|
|
45
44
|
color: var(--button-style-1-text-color);
|
|
46
45
|
|
|
47
46
|
&:hover {
|
|
48
47
|
background-color: var(--button-style-1-background-hover-color);
|
|
49
|
-
//override ANTD default colors
|
|
50
48
|
color: var(--button-style-1-text-hover-color) !important;
|
|
51
49
|
}
|
|
52
50
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import styles from './styles.module.scss';
|
|
2
|
-
import { Link } from '../Link
|
|
2
|
+
import { Link } from '../Link';
|
|
3
3
|
import { ArrowLeftOutlined, HomeOutlined, LogoutOutlined } from '@ant-design/icons';
|
|
4
4
|
|
|
5
5
|
export interface HeaderProps {
|
|
@@ -10,7 +10,7 @@ export interface HeaderProps {
|
|
|
10
10
|
|
|
11
11
|
export const Header = (props: HeaderProps) => {
|
|
12
12
|
const { backLink, title, homeLink } = props;
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
return (
|
|
15
15
|
<div className={styles.header}>
|
|
16
16
|
<div className={styles.columnLeft}>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Meta, Story } from "@storybook/react";
|
|
2
|
+
import { FormInputField, FormInputFieldProps } from '.';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'FormInputField',
|
|
6
|
+
component: FormInputField,
|
|
7
|
+
} as Meta;
|
|
8
|
+
|
|
9
|
+
const Template: Story<FormInputFieldProps> = (args) => <FormInputField {...args}></FormInputField>;
|
|
10
|
+
|
|
11
|
+
export const Primary = Template.bind({});
|
|
12
|
+
Primary.args = {
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Form, FormItemProps, Input, InputProps } from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RefAttributes } from 'react';
|
|
4
|
+
import styles from './styles.module.scss';
|
|
5
|
+
|
|
6
|
+
export interface FormInputFieldProps extends Omit<FormItemProps, "name"> {
|
|
7
|
+
name: string;
|
|
8
|
+
inputProps?: InputProps;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const InputField = (inputProps: InputProps) => (
|
|
12
|
+
<Input className={styles.input} {...inputProps} />
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const FormInputField = ({ inputProps, ...itemProps }: FormInputFieldProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<Form.Item {...itemProps}>
|
|
18
|
+
<InputField {...inputProps} />
|
|
19
|
+
</Form.Item>
|
|
20
|
+
)
|
|
21
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback, useState, useEffect } from 'react';
|
|
2
|
+
import { Form, FormItemProps, Input, InputProps, SelectProps } from 'antd';
|
|
3
|
+
import { InputField } from '../Input';
|
|
4
|
+
import { CustomSelect } from '../Select';
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
|
|
7
|
+
export interface FormInputCountryCodeProps extends Omit<FormItemProps, "name"> {
|
|
8
|
+
name: string;
|
|
9
|
+
selectProps?: SelectProps;
|
|
10
|
+
inputProps?: InputProps;
|
|
11
|
+
inputWithSelectBoxValue?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface CountryCodeProps {
|
|
15
|
+
value?: string;
|
|
16
|
+
onChange?: (value: string) => void;
|
|
17
|
+
selectProps?: SelectProps;
|
|
18
|
+
inputProps?: InputProps;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const CountryCode = ({ value, onChange, selectProps, inputProps }: CountryCodeProps) => {
|
|
22
|
+
const[inputDefaultValue, setInputDefaultValue] = useState<any>(inputProps?.defaultValue);
|
|
23
|
+
|
|
24
|
+
useEffect(()=> {
|
|
25
|
+
setInputDefaultValue(inputProps?.defaultValue);
|
|
26
|
+
}, [])
|
|
27
|
+
|
|
28
|
+
const validCountryCode = selectProps?.options?.find((countryCode) => {
|
|
29
|
+
return value?.startsWith(countryCode.value as string);
|
|
30
|
+
})?.value || "";
|
|
31
|
+
|
|
32
|
+
const phoneNumber = value?.replace(validCountryCode as string || "", "") || "";
|
|
33
|
+
const changeLocalValue = useCallback((value: string | number, element: string) => {
|
|
34
|
+
if(element !== 'countryCode') {
|
|
35
|
+
setInputDefaultValue(value);
|
|
36
|
+
onChange?.(`${validCountryCode}${value}` || "");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const valueReplaced = `${value}${phoneNumber}`;
|
|
41
|
+
|
|
42
|
+
onChange?.(valueReplaced || "");
|
|
43
|
+
}, [value, onChange]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Input.Group compact className={styles.inputGroup}>
|
|
47
|
+
<CustomSelect
|
|
48
|
+
{...selectProps}
|
|
49
|
+
value={validCountryCode || selectProps?.defaultValue}
|
|
50
|
+
onChange={(value) => changeLocalValue(value, 'countryCode')}
|
|
51
|
+
>
|
|
52
|
+
</CustomSelect>
|
|
53
|
+
<InputField { ...inputProps } value={phoneNumber || inputDefaultValue} onChange={(event) => changeLocalValue(event.target.value, 'phoneNumber')}/>
|
|
54
|
+
</Input.Group>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const InputCountryCode = ({ inputProps, selectProps, inputWithSelectBoxValue, ...itemProps}: FormInputCountryCodeProps) => {
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Form.Item {...itemProps}>
|
|
62
|
+
<CountryCode inputProps={inputProps} selectProps={selectProps} />
|
|
63
|
+
</Form.Item>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Form , Button} from 'antd';
|
|
2
|
+
import { Meta, Story } from "@storybook/react";
|
|
3
|
+
import { InputCountryCode, FormInputCountryCodeProps } from '.';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'InputCountryCode',
|
|
7
|
+
component: InputCountryCode,
|
|
8
|
+
} as Meta;
|
|
9
|
+
|
|
10
|
+
const Template: Story<FormInputCountryCodeProps> = (args) => <Form>
|
|
11
|
+
<InputCountryCode {...args}></InputCountryCode>
|
|
12
|
+
</Form>;
|
|
13
|
+
|
|
14
|
+
export const Primary = Template.bind({});
|
|
15
|
+
Primary.args = {
|
|
16
|
+
name: "test",
|
|
17
|
+
inputProps: {
|
|
18
|
+
defaultValue: 961303639,
|
|
19
|
+
},
|
|
20
|
+
selectProps: {
|
|
21
|
+
defaultValue: 'PT',
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
label: 'PT',
|
|
25
|
+
value: '+351',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'KZ',
|
|
29
|
+
value: '94',
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
};
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Meta, Story } from "@storybook/react";
|
|
2
|
-
import { Link, CustomLinkProps } from '
|
|
2
|
+
import { Link, CustomLinkProps } from '.';
|
|
3
3
|
import { SearchOutlined } from '@ant-design/icons';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
@@ -28,4 +28,3 @@ iconAlignRight.args = {
|
|
|
28
28
|
linkSecondary: true,
|
|
29
29
|
icon: <SearchOutlined />
|
|
30
30
|
};
|
|
31
|
-
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Meta, Story } from "@storybook/react";
|
|
2
|
+
import { CustomTable, customTableProps } from '.';
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'customTable',
|
|
7
|
+
component: CustomTable,
|
|
8
|
+
} as Meta;
|
|
9
|
+
|
|
10
|
+
const Template: Story<customTableProps> = (args) => {
|
|
11
|
+
const [pageInfo, setPageInfo] = useState<any>({});
|
|
12
|
+
// const [sortingInfo, setSortingInfo] = useState<any>({});
|
|
13
|
+
const [sortBy, setSortBy] = useState<string[]>(['key', 'desc']);
|
|
14
|
+
|
|
15
|
+
const newDataSource = args.dataSource?.slice().sort((a, b) => {
|
|
16
|
+
if(sortBy[1] === 'asc') {
|
|
17
|
+
return a[sortBy[0]].localeCompare(b[sortBy[0]]);
|
|
18
|
+
} else {
|
|
19
|
+
debugger;
|
|
20
|
+
return b[sortBy[0]].localeCompare(a[sortBy[0]]);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return <CustomTable {...args} dataSource={newDataSource} onSort={(field, sort) => setSortBy([field, sort]) } paginationInfo={setPageInfo} headingTranslationsKey={'tableHeadings'} ></CustomTable>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Primary = Template.bind({});
|
|
28
|
+
Primary.args = {
|
|
29
|
+
fieldsToSort: ['store', 'mecanographicNumber'],
|
|
30
|
+
selectPlaceholder: 'Order by',
|
|
31
|
+
dataSource: [
|
|
32
|
+
{
|
|
33
|
+
key: `1`,
|
|
34
|
+
name: `John Brown`,
|
|
35
|
+
mecanographicNumber: "232",
|
|
36
|
+
store: `Levi's Sta Catarina`,
|
|
37
|
+
role: `Gerente`,
|
|
38
|
+
type: `Efetivo`
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: `2`,
|
|
42
|
+
name: `Mary Brown`,
|
|
43
|
+
mecanographicNumber: "32",
|
|
44
|
+
store: `Levi's Sta Catarina`,
|
|
45
|
+
role: `Comercial`,
|
|
46
|
+
type: `Efetivo`
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: `3`,
|
|
50
|
+
name: `Anna Astori`,
|
|
51
|
+
mecanographicNumber: "3212",
|
|
52
|
+
store: `Levi's Sta Catarina`,
|
|
53
|
+
role: `Funcionário`,
|
|
54
|
+
type: `Efetivo`
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: `4`,
|
|
58
|
+
name: `Yield Ona`,
|
|
59
|
+
mecanographicNumber: "21232",
|
|
60
|
+
store: `Adidas Restaurantes`,
|
|
61
|
+
role: `Gerente`,
|
|
62
|
+
type: `Efetivo`
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
pagination: {
|
|
66
|
+
total: 24,
|
|
67
|
+
pageSize: 4
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const Secondary = Template.bind({});
|
|
72
|
+
Secondary.args = {
|
|
73
|
+
dataSource: [
|
|
74
|
+
{
|
|
75
|
+
key: `1`,
|
|
76
|
+
name: `as John Brown`,
|
|
77
|
+
mecanographicNumber: 232,
|
|
78
|
+
store: `Levi's Sta Catarina`,
|
|
79
|
+
role: `Gerente`,
|
|
80
|
+
type: `Efetivo`
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
key: `2`,
|
|
84
|
+
name: `bv Mary Brown`,
|
|
85
|
+
mecanographicNumber: 32,
|
|
86
|
+
store: `Levi's Sta Catarina`,
|
|
87
|
+
role: `Comercial`,
|
|
88
|
+
type: `Efetivo`
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
key: `3`,
|
|
92
|
+
name: `as Anna Astori`,
|
|
93
|
+
mecanographicNumber: 3212,
|
|
94
|
+
store: `Levi's Sta Catarina`,
|
|
95
|
+
role: `Funcionário`,
|
|
96
|
+
type: `Efetivo`
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
key: `4`,
|
|
100
|
+
name: `bv Yield Ona`,
|
|
101
|
+
mecanographicNumber: 21232,
|
|
102
|
+
store: `Adidas Restaurantes`,
|
|
103
|
+
role: `Gerente`,
|
|
104
|
+
type: `Efetivo`
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
pagination: {
|
|
108
|
+
total: 4,
|
|
109
|
+
pageSize: 10
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const WithCheckbox = Template.bind({});
|
|
114
|
+
WithCheckbox.args = {
|
|
115
|
+
dataSource: [
|
|
116
|
+
{
|
|
117
|
+
key: `1`,
|
|
118
|
+
name: `John Brown`,
|
|
119
|
+
mecanographicNumber: 232,
|
|
120
|
+
store: `Levi's Sta Catarina`,
|
|
121
|
+
role: `Gerente`,
|
|
122
|
+
type: `Efetivo`
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
key: `2`,
|
|
126
|
+
name: `Mary Brown`,
|
|
127
|
+
mecanographicNumber: 32,
|
|
128
|
+
store: `Levi's Sta Catarina`,
|
|
129
|
+
role: `Comercial`,
|
|
130
|
+
type: `Efetivo`
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
key: `3`,
|
|
134
|
+
name: `Anna Astori`,
|
|
135
|
+
mecanographicNumber: 3212,
|
|
136
|
+
store: `Levi's Sta Catarina`,
|
|
137
|
+
role: `Funcionário`,
|
|
138
|
+
type: `Efetivo`
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
key: `4`,
|
|
142
|
+
name: `Yield Ona`,
|
|
143
|
+
mecanographicNumber: 21232,
|
|
144
|
+
store: `Adidas Restaurantes`,
|
|
145
|
+
role: `Gerente`,
|
|
146
|
+
type: `Efetivo`
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
rowSelection: {
|
|
150
|
+
type: "checkbox"
|
|
151
|
+
}
|
|
152
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { Space, TableProps, Select } from 'antd';
|
|
3
|
+
import { Table } from 'antd';
|
|
4
|
+
import type { ColumnsType } from 'antd/es/table/interface';
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
|
|
8
|
+
export interface FilterOptions {
|
|
9
|
+
value: string,
|
|
10
|
+
label: string,
|
|
11
|
+
direction: string,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum sortBy {
|
|
15
|
+
asc = 'asc',
|
|
16
|
+
desc = 'desc',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface customTableProps extends TableProps<any> {
|
|
20
|
+
fieldsToSort?: any[],
|
|
21
|
+
selectPlaceholder?: string,
|
|
22
|
+
onSort?: (field: any, sortBy: any) => void;
|
|
23
|
+
sortInfo?: any;
|
|
24
|
+
paginationInfo?: any;
|
|
25
|
+
headingTranslationsKey?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const CustomTable = (props: customTableProps) => {
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
dataSource,
|
|
33
|
+
fieldsToSort = ['key', 'name', 'store'],
|
|
34
|
+
selectPlaceholder, onSort,
|
|
35
|
+
headingTranslationsKey
|
|
36
|
+
} = props;
|
|
37
|
+
|
|
38
|
+
const [customFilters, setCustomFilters] = useState<any>([]);
|
|
39
|
+
const [customColumns, setCustomColumns] = useState<ColumnsType<any>>([]);
|
|
40
|
+
const [sortInfo, setSortInfo] = useState<any>([]);
|
|
41
|
+
|
|
42
|
+
const handleChange: TableProps<any>['onChange'] = (pagination) => {
|
|
43
|
+
const getPagination = {
|
|
44
|
+
currentPage: pagination.current,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getSortAndPaginationInfo = {...sortInfo, ...getPagination}
|
|
48
|
+
props.paginationInfo(getSortAndPaginationInfo);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const setSorter = (option: any) => {
|
|
52
|
+
onSort?.(option.value.split('-')[0], option.direction);
|
|
53
|
+
const sortData = {
|
|
54
|
+
sortDirection: option.direction,
|
|
55
|
+
sortValue: option.value.split('-')[0],
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setSortInfo(sortData)
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
// Columns
|
|
63
|
+
const columns = Object.keys(dataSource?.[0]).map(key => ({
|
|
64
|
+
title: headingTranslationsKey ? `${headingTranslationsKey}.${key}` : key,
|
|
65
|
+
dataIndex: key,
|
|
66
|
+
key: key,
|
|
67
|
+
ellipsis: true,
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
setCustomColumns(columns);
|
|
71
|
+
|
|
72
|
+
// Filters
|
|
73
|
+
const dataKeysToFilter = Object.keys(dataSource?.[0]).filter((el) => fieldsToSort.includes(el));
|
|
74
|
+
|
|
75
|
+
const filters = ([] as FilterOptions[]).concat(
|
|
76
|
+
...dataKeysToFilter.map(key => ({
|
|
77
|
+
value: `${key}-${sortBy.desc}`,
|
|
78
|
+
label: `${headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key} (${sortBy.desc})`,
|
|
79
|
+
direction: `${sortBy.desc}`,
|
|
80
|
+
})),
|
|
81
|
+
...dataKeysToFilter.map(key => ({
|
|
82
|
+
value: `${key}-${sortBy.asc}`,
|
|
83
|
+
label: `${headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key} (${sortBy.asc})`,
|
|
84
|
+
direction: `${sortBy.asc}`,
|
|
85
|
+
}))
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
setCustomFilters(filters);
|
|
89
|
+
}, [dataSource]);
|
|
90
|
+
|
|
91
|
+
const shouldRenderSortDropdown = customFilters.length > 0;
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div className={styles.tableWrapper}>
|
|
95
|
+
{shouldRenderSortDropdown &&
|
|
96
|
+
<Space style={{ marginBottom: 16 }}>
|
|
97
|
+
<Select
|
|
98
|
+
style={{ width: 'auto', minWidth: 200 }}
|
|
99
|
+
placeholder={selectPlaceholder}
|
|
100
|
+
onSelect={(_, option: any) => {
|
|
101
|
+
setSorter(option);
|
|
102
|
+
}}
|
|
103
|
+
optionFilterProp="children"
|
|
104
|
+
filterOption={(input, option) => (option?.label ?? '').includes(input)}
|
|
105
|
+
filterSort={(optionA, optionB) =>
|
|
106
|
+
(optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase())
|
|
107
|
+
}
|
|
108
|
+
options={customFilters}
|
|
109
|
+
/>
|
|
110
|
+
</Space>
|
|
111
|
+
}
|
|
112
|
+
<Table
|
|
113
|
+
dataSource={dataSource}
|
|
114
|
+
onChange={handleChange}
|
|
115
|
+
{...props}
|
|
116
|
+
>
|
|
117
|
+
{customColumns.map((column) => (
|
|
118
|
+
<Table.Column
|
|
119
|
+
key={column.key}
|
|
120
|
+
title={headingTranslationsKey ? t(column.title as string) : column.title}
|
|
121
|
+
dataIndex={(column as any).dataIndex}
|
|
122
|
+
/>
|
|
123
|
+
))}
|
|
124
|
+
</Table>
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
.tableWrapper {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
|
|
6
|
+
:global {
|
|
7
|
+
.ant-table-thead > tr > th {
|
|
8
|
+
background-color: transparent;
|
|
9
|
+
border: 0px;
|
|
10
|
+
color: var(--color-blue);
|
|
11
|
+
|
|
12
|
+
&:before {
|
|
13
|
+
display: none;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ant-table-tbody {
|
|
18
|
+
> tr {
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
|
|
21
|
+
&:last-child {
|
|
22
|
+
> td {
|
|
23
|
+
border-bottom: 1px solid var(--color-grey-light) !important;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&:first-child {
|
|
28
|
+
> td {
|
|
29
|
+
border-top: 1px solid var(--color-blue) !important;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:hover {
|
|
34
|
+
td {
|
|
35
|
+
border-radius: 0 !important;
|
|
36
|
+
border-bottom-color: var(--color-grey-light) !important;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ant-space {
|
|
43
|
+
align-self: flex-end;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ant-select-selection-placeholder {
|
|
47
|
+
color: var(--color-black);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.ant-select-selector,
|
|
51
|
+
.ant-select-focused
|
|
52
|
+
.ant-select-selection-search {
|
|
53
|
+
border: none !important;
|
|
54
|
+
box-shadow: none !important;
|
|
55
|
+
|
|
56
|
+
&:focus,
|
|
57
|
+
&:hover {
|
|
58
|
+
border: none !important;
|
|
59
|
+
box-shadow: none !important;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './Button';
|
|
2
|
+
export * from './Header';
|
|
3
|
+
export * from './Input';
|
|
4
|
+
export * from './InputCountryCode';
|
|
5
|
+
export * from './Label';
|
|
6
|
+
export * from './Link';
|
|
7
|
+
export * from './Select';
|
|
8
|
+
export * from './Separator';
|
|
9
|
+
export * from './Table';
|
|
10
|
+
export * from './Tag';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import i18next from 'i18next';
|
|
2
|
+
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
3
|
+
import { initReactI18next } from "react-i18next";
|
|
4
|
+
import en from '../locales/en.json';
|
|
5
|
+
import es from '../locales/es.json';
|
|
6
|
+
import pt from '../locales/pt.json';
|
|
7
|
+
|
|
8
|
+
i18next
|
|
9
|
+
.use(initReactI18next)
|
|
10
|
+
.use(LanguageDetector)
|
|
11
|
+
.init({
|
|
12
|
+
resources: {
|
|
13
|
+
en: { translation: en },
|
|
14
|
+
pt: { translation: pt },
|
|
15
|
+
es: { translation: es },
|
|
16
|
+
},
|
|
17
|
+
detection: {
|
|
18
|
+
order: ['querystring', 'navigator', 'htmlTag'],
|
|
19
|
+
lookupQuerystring: 'lng',
|
|
20
|
+
htmlTag: document.documentElement,
|
|
21
|
+
},
|
|
22
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|