@geoinsight/react-components 0.4.2 → 0.4.4

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 CHANGED
@@ -16,8 +16,8 @@ function recursiveChildren(children, i = 0) {
16
16
  return react.cloneElement(child, {
17
17
  ...child.props,
18
18
  children: recursiveChildren(child.props.children, i++),
19
- ...(child?.type?.displayName === "AccordionItem" && {
20
- label: `${child?.type?.displayName}-${index}-${i}`,
19
+ ...(child?.type?.name === "AccordionItem" && {
20
+ label: `${child?.type?.name}-${index}-${i}`,
21
21
  }),
22
22
  });
23
23
  }
@@ -30,7 +30,7 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
30
30
  }
31
31
  for (const child of children) {
32
32
  if (react.isValidElement(child)) {
33
- if (child?.type?.displayName === "AccordionItem" && child.props.label) {
33
+ if (child?.type?.name === "AccordionItem" && child.props.label) {
34
34
  toggleArray[child.props.label] = {
35
35
  isToggle: props.expanded === "all"
36
36
  ? true
@@ -44,7 +44,7 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
44
44
  };
45
45
  }
46
46
  if (typeof child.props.children !== "string" &&
47
- child.props.children.find((v) => v?.type?.displayName === "AccordionItem")) {
47
+ child.props.children.find((v) => v?.type?.name === "AccordionItem")) {
48
48
  recursiveToggle(Array.isArray(child.props.children)
49
49
  ? child.props.children
50
50
  : [child.props.children], toggleArray, i + 1, props);
@@ -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 = react.useMemo(() => recursiveChildren(children, 0), []);
60
- const [toggle, setToggle] = react.useState(recursiveToggle(newChildren, {}, 0, { expanded }));
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,80 +71,40 @@ function useAccordion() {
68
71
  return context;
69
72
  }
70
73
 
71
- function Accordion({ children, expanded = "all", defaultValue, selectValue, }) {
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
- const AccordionItem = react.forwardRef(function AccordionItem({ children, label, isExpanded = false }, ref) {
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,
80
86
  }, children: react.Children.map(children, (child) => react.cloneElement(child, {
81
87
  toggle: toggle,
82
- setToggle: setToggle,
83
- ...(child?.type?.displayName !== "AccordionItem" && {
88
+ // setToggle: setToggle,
89
+ ...(child?.type?.name !== "AccordionItem" && {
84
90
  label: 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
- const ThemeContext = react.createContext(undefined);
96
- function ThemeProvider({ children }) {
97
- const [dataTheme, setDataTheme] = react.useState();
98
- const [paletteTheme, setPaletteTheme] = react.useState();
99
- react.useEffect(() => {
100
- if (window.matchMedia) {
101
- if (localStorage.getItem("data-theme")) {
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}`, `accordion-button__${is}--${dataTheme}`), ...(is !== "link" && {
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 = react.forwardRef(function AccordionContent({ children, label, toggle, }, ref) {
167
- return label && toggle && toggle[label].isToggle && jsxRuntime.jsx("div", { className: "accordion-content", children: children });
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, useContext, useMemo, useState, forwardRef, useEffect, useRef, useReducer } from 'react';
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';
@@ -14,8 +14,8 @@ function recursiveChildren(children, i = 0) {
14
14
  return cloneElement(child, {
15
15
  ...child.props,
16
16
  children: recursiveChildren(child.props.children, i++),
17
- ...(child?.type?.displayName === "AccordionItem" && {
18
- label: `${child?.type?.displayName}-${index}-${i}`,
17
+ ...(child?.type?.name === "AccordionItem" && {
18
+ label: `${child?.type?.name}-${index}-${i}`,
19
19
  }),
20
20
  });
21
21
  }
@@ -28,7 +28,7 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
28
28
  }
29
29
  for (const child of children) {
30
30
  if (isValidElement(child)) {
31
- if (child?.type?.displayName === "AccordionItem" && child.props.label) {
31
+ if (child?.type?.name === "AccordionItem" && child.props.label) {
32
32
  toggleArray[child.props.label] = {
33
33
  isToggle: props.expanded === "all"
34
34
  ? true
@@ -42,7 +42,7 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
42
42
  };
43
43
  }
44
44
  if (typeof child.props.children !== "string" &&
45
- child.props.children.find((v) => v?.type?.displayName === "AccordionItem")) {
45
+ child.props.children.find((v) => v?.type?.name === "AccordionItem")) {
46
46
  recursiveToggle(Array.isArray(child.props.children)
47
47
  ? child.props.children
48
48
  : [child.props.children], toggleArray, i + 1, props);
@@ -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 = useMemo(() => recursiveChildren(children, 0), []);
58
- const [toggle, setToggle] = useState(recursiveToggle(newChildren, {}, 0, { expanded }));
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,80 +69,40 @@ function useAccordion() {
66
69
  return context;
67
70
  }
68
71
 
69
- function Accordion({ children, expanded = "all", defaultValue, selectValue, }) {
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
- const AccordionItem = forwardRef(function AccordionItem({ children, label, isExpanded = false }, ref) {
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,
78
84
  }, children: Children.map(children, (child) => cloneElement(child, {
79
85
  toggle: toggle,
80
- setToggle: setToggle,
81
- ...(child?.type?.displayName !== "AccordionItem" && {
86
+ // setToggle: setToggle,
87
+ ...(child?.type?.name !== "AccordionItem" && {
82
88
  label: label,
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
- const ThemeContext = createContext(undefined);
94
- function ThemeProvider({ children }) {
95
- const [dataTheme, setDataTheme] = useState();
96
- const [paletteTheme, setPaletteTheme] = useState();
97
- useEffect(() => {
98
- if (window.matchMedia) {
99
- if (localStorage.getItem("data-theme")) {
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}`, `accordion-button__${is}--${dataTheme}`), ...(is !== "link" && {
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 = forwardRef(function AccordionContent({ children, label, toggle, }, ref) {
165
- return label && toggle && toggle[label].isToggle && jsx("div", { className: "accordion-content", children: children });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoinsight/react-components",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "This library is the main UI component library for geoinsight",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",