@xaypay/tui 0.0.28 → 0.0.30
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/dist/index.es.js +220 -124
- package/dist/index.js +220 -123
- package/package.json +1 -1
- package/src/components/checkbox/index.js +5 -1
- package/src/components/table/index.js +125 -0
- package/src/components/table/table.module.css +80 -0
- package/src/components/table/table.stories.js +36 -0
- package/src/index.js +2 -1
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ export const Checkbox = ({
|
|
|
14
14
|
onChange,
|
|
15
15
|
label,
|
|
16
16
|
keyNames,
|
|
17
|
+
onClick,
|
|
17
18
|
...props
|
|
18
19
|
}) => {
|
|
19
20
|
const classProps = classNames(styles.checkbox, className);
|
|
@@ -26,7 +27,7 @@ export const Checkbox = ({
|
|
|
26
27
|
setData(parseData);
|
|
27
28
|
},[jsonData])
|
|
28
29
|
useEffect(()=>{
|
|
29
|
-
onChange(data.filter(d => d.checked));
|
|
30
|
+
onChange ? onChange(data.filter(d => d.checked)) : '';
|
|
30
31
|
},[data])
|
|
31
32
|
|
|
32
33
|
const handleChange = e => {
|
|
@@ -60,6 +61,8 @@ export const Checkbox = ({
|
|
|
60
61
|
name={keyNames.name ? element[keyNames.name] : ''}
|
|
61
62
|
id={keyNames.id ? element[keyNames.id] : ''}
|
|
62
63
|
onChange={handleChange}
|
|
64
|
+
onClick={onClick ? onClick: ()=>{}}
|
|
65
|
+
defaultChecked = {element.checked}
|
|
63
66
|
{...props}
|
|
64
67
|
/>
|
|
65
68
|
<span className={styles["checkmark"]} />
|
|
@@ -83,6 +86,7 @@ export const Checkbox = ({
|
|
|
83
86
|
Checkbox.propTypes = {
|
|
84
87
|
className: PropTypes.string,
|
|
85
88
|
onChange: PropTypes.func,
|
|
89
|
+
onClick: PropTypes.func,
|
|
86
90
|
required: PropTypes.bool,
|
|
87
91
|
disabled: PropTypes.bool,
|
|
88
92
|
name: PropTypes.string,
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import PropTypes, { bool, checkPropTypes, func } from "prop-types";
|
|
3
|
+
import classnames from "classnames";
|
|
4
|
+
import styles from "./table.module.css";
|
|
5
|
+
import { Checkbox } from "../checkbox";
|
|
6
|
+
|
|
7
|
+
export const Table = ({
|
|
8
|
+
className,
|
|
9
|
+
onChange,
|
|
10
|
+
config,
|
|
11
|
+
jsonData,
|
|
12
|
+
hearderData,
|
|
13
|
+
keyNames,
|
|
14
|
+
actions,
|
|
15
|
+
...props
|
|
16
|
+
}) => {
|
|
17
|
+
const classProps = classnames(className);
|
|
18
|
+
let tbodyData = jsonData.length ? JSON.parse(jsonData) : [];
|
|
19
|
+
|
|
20
|
+
useEffect(()=>{
|
|
21
|
+
tbodyData = jsonData.length ? JSON.parse(jsonData) : [];
|
|
22
|
+
},[jsonData])
|
|
23
|
+
|
|
24
|
+
const [checked,setChecked] = useState(config.isCheckbox && config.isCheckbox.checked ? config.isCheckbox.checked : []);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
config.isCheckbox && config.isCheckbox.showCheckbox == undefined
|
|
28
|
+
? (config.isCheckbox.showCheckbox = () => {
|
|
29
|
+
return true;
|
|
30
|
+
})
|
|
31
|
+
: "";
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className={styles["table-wrap"]}>
|
|
35
|
+
{config.isHeader &&
|
|
36
|
+
hearderData.map((header, key) => {
|
|
37
|
+
return (
|
|
38
|
+
<div className={styles["table-top"]} key={key}>
|
|
39
|
+
<div className={styles["table-items"]}>
|
|
40
|
+
{header}
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
<div className={styles["table-bottom"]}>
|
|
46
|
+
{tbodyData.map((item, key) => {
|
|
47
|
+
return (
|
|
48
|
+
<div className={styles["table-bottom-inner"]} key={key}>
|
|
49
|
+
{keyNames.map((keyName, keyNameKey) => {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
className={styles["table-items"]}
|
|
53
|
+
key={keyNameKey}
|
|
54
|
+
>
|
|
55
|
+
{config.isCheckbox &&
|
|
56
|
+
config.isCheckbox.showCheckbox &&
|
|
57
|
+
config.isCheckbox.showCheckbox(
|
|
58
|
+
item
|
|
59
|
+
) &&
|
|
60
|
+
keyNameKey == 0 && (
|
|
61
|
+
<Checkbox
|
|
62
|
+
onClick={(e) => {
|
|
63
|
+
const id = e.target.id;
|
|
64
|
+
const checkedValue = e.target.checked;
|
|
65
|
+
let ch = [...checked]
|
|
66
|
+
checkedValue ? ch.push(Number(id)) : ch.splice(ch.indexOf(id), 1);
|
|
67
|
+
setChecked(ch);
|
|
68
|
+
config.isCheckbox.onChange(ch);
|
|
69
|
+
}}
|
|
70
|
+
jsonData={`[{"value":"", "name":"", "label":"", "id":${item.id}, "checked":${checked.indexOf(item.id) > -1 ? true : false }}]`}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
{typeof keyName === "string" ? (
|
|
74
|
+
item[keyName]
|
|
75
|
+
) : (
|
|
76
|
+
<>
|
|
77
|
+
<i className={keyName.icon} />
|
|
78
|
+
{item[keyName.name]}
|
|
79
|
+
</>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
})}
|
|
84
|
+
|
|
85
|
+
{actions && (
|
|
86
|
+
<div className={styles["table-items"]}>
|
|
87
|
+
{actions.filter(a => a.show && a.show(item) || a.show === undefined).map((action, key) => {
|
|
88
|
+
return (<div key={key}>
|
|
89
|
+
<i className={action.icon} onClick={action.click? action.click : ()=>{}}>
|
|
90
|
+
{action.icon}
|
|
91
|
+
</i>
|
|
92
|
+
</div>)
|
|
93
|
+
})}
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
})}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Table.propTypes = {
|
|
105
|
+
className: PropTypes.string,
|
|
106
|
+
onChange: PropTypes.func,
|
|
107
|
+
config: PropTypes.object,
|
|
108
|
+
actions: PropTypes.arrayOf(PropTypes.object),
|
|
109
|
+
jsonData: PropTypes.string,
|
|
110
|
+
keyNames: PropTypes.arrayOf(
|
|
111
|
+
PropTypes.oneOf([PropTypes.string, PropTypes.object])
|
|
112
|
+
),
|
|
113
|
+
hearderData: PropTypes.array,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Table.defaultProps = {
|
|
117
|
+
className: "",
|
|
118
|
+
onChange: undefined,
|
|
119
|
+
errorMesage: "",
|
|
120
|
+
config: { isHeader: true, isCheckbox: {checked:[]} },
|
|
121
|
+
actions: [],
|
|
122
|
+
jsonData: "",
|
|
123
|
+
keyNames: [],
|
|
124
|
+
hearderData: [],
|
|
125
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
.table-wrap {
|
|
2
|
+
width: 100%;
|
|
3
|
+
background: #fff;
|
|
4
|
+
box-shadow: 0 10px 30px rgba(0,35,106,.06);
|
|
5
|
+
border-radius: 14px 14px 0 0;
|
|
6
|
+
overflow: hidden
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.table-wrap:not(:first-child) {
|
|
10
|
+
margin-top: 30px
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.table-bottom-inner .table-items:first-child,.table-top .table-items:first-child {
|
|
14
|
+
flex: 0 0 auto;
|
|
15
|
+
width: 60px
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.table-bottom-inner .table-items:nth-child(2),.table-top .table-items:nth-child(2) {
|
|
19
|
+
flex: 0 0 auto;
|
|
20
|
+
width: 120px
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.table-bottom-inner .table-items:nth-child(3),.table-top .table-items:nth-child(3) {
|
|
24
|
+
flex: 0 0 auto;
|
|
25
|
+
width: 170px
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.table-bottom-inner .table-items:nth-child(4),.table-top .table-items:nth-child(4) {
|
|
29
|
+
flex: 0 0 auto;
|
|
30
|
+
width: 126px
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.table-bottom-inner .table-items:nth-child(5),.table-bottom-inner .table-items:nth-child(6),.table-bottom-inner .table-items:nth-child(8),.table-top .table-items:nth-child(5),.table-top .table-items:nth-child(6),.table-top .table-items:nth-child(8) {
|
|
34
|
+
flex: 0 0 auto;
|
|
35
|
+
width: 100px
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.table-bottom-inner .table-items:last-child,.table-top .table-items:last-child {
|
|
39
|
+
flex: 0 0 auto;
|
|
40
|
+
width: 104px
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.table-top {
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: 44px;
|
|
46
|
+
background: #00236a
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.table-top .table-items {
|
|
50
|
+
flex: 1 1;
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
text-align: center;
|
|
55
|
+
color: #fff;
|
|
56
|
+
font-size: 15px;
|
|
57
|
+
line-height: 17px
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.table-bottom-inner {
|
|
61
|
+
width: 100%;
|
|
62
|
+
min-height: 40px;
|
|
63
|
+
background: #fff
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.table-bottom-inner .table-items {
|
|
67
|
+
flex: 1 1;
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
text-align: center;
|
|
72
|
+
font-size: 14px;
|
|
73
|
+
line-height: 16px;
|
|
74
|
+
border-bottom: 1px solid #eee;
|
|
75
|
+
padding: 4px
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.table-bottom-inner .table-items:not(:last-child) {
|
|
79
|
+
border-right: 1px solid #eee
|
|
80
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Table } from "./index";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
component: Table,
|
|
6
|
+
title: "Components/Table",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const Template = (args) => <Table {...args} />;
|
|
10
|
+
|
|
11
|
+
export const Default = Template.bind({});
|
|
12
|
+
|
|
13
|
+
const showCheckbox = (item) => {
|
|
14
|
+
return true;
|
|
15
|
+
// return item.id === 2;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const onChange = (checked) => {
|
|
19
|
+
console.log("project",checked);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const show = () => {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const action = (id) => {
|
|
27
|
+
console.log('action from project',id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Default.args = {
|
|
31
|
+
config: {isHeader: true, isCheckbox: {showCheckbox: showCheckbox, checked: [], onChange: onChange }},
|
|
32
|
+
jsonData: JSON.stringify([{id:1,name:'Item 1',name2:'Item 1'},{id:2, name:'Item 2',name2:'Item 2'}]),
|
|
33
|
+
actions: [{icon: 'icon-1',show: show, click: action},{icon: 'icon-2'},{icon: 'icon-3'},{icon: 'icon-4'}],
|
|
34
|
+
keyNames: ['name',{name: 'name2', icon: 'icon-temp'}],
|
|
35
|
+
hearderData: ['first Name', 'Last Name']
|
|
36
|
+
};
|
package/src/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export * from './components/captcha';
|
|
|
10
10
|
export * from './components/stepper';
|
|
11
11
|
export * from './components/select';
|
|
12
12
|
export * from './components/file';
|
|
13
|
-
export * from './components/modal';
|
|
13
|
+
export * from './components/modal';
|
|
14
|
+
export * from './components/table';
|