aio-card 2.0.0 → 2.0.2
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/index.css +4 -1
- package/index.d.ts +69 -53
- package/index.js +32 -50
- package/package.json +1 -2
package/index.css
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
overflow: hidden;
|
|
4
4
|
display: flex;
|
|
5
5
|
flex-direction: column;
|
|
6
|
+
flex-shrink:0;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
.aio-cards-horizontal{
|
|
@@ -17,7 +18,9 @@
|
|
|
17
18
|
.aio-card-text{
|
|
18
19
|
height:100%;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
.aio-card-drag-icon{
|
|
22
|
+
width:12px;
|
|
23
|
+
}
|
|
21
24
|
.aio-card-footer{
|
|
22
25
|
overflow:hidden;
|
|
23
26
|
}
|
package/index.d.ts
CHANGED
|
@@ -16,86 +16,107 @@ export type I_Cards<T> = {
|
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
placeholder?: ReactNode;
|
|
18
18
|
option: {
|
|
19
|
-
|
|
20
|
-
row: T;
|
|
19
|
+
value?: (row: T, p: {
|
|
21
20
|
index: number;
|
|
21
|
+
value: any;
|
|
22
|
+
disabled: boolean;
|
|
23
|
+
row: any;
|
|
22
24
|
}) => ReactNode;
|
|
23
|
-
|
|
24
|
-
row: T;
|
|
25
|
+
text?: (row: T, p: {
|
|
25
26
|
index: number;
|
|
27
|
+
value: any;
|
|
28
|
+
disabled: boolean;
|
|
29
|
+
row: any;
|
|
26
30
|
}) => ReactNode;
|
|
27
|
-
show?: (p: {
|
|
28
|
-
row: T;
|
|
31
|
+
show?: (row: T, p: {
|
|
29
32
|
index: number;
|
|
33
|
+
value: any;
|
|
34
|
+
disabled: boolean;
|
|
35
|
+
row: any;
|
|
30
36
|
}) => boolean | undefined;
|
|
31
|
-
before?: (p: {
|
|
32
|
-
row: T;
|
|
37
|
+
before?: (row: T, p: {
|
|
33
38
|
index: number;
|
|
39
|
+
value: any;
|
|
40
|
+
disabled: boolean;
|
|
41
|
+
row: any;
|
|
34
42
|
}) => ReactNode[] | undefined;
|
|
35
|
-
after?: (p: {
|
|
36
|
-
row: T;
|
|
43
|
+
after?: (row: T, p: {
|
|
37
44
|
index: number;
|
|
45
|
+
value: any;
|
|
46
|
+
disabled: boolean;
|
|
47
|
+
row: any;
|
|
38
48
|
}) => ReactNode[] | undefined;
|
|
39
|
-
disabled?: (p: {
|
|
40
|
-
row: T;
|
|
49
|
+
disabled?: (row: T, p: {
|
|
41
50
|
index: number;
|
|
51
|
+
value: any;
|
|
52
|
+
disabled: boolean;
|
|
53
|
+
row: any;
|
|
42
54
|
}) => boolean | undefined;
|
|
43
|
-
header?: (p: {
|
|
44
|
-
row: T;
|
|
55
|
+
header?: (row: T, p: {
|
|
45
56
|
index: number;
|
|
57
|
+
value: any;
|
|
58
|
+
disabled: boolean;
|
|
59
|
+
row: any;
|
|
46
60
|
}) => ReactNode | undefined;
|
|
47
|
-
footer?: (p: {
|
|
48
|
-
row: T;
|
|
61
|
+
footer?: (row: T, p: {
|
|
49
62
|
index: number;
|
|
63
|
+
value: any;
|
|
64
|
+
disabled: boolean;
|
|
65
|
+
row: any;
|
|
50
66
|
}) => ReactNode | undefined;
|
|
51
|
-
layoutAttrs?: (p: {
|
|
52
|
-
row: T;
|
|
67
|
+
layoutAttrs?: (row: T, p: {
|
|
53
68
|
index: number;
|
|
69
|
+
value: any;
|
|
70
|
+
disabled: boolean;
|
|
71
|
+
row: any;
|
|
54
72
|
}) => any;
|
|
55
|
-
attrs?: (p: {
|
|
56
|
-
row: T;
|
|
73
|
+
attrs?: (row: T, p: {
|
|
57
74
|
index: number;
|
|
75
|
+
value: any;
|
|
76
|
+
disabled: boolean;
|
|
77
|
+
row: any;
|
|
58
78
|
}) => any;
|
|
59
|
-
footerAttrs?: (p: {
|
|
60
|
-
row: T;
|
|
79
|
+
footerAttrs?: (row: T, p: {
|
|
61
80
|
index: number;
|
|
81
|
+
value: any;
|
|
82
|
+
disabled: boolean;
|
|
83
|
+
row: any;
|
|
62
84
|
}) => any;
|
|
63
|
-
className?: (p: {
|
|
64
|
-
row: T;
|
|
85
|
+
className?: (row: T, p: {
|
|
65
86
|
index: number;
|
|
87
|
+
value: any;
|
|
88
|
+
disabled: boolean;
|
|
89
|
+
row: any;
|
|
66
90
|
}) => (string | undefined)[] | undefined;
|
|
67
|
-
style?: (p: {
|
|
68
|
-
row: T;
|
|
91
|
+
style?: (row: T, p: {
|
|
69
92
|
index: number;
|
|
93
|
+
value: any;
|
|
94
|
+
disabled: boolean;
|
|
95
|
+
row: any;
|
|
70
96
|
}) => any;
|
|
71
|
-
|
|
72
|
-
row: T;
|
|
73
|
-
index: number;
|
|
74
|
-
e?: React.MouseEvent<HTMLDivElement>;
|
|
75
|
-
}) => void;
|
|
76
|
-
actions?: (p: {
|
|
77
|
-
row: T;
|
|
78
|
-
index: number;
|
|
79
|
-
}) => {
|
|
80
|
-
text: ReactNode;
|
|
81
|
-
before?: ReactNode;
|
|
82
|
-
onClick?: () => void;
|
|
83
|
-
}[];
|
|
84
|
-
html?: (p: {
|
|
85
|
-
row: T;
|
|
97
|
+
html?: (row: T, p: {
|
|
86
98
|
index: number;
|
|
99
|
+
value: any;
|
|
100
|
+
disabled: boolean;
|
|
101
|
+
row: any;
|
|
87
102
|
}) => ReactNode;
|
|
88
|
-
showFooter?: (p: {
|
|
89
|
-
row: T;
|
|
103
|
+
showFooter?: (row: T, p: {
|
|
90
104
|
index: number;
|
|
105
|
+
value: any;
|
|
106
|
+
disabled: boolean;
|
|
107
|
+
row: any;
|
|
91
108
|
}) => boolean | undefined;
|
|
92
|
-
close?: (p: {
|
|
93
|
-
row: T;
|
|
109
|
+
close?: (row: T, p: {
|
|
94
110
|
index: number;
|
|
111
|
+
value: any;
|
|
112
|
+
disabled: boolean;
|
|
113
|
+
row: any;
|
|
95
114
|
}) => boolean;
|
|
96
|
-
justify?: (p: {
|
|
97
|
-
row: T;
|
|
115
|
+
justify?: (row: T, p: {
|
|
98
116
|
index: number;
|
|
117
|
+
value: any;
|
|
118
|
+
disabled: boolean;
|
|
119
|
+
row: any;
|
|
99
120
|
}) => boolean;
|
|
100
121
|
};
|
|
101
122
|
};
|
|
@@ -104,13 +125,7 @@ export type I_Card = {
|
|
|
104
125
|
before?: ReactNode[];
|
|
105
126
|
after?: ReactNode[];
|
|
106
127
|
text: ReactNode;
|
|
107
|
-
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
|
108
128
|
rtl?: boolean;
|
|
109
|
-
actions?: {
|
|
110
|
-
text: ReactNode;
|
|
111
|
-
before?: ReactNode;
|
|
112
|
-
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
|
113
|
-
}[];
|
|
114
129
|
layoutAttrs?: any;
|
|
115
130
|
disabled?: boolean;
|
|
116
131
|
attrs?: any;
|
|
@@ -138,6 +153,7 @@ export type I_Card = {
|
|
|
138
153
|
required?: boolean;
|
|
139
154
|
footerAttrs?: any;
|
|
140
155
|
justify?: boolean;
|
|
156
|
+
close?: boolean;
|
|
141
157
|
popover?: {
|
|
142
158
|
focus?: boolean | string;
|
|
143
159
|
portal?: boolean;
|
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, createRef, useContext, useRef } from "react";
|
|
3
3
|
import usePopup from 'aio-popup';
|
|
4
|
-
import { AISelect } from "aio-input";
|
|
5
4
|
import { DragAndDrop } from "aio-utils";
|
|
6
5
|
import { AddToAttrs } from "aio-class";
|
|
7
6
|
import { Mdie, $ } from "aio-deps";
|
|
@@ -12,19 +11,22 @@ export const Cards = ({ items, attrs, option, direction, className = [], style,
|
|
|
12
11
|
getContainer: () => ref.current,
|
|
13
12
|
rtl,
|
|
14
13
|
isActive: (index) => {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
14
|
+
const row = items[index];
|
|
15
|
+
const disabled = getByOption({ option, field: 'disabled', row, index });
|
|
16
|
+
const show = getByOption({ option, field: 'show', row, index, def: true });
|
|
17
17
|
return !disabled && !!show;
|
|
18
18
|
},
|
|
19
19
|
itemClassName: 'aio-card',
|
|
20
20
|
getLength: () => items.length,
|
|
21
21
|
onEnter: (e, index) => {
|
|
22
22
|
const row = items[index];
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const value = getByOption({ field: 'value', row, index, option });
|
|
24
|
+
const attrs = getByOption({ field: 'attrs', row, index, option });
|
|
25
|
+
if (attrs === null || attrs === void 0 ? void 0 : attrs.onClick) {
|
|
26
|
+
attrs.onClick(e, value);
|
|
25
27
|
}
|
|
26
28
|
else if (typeof row === 'object' && row.onClick) {
|
|
27
|
-
row.onClick(
|
|
29
|
+
row.onClick(e, value);
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
});
|
|
@@ -36,9 +38,9 @@ export const Cards = ({ items, attrs, option, direction, className = [], style,
|
|
|
36
38
|
return (_jsx("div", { className: "aio-cards-placeholder", children: placeholder }));
|
|
37
39
|
}
|
|
38
40
|
if (onSwap) {
|
|
39
|
-
return (_jsx(
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
return (_jsx(DragAndDrop, { attrs: Attrs, handle: '.aio-card-drag-icon', data: items, getId: (row, { index }) => getByOption({ field: 'value', row, option, index, def: '' }), getContent: (row, { id, index }) => {
|
|
42
|
+
return _jsx(CardsItem, { row: row, option: option, index: index, direction: direction, value: id, draggable: !!onSwap, disabled: disabled }, id);
|
|
43
|
+
}, onChange: (newOptions, fromIndex, toIndex) => onSwap(newOptions, fromIndex, toIndex) }));
|
|
42
44
|
}
|
|
43
45
|
return (_jsx("div", Object.assign({}, Attrs, { children: items.map((item, i) => {
|
|
44
46
|
const value = getByOption({ field: 'value', row: item, option, index: i, def: '' });
|
|
@@ -46,8 +48,15 @@ export const Cards = ({ items, attrs, option, direction, className = [], style,
|
|
|
46
48
|
}) })));
|
|
47
49
|
};
|
|
48
50
|
const getByOption = (p) => {
|
|
51
|
+
let value, disabled;
|
|
52
|
+
if (p.field !== "value") {
|
|
53
|
+
value = getByOption(Object.assign(Object.assign({}, p), { def: undefined, field: 'value' }));
|
|
54
|
+
if (p.field !== 'disabled') {
|
|
55
|
+
disabled = getByOption(Object.assign(Object.assign({}, p), { def: undefined, field: 'disabled' }));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
const { field, option, row, index, def } = p;
|
|
50
|
-
const res = option[field] ? option[field](
|
|
59
|
+
const res = option[field] ? option[field](row, { index, value, disabled: !!disabled, row }) : undefined;
|
|
51
60
|
if (res !== undefined) {
|
|
52
61
|
return res;
|
|
53
62
|
}
|
|
@@ -66,23 +75,7 @@ const CardsItem = ({ row, option, index, direction, draggable, disabled }) => {
|
|
|
66
75
|
if (!show) {
|
|
67
76
|
return null;
|
|
68
77
|
}
|
|
69
|
-
return (_jsx(Card, { popoverActions: popoverActions, index: index, direction: direction, draggable: draggable, showFooter: getByOption({ field: 'showFooter', row, option, index, def: true }), disabled: !!disabled ? true : getByOption({ field: 'disabled', row, option, index, def: false }),
|
|
70
|
-
if (option.onClick) {
|
|
71
|
-
option.onClick({ row, index, e });
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const attrs = getByOption({ field: 'attrs', row, option, index });
|
|
75
|
-
if (attrs === null || attrs === void 0 ? void 0 : attrs.onClick) {
|
|
76
|
-
attrs.onClick(e);
|
|
77
|
-
}
|
|
78
|
-
else if (typeof row === 'object' && row.onClick) {
|
|
79
|
-
row.onClick(e);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (getByOption({ field: 'close', row, option, index })) {
|
|
83
|
-
popoverActions.close();
|
|
84
|
-
}
|
|
85
|
-
} }, index));
|
|
78
|
+
return (_jsx(Card, { popoverActions: popoverActions, index: index, direction: direction, draggable: draggable, showFooter: getByOption({ field: 'showFooter', row, option, index, def: true }), disabled: !!disabled ? true : getByOption({ field: 'disabled', row, option, index, def: false }), close: getByOption({ field: 'close', row, option, index }), footerAttrs: getByOption({ field: 'footerAttrs', row, option, index }), className: getByOption({ field: 'className', row, option, index, def: [] }), style: getByOption({ field: 'style', row, option, index, def: {} }), before: getByOption({ field: 'before', row, option, index, def: [] }), after: getByOption({ field: 'after', row, option, index, def: [] }), text: getByOption({ field: 'text', row, option, index, def: '' }), header: getByOption({ field: 'header', row, option, index }), justify: getByOption({ field: 'justify', row, option, index }), footer: getByOption({ field: 'footer', row, option, index }), layoutAttrs: getByOption({ field: 'layoutAttrs', row, option, index }), attrs: getByOption({ field: 'attrs', row, option, index, def: {} }) }, index));
|
|
86
79
|
};
|
|
87
80
|
const Context = createContext({});
|
|
88
81
|
const Provider = ({ value, children }) => {
|
|
@@ -90,7 +83,7 @@ const Provider = ({ value, children }) => {
|
|
|
90
83
|
};
|
|
91
84
|
const useProvider = () => useContext(Context);
|
|
92
85
|
export const Card = (props) => {
|
|
93
|
-
const { text, footer, header, layoutAttrs, showFooter, show = true, placeholder, popoverActions, errorMessage, label, required, footerAttrs, showCard = true } = props;
|
|
86
|
+
const { text, footer, header, layoutAttrs, showFooter, show = true, placeholder, popoverActions, errorMessage, label, required, footerAttrs, showCard = true, popover } = props;
|
|
94
87
|
const mainRef = useRef(null);
|
|
95
88
|
const popup = usePopup();
|
|
96
89
|
const cardClass = CardClass(mainRef, popup);
|
|
@@ -103,7 +96,7 @@ export const Card = (props) => {
|
|
|
103
96
|
popoverActions.isOpen = () => !!popup.getModals().length;
|
|
104
97
|
}
|
|
105
98
|
const { beforeNodes, afterNodes } = cardClass.getSideNodes(props);
|
|
106
|
-
const card = !showCard ? null : (_jsxs(_Fragment, { children: [_jsxs("div", Object.assign({}, cardClass.getCardAttrs(props), { children: [_jsx(CardBefore, { befores: beforeNodes }), _jsx(CardText, { text: text, placeholder: placeholder, justify: props.justify }), _jsx(CardAfter, { afters: afterNodes })] })), popup.render()] }));
|
|
99
|
+
const card = !showCard ? null : (_jsxs(_Fragment, { children: [_jsxs("div", Object.assign({}, cardClass.getCardAttrs(props), { children: [_jsx(CardBefore, { befores: beforeNodes }), _jsx(CardText, { text: text, placeholder: placeholder, justify: props.justify }), _jsx(CardAfter, { afters: afterNodes })] })), !(popover === null || popover === void 0 ? void 0 : popover.portal) && popup.render(), !!(popover === null || popover === void 0 ? void 0 : popover.portal) && popup.portal()] }));
|
|
107
100
|
let result = card;
|
|
108
101
|
if (errorMessage || label || header || footer || layoutAttrs) {
|
|
109
102
|
const attrs = AddToAttrs(layoutAttrs, { className: ["aio-card-layout"] });
|
|
@@ -153,23 +146,12 @@ const CardCaret = () => {
|
|
|
153
146
|
};
|
|
154
147
|
return (_jsx("div", { className: "aio-card-caret", onClick: openByCaret ? () => cardClass.openPopover(rootProps) : undefined, children: getContnet() }));
|
|
155
148
|
};
|
|
156
|
-
const CardActions = ({ actions }) => {
|
|
157
|
-
return (_jsx(AISelect, { className: 'aio-card-actions', text: Mdie('mdiDotsHorizontal', 0.7), options: actions || [], option: {
|
|
158
|
-
text: (o) => o.text,
|
|
159
|
-
before: (o) => o.before,
|
|
160
|
-
onClick: (o) => o.onClick
|
|
161
|
-
}, popover: { portal: true }, caret: false }));
|
|
162
|
-
};
|
|
163
149
|
function CardClass(mainRef, popup) {
|
|
164
150
|
const isPopoverOpen = () => !!popup.getModals().length;
|
|
165
151
|
const _getSideNodes = (mainProps, type) => {
|
|
166
|
-
var _a;
|
|
167
152
|
const Nodes = mainProps[type] || [];
|
|
168
153
|
const nodes = Nodes.filter((o) => !!o && o !== null);
|
|
169
154
|
const hasCaret = !!mainProps.popover && mainProps.caret !== false && type === 'after';
|
|
170
|
-
if (((_a = mainProps.actions) === null || _a === void 0 ? void 0 : _a.length) && type === 'after') {
|
|
171
|
-
nodes.splice(0, 0, _jsx(CardActions, { actions: mainProps.actions }));
|
|
172
|
-
}
|
|
173
155
|
if (hasCaret) {
|
|
174
156
|
nodes.push(_jsx(CardCaret, {}));
|
|
175
157
|
}
|
|
@@ -184,28 +166,31 @@ function CardClass(mainRef, popup) {
|
|
|
184
166
|
return { beforeNodes, afterNodes };
|
|
185
167
|
};
|
|
186
168
|
const hasCardClick = (mainProps) => {
|
|
187
|
-
const { disabled,
|
|
169
|
+
const { disabled, attrs, popover, openByCaret } = mainProps;
|
|
188
170
|
if (disabled) {
|
|
189
171
|
return false;
|
|
190
172
|
}
|
|
191
173
|
if (popover && !openByCaret) {
|
|
192
174
|
return true;
|
|
193
175
|
}
|
|
194
|
-
else if (onClick) {
|
|
195
|
-
true;
|
|
176
|
+
else if (attrs === null || attrs === void 0 ? void 0 : attrs.onClick) {
|
|
177
|
+
return true;
|
|
196
178
|
}
|
|
197
179
|
return false;
|
|
198
180
|
};
|
|
199
181
|
const cardClick = (mainProps, e) => {
|
|
200
|
-
const { disabled,
|
|
182
|
+
const { disabled, attrs, popover, openByCaret, close, popoverActions } = mainProps;
|
|
201
183
|
if (disabled) {
|
|
202
184
|
return;
|
|
203
185
|
}
|
|
204
186
|
if (popover && !openByCaret) {
|
|
205
187
|
openPopover(mainProps);
|
|
206
188
|
}
|
|
207
|
-
else if (onClick) {
|
|
208
|
-
onClick(e);
|
|
189
|
+
else if (attrs === null || attrs === void 0 ? void 0 : attrs.onClick) {
|
|
190
|
+
attrs.onClick(e);
|
|
191
|
+
if (close) {
|
|
192
|
+
popoverActions === null || popoverActions === void 0 ? void 0 : popoverActions.close();
|
|
193
|
+
}
|
|
209
194
|
}
|
|
210
195
|
};
|
|
211
196
|
const getCardAttrs = (mainProps) => {
|
|
@@ -234,10 +219,7 @@ function CardClass(mainRef, popup) {
|
|
|
234
219
|
if (!popover) {
|
|
235
220
|
return;
|
|
236
221
|
}
|
|
237
|
-
let obj = Object.assign(Object.assign({}, popover), { body: popover.body || null, isPopover: true, rtl: !!mainProps.rtl, position: popover.position || 'popover', getTarget: () =>
|
|
238
|
-
const res = $(mainRef.current);
|
|
239
|
-
return res;
|
|
240
|
-
} });
|
|
222
|
+
let obj = Object.assign(Object.assign({}, popover), { body: popover.body || null, isPopover: true, rtl: !!mainProps.rtl, position: popover.position || 'popover', getTarget: () => mainRef.current });
|
|
241
223
|
return obj;
|
|
242
224
|
};
|
|
243
225
|
const openPopover = (mainProps) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-card",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "all in one card",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"keywords": [
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"url": "https://github.com/mohammadFeiz/aio-card/issues"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"aio-input": "latest",
|
|
15
14
|
"aio-deps":"latest",
|
|
16
15
|
"aio-utils":"latest",
|
|
17
16
|
"aio-popup":"latest",
|