@omniumretail/component-library 0.1.16 → 0.1.17
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/preview.js +3 -1
- package/dist/bundle.js +89 -2
- package/dist/types/components/Table/Table.stories.d.ts +1 -0
- package/dist/types/components/Table/index.d.ts +6 -0
- package/dist/types/constants/i18n.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -1
- package/src/components/Table/Table.stories.tsx +59 -3
- package/src/components/Table/index.tsx +49 -26
- package/src/constants/i18n.ts +6 -3
- package/src/index.ts +1 -0
- package/src/locales/en.json +4 -0
- package/src/locales/es.json +4 -0
- package/src/locales/pt.json +4 -0
|
@@ -4,6 +4,10 @@ export interface FilterOptions {
|
|
|
4
4
|
label: string;
|
|
5
5
|
direction: string;
|
|
6
6
|
}
|
|
7
|
+
export interface Actions {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
7
11
|
export declare enum sortBy {
|
|
8
12
|
asc = "asc",
|
|
9
13
|
desc = "desc"
|
|
@@ -15,5 +19,7 @@ export interface customTableProps extends TableProps<any> {
|
|
|
15
19
|
sortInfo?: any;
|
|
16
20
|
paginationInfo?: any;
|
|
17
21
|
headingTranslationsKey?: string;
|
|
22
|
+
actions: boolean;
|
|
23
|
+
actionsArray: any;
|
|
18
24
|
}
|
|
19
25
|
export declare const CustomTable: (props: customTableProps) => JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const mergei18n: (appResources: any) => void;
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omniumretail/component-library",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/bundle.js",
|
|
6
6
|
"typings": "./dist/types/index",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"jest": "^27.4.3",
|
|
44
44
|
"jest-resolve": "^27.4.2",
|
|
45
45
|
"jest-watch-typeahead": "^1.0.0",
|
|
46
|
+
"lodash.merge": "^4.6.2",
|
|
46
47
|
"mini-css-extract-plugin": "^2.7.2",
|
|
47
48
|
"moment": "^2.29.4",
|
|
48
49
|
"postcss": "^8.4.4",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Meta, Story } from "@storybook/react";
|
|
2
2
|
import { CustomTable, customTableProps } from '.';
|
|
3
3
|
import { useState } from "react";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
6
7
|
title: 'customTable',
|
|
@@ -8,20 +9,30 @@ export default {
|
|
|
8
9
|
} as Meta;
|
|
9
10
|
|
|
10
11
|
const Template: Story<customTableProps> = (args) => {
|
|
12
|
+
const { t } = useTranslation();
|
|
11
13
|
const [pageInfo, setPageInfo] = useState<any>({});
|
|
12
14
|
// const [sortingInfo, setSortingInfo] = useState<any>({});
|
|
13
15
|
const [sortBy, setSortBy] = useState<string[]>(['key', 'desc']);
|
|
14
16
|
|
|
15
17
|
const newDataSource = args.dataSource?.slice().sort((a, b) => {
|
|
16
|
-
if(sortBy[1] === 'asc') {
|
|
18
|
+
if (sortBy[1] === 'asc') {
|
|
17
19
|
return a[sortBy[0]].localeCompare(b[sortBy[0]]);
|
|
18
20
|
} else {
|
|
19
|
-
debugger;
|
|
20
21
|
return b[sortBy[0]].localeCompare(a[sortBy[0]]);
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
|
|
24
|
-
return <CustomTable {...args} dataSource={newDataSource} onSort={(field, sort) => setSortBy([field, sort])
|
|
25
|
+
return <CustomTable {...args} dataSource={newDataSource} onSort={(field, sort) => setSortBy([field, sort])} paginationInfo={setPageInfo} headingTranslationsKey={'tableHeadings'} actionsArray={
|
|
26
|
+
[
|
|
27
|
+
{ key: '1', label: `${t('actions.one')}`, onClick: () => {
|
|
28
|
+
console.log('oi');
|
|
29
|
+
} },
|
|
30
|
+
{ key: '2', label: `${t('actions.two')}` },
|
|
31
|
+
{
|
|
32
|
+
key: '3', label: 'label 3'
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}></CustomTable>;
|
|
25
36
|
};
|
|
26
37
|
|
|
27
38
|
export const Primary = Template.bind({});
|
|
@@ -150,3 +161,48 @@ WithCheckbox.args = {
|
|
|
150
161
|
type: "checkbox"
|
|
151
162
|
}
|
|
152
163
|
};
|
|
164
|
+
|
|
165
|
+
export const withActions = Template.bind({});
|
|
166
|
+
withActions.args = {
|
|
167
|
+
fieldsToSort: ['store', 'mecanographicNumber'],
|
|
168
|
+
selectPlaceholder: 'Order by',
|
|
169
|
+
dataSource: [
|
|
170
|
+
{
|
|
171
|
+
key: `1`,
|
|
172
|
+
name: `John Brown`,
|
|
173
|
+
mecanographicNumber: "232",
|
|
174
|
+
store: `Levi's Sta Catarina`,
|
|
175
|
+
role: `Gerente`,
|
|
176
|
+
type: `Efetivo`
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
key: `2`,
|
|
180
|
+
name: `Mary Brown`,
|
|
181
|
+
mecanographicNumber: "32",
|
|
182
|
+
store: `Levi's Sta Catarina`,
|
|
183
|
+
role: `Comercial`,
|
|
184
|
+
type: `Efetivo`
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
key: `3`,
|
|
188
|
+
name: `Anna Astori`,
|
|
189
|
+
mecanographicNumber: "3212",
|
|
190
|
+
store: `Levi's Sta Catarina`,
|
|
191
|
+
role: `Funcionário`,
|
|
192
|
+
type: `Efetivo`
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
key: `4`,
|
|
196
|
+
name: `Yield Ona`,
|
|
197
|
+
mecanographicNumber: "21232",
|
|
198
|
+
store: `Adidas Restaurantes`,
|
|
199
|
+
role: `Gerente`,
|
|
200
|
+
type: `Efetivo`
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
pagination: {
|
|
204
|
+
total: 24,
|
|
205
|
+
pageSize: 4
|
|
206
|
+
},
|
|
207
|
+
actions: true,
|
|
208
|
+
};
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
import { Space, TableProps, Select } from 'antd';
|
|
2
|
+
import { Space, TableProps, Select, Dropdown, MenuProps } from 'antd';
|
|
3
3
|
import { Table } from 'antd';
|
|
4
4
|
import type { ColumnsType } from 'antd/es/table/interface';
|
|
5
5
|
import styles from './styles.module.scss';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { EllipsisOutlined } from '@ant-design/icons';
|
|
7
8
|
|
|
8
9
|
export interface FilterOptions {
|
|
9
|
-
value: string
|
|
10
|
-
label: string
|
|
11
|
-
direction: string
|
|
10
|
+
value: string;
|
|
11
|
+
label: string;
|
|
12
|
+
direction: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Actions {
|
|
16
|
+
key: string;
|
|
17
|
+
label: string;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export enum sortBy {
|
|
@@ -23,18 +29,22 @@ export interface customTableProps extends TableProps<any> {
|
|
|
23
29
|
sortInfo?: any;
|
|
24
30
|
paginationInfo?: any;
|
|
25
31
|
headingTranslationsKey?: string;
|
|
32
|
+
actions: boolean;
|
|
33
|
+
actionsArray: any;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
export const CustomTable = (props: customTableProps) => {
|
|
29
37
|
const { t } = useTranslation();
|
|
30
38
|
|
|
31
|
-
const {
|
|
32
|
-
dataSource,
|
|
33
|
-
fieldsToSort = ['key', 'name', 'store'],
|
|
34
|
-
selectPlaceholder, onSort,
|
|
35
|
-
headingTranslationsKey
|
|
39
|
+
const {
|
|
40
|
+
dataSource,
|
|
41
|
+
fieldsToSort = ['key', 'name', 'store'],
|
|
42
|
+
selectPlaceholder, onSort,
|
|
43
|
+
headingTranslationsKey,
|
|
44
|
+
actions,
|
|
45
|
+
actionsArray: items,
|
|
36
46
|
} = props;
|
|
37
|
-
|
|
47
|
+
|
|
38
48
|
const [customFilters, setCustomFilters] = useState<any>([]);
|
|
39
49
|
const [customColumns, setCustomColumns] = useState<ColumnsType<any>>([]);
|
|
40
50
|
const [sortInfo, setSortInfo] = useState<any>([]);
|
|
@@ -44,7 +54,7 @@ export const CustomTable = (props: customTableProps) => {
|
|
|
44
54
|
currentPage: pagination.current,
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
const getSortAndPaginationInfo = {...sortInfo, ...getPagination}
|
|
57
|
+
const getSortAndPaginationInfo = { ...sortInfo, ...getPagination }
|
|
48
58
|
props.paginationInfo(getSortAndPaginationInfo);
|
|
49
59
|
};
|
|
50
60
|
|
|
@@ -60,12 +70,32 @@ export const CustomTable = (props: customTableProps) => {
|
|
|
60
70
|
|
|
61
71
|
useEffect(() => {
|
|
62
72
|
// Columns
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
let columns = Object.keys(dataSource?.[0]).map(key => {
|
|
74
|
+
return ({
|
|
75
|
+
title: headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key,
|
|
76
|
+
dataIndex: key,
|
|
77
|
+
key: key,
|
|
78
|
+
ellipsis: true,
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
let columnActions = {
|
|
83
|
+
title: 'Action',
|
|
84
|
+
key: 'action',
|
|
85
|
+
dataIndex: 6,
|
|
86
|
+
ellipsis: false,
|
|
87
|
+
render: () => (
|
|
88
|
+
<Space size="middle">
|
|
89
|
+
<Dropdown menu={{ items }}>
|
|
90
|
+
<a>
|
|
91
|
+
<EllipsisOutlined />
|
|
92
|
+
</a>
|
|
93
|
+
</Dropdown>
|
|
94
|
+
</Space>
|
|
95
|
+
),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
actions && columns.push(columnActions as any);
|
|
69
99
|
|
|
70
100
|
setCustomColumns(columns);
|
|
71
101
|
|
|
@@ -113,15 +143,8 @@ export const CustomTable = (props: customTableProps) => {
|
|
|
113
143
|
dataSource={dataSource}
|
|
114
144
|
onChange={handleChange}
|
|
115
145
|
{...props}
|
|
116
|
-
|
|
117
|
-
|
|
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>
|
|
146
|
+
columns={customColumns}
|
|
147
|
+
/>
|
|
125
148
|
</div>
|
|
126
149
|
);
|
|
127
150
|
}
|
package/src/constants/i18n.ts
CHANGED
|
@@ -4,19 +4,22 @@ import { initReactI18next } from "react-i18next";
|
|
|
4
4
|
import en from '../locales/en.json';
|
|
5
5
|
import es from '../locales/es.json';
|
|
6
6
|
import pt from '../locales/pt.json';
|
|
7
|
+
var merge = require('lodash.merge');
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
export const mergei18n = (appResources: any) => {
|
|
10
|
+
i18next
|
|
9
11
|
.use(initReactI18next)
|
|
10
12
|
.use(LanguageDetector)
|
|
11
13
|
.init({
|
|
12
|
-
resources: {
|
|
14
|
+
resources: merge({
|
|
13
15
|
en: { translation: en },
|
|
14
16
|
pt: { translation: pt },
|
|
15
17
|
es: { translation: es },
|
|
16
|
-
},
|
|
18
|
+
}, appResources),
|
|
17
19
|
detection: {
|
|
18
20
|
order: ['querystring', 'navigator', 'htmlTag'],
|
|
19
21
|
lookupQuerystring: 'lng',
|
|
20
22
|
htmlTag: document.documentElement,
|
|
21
23
|
},
|
|
22
24
|
});
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
package/src/locales/en.json
CHANGED
package/src/locales/es.json
CHANGED