@geoinsight/react-components 0.4.2 → 0.4.3
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 +75 -60
- package/dist/esm/index.js +76 -61
- package/package.json +1 -1
- package/geoinsight-react-components-0.4.1.tgz +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -56,8 +56,11 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
|
|
|
56
56
|
|
|
57
57
|
const AccordionContext = react.createContext(undefined);
|
|
58
58
|
function AccordionProvider({ children, expanded = "all" }) {
|
|
59
|
-
const newChildren =
|
|
60
|
-
const [toggle,
|
|
59
|
+
const newChildren = recursiveChildren(children, 0);
|
|
60
|
+
const [toggle, _setToggle] = react.useState(recursiveToggle(newChildren, {}, 0, { expanded }));
|
|
61
|
+
const setToggle = (prev) => {
|
|
62
|
+
_setToggle(prev);
|
|
63
|
+
};
|
|
61
64
|
return (jsxRuntime.jsx(AccordionContext.Provider, { value: { toggle, setToggle }, children: jsxRuntime.jsx("div", { className: "accordion", children: newChildren }) }));
|
|
62
65
|
}
|
|
63
66
|
function useAccordion() {
|
|
@@ -68,12 +71,15 @@ function useAccordion() {
|
|
|
68
71
|
return context;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
function Accordion({ children, expanded = "all",
|
|
74
|
+
function Accordion({ children, expanded = "all",
|
|
75
|
+
// defaultValue,
|
|
76
|
+
// selectValue,
|
|
77
|
+
}) {
|
|
72
78
|
// const { dataTheme } = useTheme();
|
|
73
79
|
return (jsxRuntime.jsx(AccordionProvider, { expanded: expanded, children: children }));
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
function AccordionItem({ children, label, isExpanded = false, }) {
|
|
77
83
|
const { toggle, setToggle } = useAccordion();
|
|
78
84
|
return (jsxRuntime.jsx("div", { className: "accordion-item", style: {
|
|
79
85
|
paddingLeft: toggle && label && toggle[label].paddingLeft,
|
|
@@ -85,63 +91,20 @@ const AccordionItem = react.forwardRef(function AccordionItem({ children, label,
|
|
|
85
91
|
}),
|
|
86
92
|
isExpanded: isExpanded,
|
|
87
93
|
})) }));
|
|
88
|
-
}
|
|
94
|
+
}
|
|
89
95
|
|
|
90
96
|
const Anchor = ({ Custom, children, ...rest }) => Custom ? jsxRuntime.jsx(Custom, { ...rest, children: children }) : jsxRuntime.jsx("a", { ...rest, children: children });
|
|
91
97
|
function Button({ children = "Click me", className = "", icon = undefined, isNewWindow = false, mode = "primary", size = "medium", as = "button", CustomAnchor, ...rest }) {
|
|
92
98
|
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] }));
|
|
93
99
|
}
|
|
94
100
|
|
|
95
|
-
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
document.documentElement.setAttribute("data-theme", localStorage.getItem("data-theme"));
|
|
103
|
-
setDataTheme(localStorage.getItem("data-theme"));
|
|
104
|
-
}
|
|
105
|
-
else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
106
|
-
document.documentElement.setAttribute("data-theme", "dark");
|
|
107
|
-
setDataTheme("dark");
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}, []);
|
|
111
|
-
const switchDataTheme = (mode) => {
|
|
112
|
-
document.documentElement.setAttribute("data-theme", mode);
|
|
113
|
-
setDataTheme(mode);
|
|
114
|
-
localStorage.setItem("data-theme", mode);
|
|
115
|
-
};
|
|
116
|
-
const switchPaletteTheme = (mode) => {
|
|
117
|
-
document.documentElement.setAttribute("palette-theme", mode);
|
|
118
|
-
setPaletteTheme(mode);
|
|
119
|
-
localStorage.setItem("palette-theme", mode);
|
|
120
|
-
};
|
|
121
|
-
return (jsxRuntime.jsx(ThemeContext.Provider, { value: { dataTheme, switchDataTheme, paletteTheme, switchPaletteTheme }, children: children }));
|
|
122
|
-
}
|
|
123
|
-
function useTheme({ dataTheme = undefined, paletteTheme = "water", } = {}) {
|
|
124
|
-
const context = react.useContext(ThemeContext);
|
|
125
|
-
// only happens if there is an initial mode value.
|
|
126
|
-
react.useEffect(() => {
|
|
127
|
-
if (dataTheme && !localStorage.getItem("data-theme")) {
|
|
128
|
-
context?.switchDataTheme(dataTheme);
|
|
129
|
-
}
|
|
130
|
-
else if (!dataTheme && localStorage.getItem("data-theme")) {
|
|
131
|
-
localStorage.removeItem("data-theme");
|
|
132
|
-
}
|
|
133
|
-
}, []);
|
|
134
|
-
react.useEffect(() => {
|
|
135
|
-
context?.switchPaletteTheme(paletteTheme);
|
|
136
|
-
}, []);
|
|
137
|
-
if (context === undefined) {
|
|
138
|
-
throw new Error("useTheme must be used within a ThemeProvider");
|
|
139
|
-
}
|
|
140
|
-
return context;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const AccordionButton = react.forwardRef(function AccordionButton({ children, is = "link", label, toggle, setToggle, ...rest }, ref) {
|
|
144
|
-
const { dataTheme } = useTheme();
|
|
101
|
+
// import { useTheme } from "../../context/themeContext";
|
|
102
|
+
function AccordionButton({ children, is = "link", label,
|
|
103
|
+
// toggle,
|
|
104
|
+
// setToggle = (prev: any) => void,
|
|
105
|
+
...rest }) {
|
|
106
|
+
// const { dataTheme } = useTheme();
|
|
107
|
+
const { toggle, setToggle } = useAccordion();
|
|
145
108
|
const handleToggle = () => {
|
|
146
109
|
setToggle((prev) => {
|
|
147
110
|
if (label) {
|
|
@@ -158,14 +121,18 @@ const AccordionButton = react.forwardRef(function AccordionButton({ children, is
|
|
|
158
121
|
}
|
|
159
122
|
});
|
|
160
123
|
};
|
|
161
|
-
return (jsxRuntime.jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}
|
|
124
|
+
return (jsxRuntime.jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}`
|
|
125
|
+
// `accordion-button__${is}--${dataTheme}`
|
|
126
|
+
), ...(is !== "link" && {
|
|
162
127
|
icon: label && toggle && toggle[label].isToggle ? (jsxRuntime.jsx(tfi.TfiAngleDown, {})) : (jsxRuntime.jsx(tfi.TfiAngleUp, {})),
|
|
163
128
|
}), ...(is !== "link" && { onClick: handleToggle }), ...rest, children: children }));
|
|
164
|
-
}
|
|
129
|
+
}
|
|
165
130
|
|
|
166
|
-
const AccordionContent =
|
|
167
|
-
return label &&
|
|
168
|
-
|
|
131
|
+
const AccordionContent = function AccordionContent({ children, label, toggle, }) {
|
|
132
|
+
return (label &&
|
|
133
|
+
toggle &&
|
|
134
|
+
toggle[label].isToggle && (jsxRuntime.jsx("div", { className: "accordion-content", children: children })));
|
|
135
|
+
};
|
|
169
136
|
|
|
170
137
|
function Input({ className = "", classNameGroup = "", errorMessage = "", inputRef, styleGroup, ...rest }) {
|
|
171
138
|
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 })] }));
|
|
@@ -198,6 +165,54 @@ function Loading({ img, children }) {
|
|
|
198
165
|
return (jsxRuntime.jsxs("div", { className: "loading", children: [jsxRuntime.jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
199
166
|
}
|
|
200
167
|
|
|
168
|
+
const ThemeContext = react.createContext(undefined);
|
|
169
|
+
function ThemeProvider({ children }) {
|
|
170
|
+
const [dataTheme, setDataTheme] = react.useState();
|
|
171
|
+
const [paletteTheme, setPaletteTheme] = react.useState();
|
|
172
|
+
react.useEffect(() => {
|
|
173
|
+
if (window.matchMedia) {
|
|
174
|
+
if (localStorage.getItem("data-theme")) {
|
|
175
|
+
document.documentElement.setAttribute("data-theme", localStorage.getItem("data-theme"));
|
|
176
|
+
setDataTheme(localStorage.getItem("data-theme"));
|
|
177
|
+
}
|
|
178
|
+
else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
179
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
180
|
+
setDataTheme("dark");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}, []);
|
|
184
|
+
const switchDataTheme = (mode) => {
|
|
185
|
+
document.documentElement.setAttribute("data-theme", mode);
|
|
186
|
+
setDataTheme(mode);
|
|
187
|
+
localStorage.setItem("data-theme", mode);
|
|
188
|
+
};
|
|
189
|
+
const switchPaletteTheme = (mode) => {
|
|
190
|
+
document.documentElement.setAttribute("palette-theme", mode);
|
|
191
|
+
setPaletteTheme(mode);
|
|
192
|
+
localStorage.setItem("palette-theme", mode);
|
|
193
|
+
};
|
|
194
|
+
return (jsxRuntime.jsx(ThemeContext.Provider, { value: { dataTheme, switchDataTheme, paletteTheme, switchPaletteTheme }, children: children }));
|
|
195
|
+
}
|
|
196
|
+
function useTheme({ dataTheme = undefined, paletteTheme = "water", } = {}) {
|
|
197
|
+
const context = react.useContext(ThemeContext);
|
|
198
|
+
// only happens if there is an initial mode value.
|
|
199
|
+
react.useEffect(() => {
|
|
200
|
+
if (dataTheme && !localStorage.getItem("data-theme")) {
|
|
201
|
+
context?.switchDataTheme(dataTheme);
|
|
202
|
+
}
|
|
203
|
+
else if (!dataTheme && localStorage.getItem("data-theme")) {
|
|
204
|
+
localStorage.removeItem("data-theme");
|
|
205
|
+
}
|
|
206
|
+
}, []);
|
|
207
|
+
react.useEffect(() => {
|
|
208
|
+
context?.switchPaletteTheme(paletteTheme);
|
|
209
|
+
}, []);
|
|
210
|
+
if (context === undefined) {
|
|
211
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
212
|
+
}
|
|
213
|
+
return context;
|
|
214
|
+
}
|
|
215
|
+
|
|
201
216
|
const LoadingContext = react.createContext(undefined);
|
|
202
217
|
function loadingReducer(state, action) {
|
|
203
218
|
switch (action.type) {
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Children, isValidElement, cloneElement, createContext,
|
|
2
|
+
import { Children, isValidElement, cloneElement, createContext, useState, useContext, useRef, useEffect, useReducer } from 'react';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { TfiAngleDown, TfiAngleUp } from 'react-icons/tfi';
|
|
5
5
|
import { TbArrowsDiagonal2 } from 'react-icons/tb';
|
|
@@ -54,8 +54,11 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
|
|
|
54
54
|
|
|
55
55
|
const AccordionContext = createContext(undefined);
|
|
56
56
|
function AccordionProvider({ children, expanded = "all" }) {
|
|
57
|
-
const newChildren =
|
|
58
|
-
const [toggle,
|
|
57
|
+
const newChildren = recursiveChildren(children, 0);
|
|
58
|
+
const [toggle, _setToggle] = useState(recursiveToggle(newChildren, {}, 0, { expanded }));
|
|
59
|
+
const setToggle = (prev) => {
|
|
60
|
+
_setToggle(prev);
|
|
61
|
+
};
|
|
59
62
|
return (jsx(AccordionContext.Provider, { value: { toggle, setToggle }, children: jsx("div", { className: "accordion", children: newChildren }) }));
|
|
60
63
|
}
|
|
61
64
|
function useAccordion() {
|
|
@@ -66,12 +69,15 @@ function useAccordion() {
|
|
|
66
69
|
return context;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
function Accordion({ children, expanded = "all",
|
|
72
|
+
function Accordion({ children, expanded = "all",
|
|
73
|
+
// defaultValue,
|
|
74
|
+
// selectValue,
|
|
75
|
+
}) {
|
|
70
76
|
// const { dataTheme } = useTheme();
|
|
71
77
|
return (jsx(AccordionProvider, { expanded: expanded, children: children }));
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
function AccordionItem({ children, label, isExpanded = false, }) {
|
|
75
81
|
const { toggle, setToggle } = useAccordion();
|
|
76
82
|
return (jsx("div", { className: "accordion-item", style: {
|
|
77
83
|
paddingLeft: toggle && label && toggle[label].paddingLeft,
|
|
@@ -83,63 +89,20 @@ const AccordionItem = forwardRef(function AccordionItem({ children, label, isExp
|
|
|
83
89
|
}),
|
|
84
90
|
isExpanded: isExpanded,
|
|
85
91
|
})) }));
|
|
86
|
-
}
|
|
92
|
+
}
|
|
87
93
|
|
|
88
94
|
const Anchor = ({ Custom, children, ...rest }) => Custom ? jsx(Custom, { ...rest, children: children }) : jsx("a", { ...rest, children: children });
|
|
89
95
|
function Button({ children = "Click me", className = "", icon = undefined, isNewWindow = false, mode = "primary", size = "medium", as = "button", CustomAnchor, ...rest }) {
|
|
90
96
|
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] }));
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
document.documentElement.setAttribute("data-theme", localStorage.getItem("data-theme"));
|
|
101
|
-
setDataTheme(localStorage.getItem("data-theme"));
|
|
102
|
-
}
|
|
103
|
-
else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
104
|
-
document.documentElement.setAttribute("data-theme", "dark");
|
|
105
|
-
setDataTheme("dark");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, []);
|
|
109
|
-
const switchDataTheme = (mode) => {
|
|
110
|
-
document.documentElement.setAttribute("data-theme", mode);
|
|
111
|
-
setDataTheme(mode);
|
|
112
|
-
localStorage.setItem("data-theme", mode);
|
|
113
|
-
};
|
|
114
|
-
const switchPaletteTheme = (mode) => {
|
|
115
|
-
document.documentElement.setAttribute("palette-theme", mode);
|
|
116
|
-
setPaletteTheme(mode);
|
|
117
|
-
localStorage.setItem("palette-theme", mode);
|
|
118
|
-
};
|
|
119
|
-
return (jsx(ThemeContext.Provider, { value: { dataTheme, switchDataTheme, paletteTheme, switchPaletteTheme }, children: children }));
|
|
120
|
-
}
|
|
121
|
-
function useTheme({ dataTheme = undefined, paletteTheme = "water", } = {}) {
|
|
122
|
-
const context = useContext(ThemeContext);
|
|
123
|
-
// only happens if there is an initial mode value.
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
if (dataTheme && !localStorage.getItem("data-theme")) {
|
|
126
|
-
context?.switchDataTheme(dataTheme);
|
|
127
|
-
}
|
|
128
|
-
else if (!dataTheme && localStorage.getItem("data-theme")) {
|
|
129
|
-
localStorage.removeItem("data-theme");
|
|
130
|
-
}
|
|
131
|
-
}, []);
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
context?.switchPaletteTheme(paletteTheme);
|
|
134
|
-
}, []);
|
|
135
|
-
if (context === undefined) {
|
|
136
|
-
throw new Error("useTheme must be used within a ThemeProvider");
|
|
137
|
-
}
|
|
138
|
-
return context;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const AccordionButton = forwardRef(function AccordionButton({ children, is = "link", label, toggle, setToggle, ...rest }, ref) {
|
|
142
|
-
const { dataTheme } = useTheme();
|
|
99
|
+
// import { useTheme } from "../../context/themeContext";
|
|
100
|
+
function AccordionButton({ children, is = "link", label,
|
|
101
|
+
// toggle,
|
|
102
|
+
// setToggle = (prev: any) => void,
|
|
103
|
+
...rest }) {
|
|
104
|
+
// const { dataTheme } = useTheme();
|
|
105
|
+
const { toggle, setToggle } = useAccordion();
|
|
143
106
|
const handleToggle = () => {
|
|
144
107
|
setToggle((prev) => {
|
|
145
108
|
if (label) {
|
|
@@ -156,14 +119,18 @@ const AccordionButton = forwardRef(function AccordionButton({ children, is = "li
|
|
|
156
119
|
}
|
|
157
120
|
});
|
|
158
121
|
};
|
|
159
|
-
return (jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}
|
|
122
|
+
return (jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}`
|
|
123
|
+
// `accordion-button__${is}--${dataTheme}`
|
|
124
|
+
), ...(is !== "link" && {
|
|
160
125
|
icon: label && toggle && toggle[label].isToggle ? (jsx(TfiAngleDown, {})) : (jsx(TfiAngleUp, {})),
|
|
161
126
|
}), ...(is !== "link" && { onClick: handleToggle }), ...rest, children: children }));
|
|
162
|
-
}
|
|
127
|
+
}
|
|
163
128
|
|
|
164
|
-
const AccordionContent =
|
|
165
|
-
return label &&
|
|
166
|
-
|
|
129
|
+
const AccordionContent = function AccordionContent({ children, label, toggle, }) {
|
|
130
|
+
return (label &&
|
|
131
|
+
toggle &&
|
|
132
|
+
toggle[label].isToggle && (jsx("div", { className: "accordion-content", children: children })));
|
|
133
|
+
};
|
|
167
134
|
|
|
168
135
|
function Input({ className = "", classNameGroup = "", errorMessage = "", inputRef, styleGroup, ...rest }) {
|
|
169
136
|
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 })] }));
|
|
@@ -196,6 +163,54 @@ function Loading({ img, children }) {
|
|
|
196
163
|
return (jsxs("div", { className: "loading", children: [jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
197
164
|
}
|
|
198
165
|
|
|
166
|
+
const ThemeContext = createContext(undefined);
|
|
167
|
+
function ThemeProvider({ children }) {
|
|
168
|
+
const [dataTheme, setDataTheme] = useState();
|
|
169
|
+
const [paletteTheme, setPaletteTheme] = useState();
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (window.matchMedia) {
|
|
172
|
+
if (localStorage.getItem("data-theme")) {
|
|
173
|
+
document.documentElement.setAttribute("data-theme", localStorage.getItem("data-theme"));
|
|
174
|
+
setDataTheme(localStorage.getItem("data-theme"));
|
|
175
|
+
}
|
|
176
|
+
else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
177
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
178
|
+
setDataTheme("dark");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}, []);
|
|
182
|
+
const switchDataTheme = (mode) => {
|
|
183
|
+
document.documentElement.setAttribute("data-theme", mode);
|
|
184
|
+
setDataTheme(mode);
|
|
185
|
+
localStorage.setItem("data-theme", mode);
|
|
186
|
+
};
|
|
187
|
+
const switchPaletteTheme = (mode) => {
|
|
188
|
+
document.documentElement.setAttribute("palette-theme", mode);
|
|
189
|
+
setPaletteTheme(mode);
|
|
190
|
+
localStorage.setItem("palette-theme", mode);
|
|
191
|
+
};
|
|
192
|
+
return (jsx(ThemeContext.Provider, { value: { dataTheme, switchDataTheme, paletteTheme, switchPaletteTheme }, children: children }));
|
|
193
|
+
}
|
|
194
|
+
function useTheme({ dataTheme = undefined, paletteTheme = "water", } = {}) {
|
|
195
|
+
const context = useContext(ThemeContext);
|
|
196
|
+
// only happens if there is an initial mode value.
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
if (dataTheme && !localStorage.getItem("data-theme")) {
|
|
199
|
+
context?.switchDataTheme(dataTheme);
|
|
200
|
+
}
|
|
201
|
+
else if (!dataTheme && localStorage.getItem("data-theme")) {
|
|
202
|
+
localStorage.removeItem("data-theme");
|
|
203
|
+
}
|
|
204
|
+
}, []);
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
context?.switchPaletteTheme(paletteTheme);
|
|
207
|
+
}, []);
|
|
208
|
+
if (context === undefined) {
|
|
209
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
210
|
+
}
|
|
211
|
+
return context;
|
|
212
|
+
}
|
|
213
|
+
|
|
199
214
|
const LoadingContext = createContext(undefined);
|
|
200
215
|
function loadingReducer(state, action) {
|
|
201
216
|
switch (action.type) {
|
package/package.json
CHANGED
|
Binary file
|