@geoinsight/react-components 0.4.0 → 0.4.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/dist/cjs/index.js +132 -173
- package/dist/esm/index.js +131 -175
- package/geoinsight-react-components-0.4.1.tgz +0 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3,195 +3,93 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var clsx = require('clsx');
|
|
6
|
+
var tfi = require('react-icons/tfi');
|
|
6
7
|
var tb = require('react-icons/tb');
|
|
7
8
|
var io5 = require('react-icons/io5');
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// ? true
|
|
27
|
-
// : expanded === "none"
|
|
28
|
-
// ? false
|
|
29
|
-
// : child?.props.isExpanded,
|
|
30
|
-
// ]),
|
|
31
|
-
// ];
|
|
32
|
-
// }
|
|
33
|
-
// );
|
|
34
|
-
// };
|
|
35
|
-
// 1. children.map((child)=>[child.props.label,true]) // [["things", true], ["thing1", true]]
|
|
36
|
-
// 2.
|
|
37
|
-
function recursive(children, arr = {}, i = 0) {
|
|
10
|
+
function recursiveChildren(children, i = 0) {
|
|
11
|
+
return react.Children.map(children, (child, index) => {
|
|
12
|
+
if (!react.isValidElement(child)) {
|
|
13
|
+
return child;
|
|
14
|
+
}
|
|
15
|
+
if (child.props.children) {
|
|
16
|
+
return react.cloneElement(child, {
|
|
17
|
+
...child.props,
|
|
18
|
+
children: recursiveChildren(child.props.children, i++),
|
|
19
|
+
...(child?.type?.displayName === "AccordionItem" && {
|
|
20
|
+
label: `${child?.type?.displayName}-${index}-${i}`,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function recursiveToggle(children, toggleArray = {}, i = 0, props) {
|
|
38
27
|
if ((children && typeof children === "string") ||
|
|
39
|
-
typeof children[0] === "string") {
|
|
28
|
+
(Array.isArray(children) && typeof children[0] === "string")) {
|
|
40
29
|
return;
|
|
41
30
|
}
|
|
42
|
-
for (const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
for (const child of children) {
|
|
32
|
+
if (react.isValidElement(child)) {
|
|
33
|
+
if (child?.type?.displayName === "AccordionItem" && child.props.label) {
|
|
34
|
+
toggleArray[child.props.label] = {
|
|
35
|
+
isToggle: props.expanded === "all"
|
|
36
|
+
? true
|
|
37
|
+
: props.expanded === "none"
|
|
38
|
+
? false
|
|
39
|
+
: props.expanded === "custom"
|
|
40
|
+
? child?.props.isExpanded
|
|
41
|
+
: false,
|
|
42
|
+
depth: i,
|
|
43
|
+
paddingLeft: `${16 * i}px`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (typeof child.props.children !== "string" &&
|
|
47
|
+
child.props.children.find((v) => v?.type?.displayName === "AccordionItem")) {
|
|
48
|
+
recursiveToggle(Array.isArray(child.props.children)
|
|
49
|
+
? child.props.children
|
|
50
|
+
: [child.props.children], toggleArray, i + 1, props);
|
|
51
|
+
}
|
|
60
52
|
}
|
|
61
53
|
}
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
const AccordionContext = react.createContext(undefined);
|
|
65
|
-
const AccordionProvider = ({ children, expanded = "all" }) => {
|
|
66
|
-
// const a = recursive1(children);
|
|
67
|
-
// console.log(recursiveFlatmap(a));
|
|
68
|
-
const newChildren = react.Children.map(children, (child, index) => {
|
|
69
|
-
return react.cloneElement(child, {
|
|
70
|
-
// isToggle: isToggle,
|
|
71
|
-
// setIsToggle: setIsToggle,
|
|
72
|
-
...(child?.type?.displayName === "AccordionItem" && {
|
|
73
|
-
label: `${child?.type?.displayName}-${index}`,
|
|
74
|
-
}),
|
|
75
|
-
// isExpanded: isExpanded,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
const [isToggle, setIsToggle] = react.useState(recursive(newChildren));
|
|
79
|
-
return (jsxRuntime.jsx(AccordionContext.Provider, { value: { isToggle, setIsToggle }, children: jsxRuntime.jsx("div", { className: "accordion", children: newChildren }) }));
|
|
80
|
-
};
|
|
81
|
-
function Accordion({ children, expanded, menu, allExpanded, defaultValue, selectValue, }) {
|
|
82
|
-
// const { dataTheme } = useTheme();
|
|
83
|
-
// const [toggle, setToggle] = useState<{ [key: string]: boolean | undefined }>(
|
|
84
|
-
// children.map((_,index)=> ({
|
|
85
|
-
// [index]: true
|
|
86
|
-
// }))
|
|
87
|
-
// // Object.fromEntries(
|
|
88
|
-
// // Object.entries(menu).map(([key, { isExpanded = false }]) => [
|
|
89
|
-
// // key,
|
|
90
|
-
// // allExpanded !== undefined ? allExpanded : isExpanded,
|
|
91
|
-
// // ])
|
|
92
|
-
// // )
|
|
93
|
-
// );
|
|
94
|
-
// // const [selected, setSelected] = useState<string>(defaultValue);
|
|
95
|
-
// const handleToggle = (name: string) => {
|
|
96
|
-
// setToggle((prev) => {
|
|
97
|
-
// return { ...prev, [name]: !prev[name] };
|
|
98
|
-
// });
|
|
99
|
-
// };
|
|
100
|
-
return (
|
|
101
|
-
// <div className="accordion">
|
|
102
|
-
// {Children.map(children, (child, index) =>
|
|
103
|
-
// cloneElement(child, {
|
|
104
|
-
// isToggle: index === toggle[index],
|
|
105
|
-
// handleToggle: handleToggle
|
|
106
|
-
// })
|
|
107
|
-
// )}
|
|
108
|
-
// </div>
|
|
109
|
-
jsxRuntime.jsx(AccordionProvider, { expanded: expanded, children: children })
|
|
110
|
-
// <div className="accordion">
|
|
111
|
-
/* <AccordionItem>
|
|
112
|
-
<AccordionButton dataTheme={dataTheme}>
|
|
113
|
-
title
|
|
114
|
-
</AccordionButton>
|
|
115
|
-
<AccordionContent>
|
|
116
|
-
ch
|
|
117
|
-
</AccordionContent>
|
|
118
|
-
</AccordionItem> */
|
|
119
|
-
/* {Object.keys(menu).map((item) => (
|
|
120
|
-
<>
|
|
121
|
-
<Button
|
|
122
|
-
className={"accordion__title"}
|
|
123
|
-
data-theme={menu[item].dataTheme}
|
|
124
|
-
icon={toggle[item] ? <TfiAngleDown /> : <TfiAngleUp />}
|
|
125
|
-
onClick={() => handleToggle(item)}
|
|
126
|
-
>
|
|
127
|
-
{menu[item].label}
|
|
128
|
-
</Button>
|
|
129
|
-
{toggle[item] && (
|
|
130
|
-
<div className="accordion__menu">
|
|
131
|
-
{menu[item].children.map((child) => (
|
|
132
|
-
<Button
|
|
133
|
-
mode="secondary"
|
|
134
|
-
data-theme={menu[item].dataTheme}
|
|
135
|
-
className={`accordion__child ${
|
|
136
|
-
child.id === selected && ` accordion__child--active`
|
|
137
|
-
}`}
|
|
138
|
-
onClick={() => {
|
|
139
|
-
setSelected(child.id);
|
|
140
|
-
selectValue && selectValue(item, child);
|
|
141
|
-
}}
|
|
142
|
-
>
|
|
143
|
-
<>
|
|
144
|
-
{child.label}
|
|
145
|
-
{child.id === selected ? (
|
|
146
|
-
<BsCheckLg className={"accordion__check"} size={"1rem"} />
|
|
147
|
-
) : (
|
|
148
|
-
""
|
|
149
|
-
)}
|
|
150
|
-
</>
|
|
151
|
-
</Button>
|
|
152
|
-
))}
|
|
153
|
-
</div>
|
|
154
|
-
)}
|
|
155
|
-
</>
|
|
156
|
-
))}
|
|
157
|
-
// </div>*/
|
|
158
|
-
);
|
|
54
|
+
return toggleArray;
|
|
159
55
|
}
|
|
160
56
|
|
|
161
|
-
const
|
|
162
|
-
function
|
|
163
|
-
|
|
57
|
+
const AccordionContext = react.createContext(undefined);
|
|
58
|
+
function AccordionProvider({ children, expanded = "all" }) {
|
|
59
|
+
const newChildren = react.useMemo(() => recursiveChildren(children, 0), []);
|
|
60
|
+
const [toggle, setToggle] = react.useState(recursiveToggle(newChildren, {}, 0, { expanded }));
|
|
61
|
+
return (jsxRuntime.jsx(AccordionContext.Provider, { value: { toggle, setToggle }, children: jsxRuntime.jsx("div", { className: "accordion", children: newChildren }) }));
|
|
164
62
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
63
|
+
function useAccordion() {
|
|
64
|
+
const context = react.useContext(AccordionContext);
|
|
65
|
+
if (context === undefined) {
|
|
66
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
67
|
+
}
|
|
68
|
+
return context;
|
|
168
69
|
}
|
|
169
70
|
|
|
170
|
-
function
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const handleClickToggle = () => {
|
|
174
|
-
if (ref && ref.current) {
|
|
175
|
-
if (isShow) {
|
|
176
|
-
ref.current.style.height = hideHeight;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
ref.current.style.height = showHeight; //(48 + ref.current.scrollHeight) + 'px';
|
|
180
|
-
}
|
|
181
|
-
setIsShow((prev) => !prev);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
return (jsxRuntime.jsxs("div", { className: clsx("textarea", className), style: style, children: [jsxRuntime.jsx("textarea", { ref: ref, className: clsx("textarea__input", textareaClassName), style: {
|
|
185
|
-
height: hasToggleButton ? hideHeight : showHeight,
|
|
186
|
-
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsxRuntime.jsx("button", { className: clsx("textarea__button", isShow && "textarea__button--show"), onClick: handleClickToggle, disabled: disabled, children: jsxRuntime.jsx(tb.TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
71
|
+
function Accordion({ children, expanded = "all", defaultValue, selectValue, }) {
|
|
72
|
+
// const { dataTheme } = useTheme();
|
|
73
|
+
return (jsxRuntime.jsx(AccordionProvider, { expanded: expanded, children: children }));
|
|
187
74
|
}
|
|
188
75
|
|
|
189
|
-
function
|
|
190
|
-
|
|
191
|
-
|
|
76
|
+
const AccordionItem = react.forwardRef(function AccordionItem({ children, label, isExpanded = false }, ref) {
|
|
77
|
+
const { toggle, setToggle } = useAccordion();
|
|
78
|
+
return (jsxRuntime.jsx("div", { className: "accordion-item", style: {
|
|
79
|
+
paddingLeft: toggle && label && toggle[label].paddingLeft,
|
|
80
|
+
}, children: react.Children.map(children, (child) => react.cloneElement(child, {
|
|
81
|
+
toggle: toggle,
|
|
82
|
+
setToggle: setToggle,
|
|
83
|
+
...(child?.type?.displayName !== "AccordionItem" && {
|
|
84
|
+
label: label,
|
|
85
|
+
}),
|
|
86
|
+
isExpanded: isExpanded,
|
|
87
|
+
})) }));
|
|
88
|
+
});
|
|
192
89
|
|
|
193
|
-
|
|
194
|
-
|
|
90
|
+
const Anchor = ({ Custom, children, ...rest }) => Custom ? jsxRuntime.jsx(Custom, { ...rest, children: children }) : jsxRuntime.jsx("a", { ...rest, children: children });
|
|
91
|
+
function Button({ children = "Click me", className = "", icon = undefined, isNewWindow = false, mode = "primary", size = "medium", as = "button", CustomAnchor, ...rest }) {
|
|
92
|
+
return as === "link" ? (jsxRuntime.jsxs(Anchor, { Custom: CustomAnchor, ...(isNewWindow && { target: "_blank" }), className: clsx(`button ${className}`, mode === "secondary" ? `button button__${mode}` : "button__link", `button__${size}`), ...rest, children: [children, icon] })) : (jsxRuntime.jsxs("button", { className: clsx("button", `button__${mode}`, `button__${size}`, className), ...rest, children: [children, icon] }));
|
|
195
93
|
}
|
|
196
94
|
|
|
197
95
|
const ThemeContext = react.createContext(undefined);
|
|
@@ -242,6 +140,64 @@ function useTheme({ dataTheme = undefined, paletteTheme = "water", } = {}) {
|
|
|
242
140
|
return context;
|
|
243
141
|
}
|
|
244
142
|
|
|
143
|
+
const AccordionButton = react.forwardRef(function AccordionButton({ children, is = "link", label, toggle, setToggle, ...rest }, ref) {
|
|
144
|
+
const { dataTheme } = useTheme();
|
|
145
|
+
const handleToggle = () => {
|
|
146
|
+
setToggle((prev) => {
|
|
147
|
+
if (label) {
|
|
148
|
+
return {
|
|
149
|
+
...prev,
|
|
150
|
+
[label]: {
|
|
151
|
+
...(prev && label && prev[label]),
|
|
152
|
+
isToggle: prev && !prev[label].isToggle,
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return prev;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
return (jsxRuntime.jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}`, `accordion-button__${is}--${dataTheme}`), ...(is !== "link" && {
|
|
162
|
+
icon: label && toggle && toggle[label].isToggle ? (jsxRuntime.jsx(tfi.TfiAngleDown, {})) : (jsxRuntime.jsx(tfi.TfiAngleUp, {})),
|
|
163
|
+
}), ...(is !== "link" && { onClick: handleToggle }), ...rest, children: children }));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const AccordionContent = react.forwardRef(function AccordionContent({ children, label, toggle, }, ref) {
|
|
167
|
+
return label && toggle && toggle[label].isToggle && jsxRuntime.jsx("div", { className: "accordion-content", children: children });
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
function Input({ className = "", classNameGroup = "", errorMessage = "", inputRef, styleGroup, ...rest }) {
|
|
171
|
+
return (jsxRuntime.jsxs("div", { className: `input-group ${classNameGroup}`, style: styleGroup, children: [jsxRuntime.jsx("input", { ref: inputRef, className: `input ${errorMessage ? "input--error" : ""} ${className}`, ...rest }), errorMessage && jsxRuntime.jsx("span", { className: "error", children: errorMessage })] }));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function TextArea({ className = "", disabled = true, hasToggleButton = true, hideHeight = "5rem", placeholder = "", showHeight = "10rem", style = {}, textareaClassName = "", ...rest }) {
|
|
175
|
+
const ref = react.useRef();
|
|
176
|
+
const [isShow, setIsShow] = react.useState(false);
|
|
177
|
+
const handleClickToggle = () => {
|
|
178
|
+
if (ref && ref.current) {
|
|
179
|
+
if (isShow) {
|
|
180
|
+
ref.current.style.height = hideHeight;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
ref.current.style.height = showHeight; //(48 + ref.current.scrollHeight) + 'px';
|
|
184
|
+
}
|
|
185
|
+
setIsShow((prev) => !prev);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
return (jsxRuntime.jsxs("div", { className: clsx("textarea", className), style: style, children: [jsxRuntime.jsx("textarea", { ref: ref, className: clsx("textarea__input", textareaClassName), style: {
|
|
189
|
+
height: hasToggleButton ? hideHeight : showHeight,
|
|
190
|
+
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsxRuntime.jsx("button", { className: clsx("textarea__button", isShow && "textarea__button--show"), onClick: handleClickToggle, disabled: disabled, children: jsxRuntime.jsx(tb.TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function Modal({ modalref, children, title, subtitle, footer, hasCloseButton = true, handleClose, }) {
|
|
194
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "modal-overlay" }), jsxRuntime.jsxs("div", { ref: modalref, className: "modal", children: [hasCloseButton && (jsxRuntime.jsx(Button, { mode: "secondary", className: "modal__close", size: "small", onClick: handleClose, children: jsxRuntime.jsx(io5.IoClose, {}) })), jsxRuntime.jsxs("div", { className: "modal__content", children: [title && (jsxRuntime.jsxs("div", { className: "modal__header", children: [jsxRuntime.jsx("h3", { children: title }), jsxRuntime.jsx("h6", { children: subtitle })] })), jsxRuntime.jsx("div", { className: "modal__children", children: children }), footer && jsxRuntime.jsx("div", { className: "modal__footer", children: footer })] })] })] }));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function Loading({ img, children }) {
|
|
198
|
+
return (jsxRuntime.jsxs("div", { className: "loading", children: [jsxRuntime.jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
199
|
+
}
|
|
200
|
+
|
|
245
201
|
const LoadingContext = react.createContext(undefined);
|
|
246
202
|
function loadingReducer(state, action) {
|
|
247
203
|
switch (action.type) {
|
|
@@ -364,6 +320,9 @@ function useModal({} = {}) {
|
|
|
364
320
|
}
|
|
365
321
|
|
|
366
322
|
exports.Accordion = Accordion;
|
|
323
|
+
exports.AccordionButton = AccordionButton;
|
|
324
|
+
exports.AccordionContent = AccordionContent;
|
|
325
|
+
exports.AccordionItem = AccordionItem;
|
|
367
326
|
exports.Button = Button;
|
|
368
327
|
exports.Input = Input;
|
|
369
328
|
exports.Loading = Loading;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,195 +1,93 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { Children, isValidElement, cloneElement, createContext, useContext, useMemo, useState, forwardRef, useEffect, useRef, useReducer } from 'react';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
+
import { TfiAngleDown, TfiAngleUp } from 'react-icons/tfi';
|
|
4
5
|
import { TbArrowsDiagonal2 } from 'react-icons/tb';
|
|
5
6
|
import { IoClose } from 'react-icons/io5';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// ? true
|
|
25
|
-
// : expanded === "none"
|
|
26
|
-
// ? false
|
|
27
|
-
// : child?.props.isExpanded,
|
|
28
|
-
// ]),
|
|
29
|
-
// ];
|
|
30
|
-
// }
|
|
31
|
-
// );
|
|
32
|
-
// };
|
|
33
|
-
// 1. children.map((child)=>[child.props.label,true]) // [["things", true], ["thing1", true]]
|
|
34
|
-
// 2.
|
|
35
|
-
function recursive(children, arr = {}, i = 0) {
|
|
8
|
+
function recursiveChildren(children, i = 0) {
|
|
9
|
+
return Children.map(children, (child, index) => {
|
|
10
|
+
if (!isValidElement(child)) {
|
|
11
|
+
return child;
|
|
12
|
+
}
|
|
13
|
+
if (child.props.children) {
|
|
14
|
+
return cloneElement(child, {
|
|
15
|
+
...child.props,
|
|
16
|
+
children: recursiveChildren(child.props.children, i++),
|
|
17
|
+
...(child?.type?.displayName === "AccordionItem" && {
|
|
18
|
+
label: `${child?.type?.displayName}-${index}-${i}`,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function recursiveToggle(children, toggleArray = {}, i = 0, props) {
|
|
36
25
|
if ((children && typeof children === "string") ||
|
|
37
|
-
typeof children[0] === "string") {
|
|
26
|
+
(Array.isArray(children) && typeof children[0] === "string")) {
|
|
38
27
|
return;
|
|
39
28
|
}
|
|
40
|
-
for (const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
29
|
+
for (const child of children) {
|
|
30
|
+
if (isValidElement(child)) {
|
|
31
|
+
if (child?.type?.displayName === "AccordionItem" && child.props.label) {
|
|
32
|
+
toggleArray[child.props.label] = {
|
|
33
|
+
isToggle: props.expanded === "all"
|
|
34
|
+
? true
|
|
35
|
+
: props.expanded === "none"
|
|
36
|
+
? false
|
|
37
|
+
: props.expanded === "custom"
|
|
38
|
+
? child?.props.isExpanded
|
|
39
|
+
: false,
|
|
40
|
+
depth: i,
|
|
41
|
+
paddingLeft: `${16 * i}px`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (typeof child.props.children !== "string" &&
|
|
45
|
+
child.props.children.find((v) => v?.type?.displayName === "AccordionItem")) {
|
|
46
|
+
recursiveToggle(Array.isArray(child.props.children)
|
|
47
|
+
? child.props.children
|
|
48
|
+
: [child.props.children], toggleArray, i + 1, props);
|
|
49
|
+
}
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
const AccordionContext = createContext(undefined);
|
|
63
|
-
const AccordionProvider = ({ children, expanded = "all" }) => {
|
|
64
|
-
// const a = recursive1(children);
|
|
65
|
-
// console.log(recursiveFlatmap(a));
|
|
66
|
-
const newChildren = Children.map(children, (child, index) => {
|
|
67
|
-
return cloneElement(child, {
|
|
68
|
-
// isToggle: isToggle,
|
|
69
|
-
// setIsToggle: setIsToggle,
|
|
70
|
-
...(child?.type?.displayName === "AccordionItem" && {
|
|
71
|
-
label: `${child?.type?.displayName}-${index}`,
|
|
72
|
-
}),
|
|
73
|
-
// isExpanded: isExpanded,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
const [isToggle, setIsToggle] = useState(recursive(newChildren));
|
|
77
|
-
return (jsx(AccordionContext.Provider, { value: { isToggle, setIsToggle }, children: jsx("div", { className: "accordion", children: newChildren }) }));
|
|
78
|
-
};
|
|
79
|
-
function Accordion({ children, expanded, menu, allExpanded, defaultValue, selectValue, }) {
|
|
80
|
-
// const { dataTheme } = useTheme();
|
|
81
|
-
// const [toggle, setToggle] = useState<{ [key: string]: boolean | undefined }>(
|
|
82
|
-
// children.map((_,index)=> ({
|
|
83
|
-
// [index]: true
|
|
84
|
-
// }))
|
|
85
|
-
// // Object.fromEntries(
|
|
86
|
-
// // Object.entries(menu).map(([key, { isExpanded = false }]) => [
|
|
87
|
-
// // key,
|
|
88
|
-
// // allExpanded !== undefined ? allExpanded : isExpanded,
|
|
89
|
-
// // ])
|
|
90
|
-
// // )
|
|
91
|
-
// );
|
|
92
|
-
// // const [selected, setSelected] = useState<string>(defaultValue);
|
|
93
|
-
// const handleToggle = (name: string) => {
|
|
94
|
-
// setToggle((prev) => {
|
|
95
|
-
// return { ...prev, [name]: !prev[name] };
|
|
96
|
-
// });
|
|
97
|
-
// };
|
|
98
|
-
return (
|
|
99
|
-
// <div className="accordion">
|
|
100
|
-
// {Children.map(children, (child, index) =>
|
|
101
|
-
// cloneElement(child, {
|
|
102
|
-
// isToggle: index === toggle[index],
|
|
103
|
-
// handleToggle: handleToggle
|
|
104
|
-
// })
|
|
105
|
-
// )}
|
|
106
|
-
// </div>
|
|
107
|
-
jsx(AccordionProvider, { expanded: expanded, children: children })
|
|
108
|
-
// <div className="accordion">
|
|
109
|
-
/* <AccordionItem>
|
|
110
|
-
<AccordionButton dataTheme={dataTheme}>
|
|
111
|
-
title
|
|
112
|
-
</AccordionButton>
|
|
113
|
-
<AccordionContent>
|
|
114
|
-
ch
|
|
115
|
-
</AccordionContent>
|
|
116
|
-
</AccordionItem> */
|
|
117
|
-
/* {Object.keys(menu).map((item) => (
|
|
118
|
-
<>
|
|
119
|
-
<Button
|
|
120
|
-
className={"accordion__title"}
|
|
121
|
-
data-theme={menu[item].dataTheme}
|
|
122
|
-
icon={toggle[item] ? <TfiAngleDown /> : <TfiAngleUp />}
|
|
123
|
-
onClick={() => handleToggle(item)}
|
|
124
|
-
>
|
|
125
|
-
{menu[item].label}
|
|
126
|
-
</Button>
|
|
127
|
-
{toggle[item] && (
|
|
128
|
-
<div className="accordion__menu">
|
|
129
|
-
{menu[item].children.map((child) => (
|
|
130
|
-
<Button
|
|
131
|
-
mode="secondary"
|
|
132
|
-
data-theme={menu[item].dataTheme}
|
|
133
|
-
className={`accordion__child ${
|
|
134
|
-
child.id === selected && ` accordion__child--active`
|
|
135
|
-
}`}
|
|
136
|
-
onClick={() => {
|
|
137
|
-
setSelected(child.id);
|
|
138
|
-
selectValue && selectValue(item, child);
|
|
139
|
-
}}
|
|
140
|
-
>
|
|
141
|
-
<>
|
|
142
|
-
{child.label}
|
|
143
|
-
{child.id === selected ? (
|
|
144
|
-
<BsCheckLg className={"accordion__check"} size={"1rem"} />
|
|
145
|
-
) : (
|
|
146
|
-
""
|
|
147
|
-
)}
|
|
148
|
-
</>
|
|
149
|
-
</Button>
|
|
150
|
-
))}
|
|
151
|
-
</div>
|
|
152
|
-
)}
|
|
153
|
-
</>
|
|
154
|
-
))}
|
|
155
|
-
// </div>*/
|
|
156
|
-
);
|
|
52
|
+
return toggleArray;
|
|
157
53
|
}
|
|
158
54
|
|
|
159
|
-
const
|
|
160
|
-
function
|
|
161
|
-
|
|
55
|
+
const AccordionContext = createContext(undefined);
|
|
56
|
+
function AccordionProvider({ children, expanded = "all" }) {
|
|
57
|
+
const newChildren = useMemo(() => recursiveChildren(children, 0), []);
|
|
58
|
+
const [toggle, setToggle] = useState(recursiveToggle(newChildren, {}, 0, { expanded }));
|
|
59
|
+
return (jsx(AccordionContext.Provider, { value: { toggle, setToggle }, children: jsx("div", { className: "accordion", children: newChildren }) }));
|
|
162
60
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
61
|
+
function useAccordion() {
|
|
62
|
+
const context = useContext(AccordionContext);
|
|
63
|
+
if (context === undefined) {
|
|
64
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
65
|
+
}
|
|
66
|
+
return context;
|
|
166
67
|
}
|
|
167
68
|
|
|
168
|
-
function
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
const handleClickToggle = () => {
|
|
172
|
-
if (ref && ref.current) {
|
|
173
|
-
if (isShow) {
|
|
174
|
-
ref.current.style.height = hideHeight;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
ref.current.style.height = showHeight; //(48 + ref.current.scrollHeight) + 'px';
|
|
178
|
-
}
|
|
179
|
-
setIsShow((prev) => !prev);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
return (jsxs("div", { className: clsx("textarea", className), style: style, children: [jsx("textarea", { ref: ref, className: clsx("textarea__input", textareaClassName), style: {
|
|
183
|
-
height: hasToggleButton ? hideHeight : showHeight,
|
|
184
|
-
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsx("button", { className: clsx("textarea__button", isShow && "textarea__button--show"), onClick: handleClickToggle, disabled: disabled, children: jsx(TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
69
|
+
function Accordion({ children, expanded = "all", defaultValue, selectValue, }) {
|
|
70
|
+
// const { dataTheme } = useTheme();
|
|
71
|
+
return (jsx(AccordionProvider, { expanded: expanded, children: children }));
|
|
185
72
|
}
|
|
186
73
|
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
74
|
+
const AccordionItem = forwardRef(function AccordionItem({ children, label, isExpanded = false }, ref) {
|
|
75
|
+
const { toggle, setToggle } = useAccordion();
|
|
76
|
+
return (jsx("div", { className: "accordion-item", style: {
|
|
77
|
+
paddingLeft: toggle && label && toggle[label].paddingLeft,
|
|
78
|
+
}, children: Children.map(children, (child) => cloneElement(child, {
|
|
79
|
+
toggle: toggle,
|
|
80
|
+
setToggle: setToggle,
|
|
81
|
+
...(child?.type?.displayName !== "AccordionItem" && {
|
|
82
|
+
label: label,
|
|
83
|
+
}),
|
|
84
|
+
isExpanded: isExpanded,
|
|
85
|
+
})) }));
|
|
86
|
+
});
|
|
190
87
|
|
|
191
|
-
|
|
192
|
-
|
|
88
|
+
const Anchor = ({ Custom, children, ...rest }) => Custom ? jsx(Custom, { ...rest, children: children }) : jsx("a", { ...rest, children: children });
|
|
89
|
+
function Button({ children = "Click me", className = "", icon = undefined, isNewWindow = false, mode = "primary", size = "medium", as = "button", CustomAnchor, ...rest }) {
|
|
90
|
+
return as === "link" ? (jsxs(Anchor, { Custom: CustomAnchor, ...(isNewWindow && { target: "_blank" }), className: clsx(`button ${className}`, mode === "secondary" ? `button button__${mode}` : "button__link", `button__${size}`), ...rest, children: [children, icon] })) : (jsxs("button", { className: clsx("button", `button__${mode}`, `button__${size}`, className), ...rest, children: [children, icon] }));
|
|
193
91
|
}
|
|
194
92
|
|
|
195
93
|
const ThemeContext = createContext(undefined);
|
|
@@ -240,6 +138,64 @@ function useTheme({ dataTheme = undefined, paletteTheme = "water", } = {}) {
|
|
|
240
138
|
return context;
|
|
241
139
|
}
|
|
242
140
|
|
|
141
|
+
const AccordionButton = forwardRef(function AccordionButton({ children, is = "link", label, toggle, setToggle, ...rest }, ref) {
|
|
142
|
+
const { dataTheme } = useTheme();
|
|
143
|
+
const handleToggle = () => {
|
|
144
|
+
setToggle((prev) => {
|
|
145
|
+
if (label) {
|
|
146
|
+
return {
|
|
147
|
+
...prev,
|
|
148
|
+
[label]: {
|
|
149
|
+
...(prev && label && prev[label]),
|
|
150
|
+
isToggle: prev && !prev[label].isToggle,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return prev;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
return (jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}`, `accordion-button__${is}--${dataTheme}`), ...(is !== "link" && {
|
|
160
|
+
icon: label && toggle && toggle[label].isToggle ? (jsx(TfiAngleDown, {})) : (jsx(TfiAngleUp, {})),
|
|
161
|
+
}), ...(is !== "link" && { onClick: handleToggle }), ...rest, children: children }));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const AccordionContent = forwardRef(function AccordionContent({ children, label, toggle, }, ref) {
|
|
165
|
+
return label && toggle && toggle[label].isToggle && jsx("div", { className: "accordion-content", children: children });
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
function Input({ className = "", classNameGroup = "", errorMessage = "", inputRef, styleGroup, ...rest }) {
|
|
169
|
+
return (jsxs("div", { className: `input-group ${classNameGroup}`, style: styleGroup, children: [jsx("input", { ref: inputRef, className: `input ${errorMessage ? "input--error" : ""} ${className}`, ...rest }), errorMessage && jsx("span", { className: "error", children: errorMessage })] }));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function TextArea({ className = "", disabled = true, hasToggleButton = true, hideHeight = "5rem", placeholder = "", showHeight = "10rem", style = {}, textareaClassName = "", ...rest }) {
|
|
173
|
+
const ref = useRef();
|
|
174
|
+
const [isShow, setIsShow] = useState(false);
|
|
175
|
+
const handleClickToggle = () => {
|
|
176
|
+
if (ref && ref.current) {
|
|
177
|
+
if (isShow) {
|
|
178
|
+
ref.current.style.height = hideHeight;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
ref.current.style.height = showHeight; //(48 + ref.current.scrollHeight) + 'px';
|
|
182
|
+
}
|
|
183
|
+
setIsShow((prev) => !prev);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return (jsxs("div", { className: clsx("textarea", className), style: style, children: [jsx("textarea", { ref: ref, className: clsx("textarea__input", textareaClassName), style: {
|
|
187
|
+
height: hasToggleButton ? hideHeight : showHeight,
|
|
188
|
+
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsx("button", { className: clsx("textarea__button", isShow && "textarea__button--show"), onClick: handleClickToggle, disabled: disabled, children: jsx(TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function Modal({ modalref, children, title, subtitle, footer, hasCloseButton = true, handleClose, }) {
|
|
192
|
+
return (jsxs(Fragment, { children: [jsx("div", { className: "modal-overlay" }), jsxs("div", { ref: modalref, className: "modal", children: [hasCloseButton && (jsx(Button, { mode: "secondary", className: "modal__close", size: "small", onClick: handleClose, children: jsx(IoClose, {}) })), jsxs("div", { className: "modal__content", children: [title && (jsxs("div", { className: "modal__header", children: [jsx("h3", { children: title }), jsx("h6", { children: subtitle })] })), jsx("div", { className: "modal__children", children: children }), footer && jsx("div", { className: "modal__footer", children: footer })] })] })] }));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function Loading({ img, children }) {
|
|
196
|
+
return (jsxs("div", { className: "loading", children: [jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
197
|
+
}
|
|
198
|
+
|
|
243
199
|
const LoadingContext = createContext(undefined);
|
|
244
200
|
function loadingReducer(state, action) {
|
|
245
201
|
switch (action.type) {
|
|
@@ -361,4 +317,4 @@ function useModal({} = {}) {
|
|
|
361
317
|
return context;
|
|
362
318
|
}
|
|
363
319
|
|
|
364
|
-
export { Accordion, Button, Input, Loading, LoadingContext, LoadingProvider, Modal, ModalContext, ModalProvider, TextArea, ThemeContext, ThemeProvider, useLoading, useModal, useTheme };
|
|
320
|
+
export { Accordion, AccordionButton, AccordionContent, AccordionItem, Button, Input, Loading, LoadingContext, LoadingProvider, Modal, ModalContext, ModalProvider, TextArea, ThemeContext, ThemeProvider, useLoading, useModal, useTheme };
|
|
Binary file
|