@geoinsight/react-components 0.5.2 → 0.6.0

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.
@@ -27,6 +27,8 @@
27
27
  --spacing-96: 6rem;
28
28
  --spacing-128: 8rem;
29
29
 
30
+ --size-m: 12rem;
31
+
30
32
  --color-black: #1d1d1d;
31
33
  --color-white: #eee;
32
34
 
@@ -152,7 +154,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
152
154
  }
153
155
 
154
156
  .accordion-button__button--dark.button {
155
- background-color: var(--color-neutral-200);
157
+ background-color: var(--color-neutral-400);
156
158
  }
157
159
 
158
160
  .accordion-button__button--light.button {
@@ -160,7 +162,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
160
162
  }
161
163
 
162
164
  .accordion-button__link--dark.button {
163
- background-color: var(--color-neutral-100) !important;
165
+ background-color: var(--color-neutral-200) !important;
164
166
  }
165
167
 
166
168
  .accordion-button__link--light.button {
@@ -309,6 +311,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
309
311
  display: flex;
310
312
  flex-direction: column;
311
313
  align-items: flex-start;
314
+ position: relative;
312
315
  width: 100%;
313
316
  }
314
317
 
@@ -319,16 +322,36 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
319
322
  border: 2px solid var(--color-primary);
320
323
  color: var(--color-black);
321
324
  padding: var(--spacing-16) var(--spacing-24);
322
- font-size:var(--font-size-16);
325
+ font-size: var(--font-size-16);
323
326
  width: 100%;
324
327
  }
325
328
 
329
+ .input--icon {
330
+ padding: var(--spacing-16) var(--spacing-40);
331
+ }
332
+
333
+ .input__icon {
334
+ /* padding-top: var(--spacing-8); */
335
+ padding: var(--spacing-16) var(--spacing-16);
336
+ position: absolute;
337
+ }
338
+
339
+ .input__icon--right {
340
+ right: 0;
341
+ }
342
+
343
+ .input__icon--left {
344
+ left: 0;
345
+ }
346
+
326
347
  .input:enabled:hover {
327
- border: 3px solid var(--color-primary-700);
348
+ box-shadow: 2px 6px 4px 0 var(--color-neutral-400);
349
+ transition: var(--transition-box-shadow-cubic-bezier);
328
350
  }
329
351
 
330
352
  .input:focus {
331
- border: 3px solid var(--color-primary-700);
353
+ box-shadow: 2px 6px 4px 0 var(--color-neutral-400);
354
+ transition: var(--transition-box-shadow-cubic-bezier);
332
355
  outline: none;
333
356
  }
334
357
 
package/dist/cjs/index.js CHANGED
@@ -9,6 +9,14 @@ var reactHookForm = require('react-hook-form');
9
9
  var io5 = require('react-icons/io5');
10
10
  var tb = require('react-icons/tb');
11
11
 
12
+ let uniqueId = (function () {
13
+ let num = 0;
14
+ return function (prefix) {
15
+ prefix = String(prefix) || '';
16
+ num += 1;
17
+ return prefix + num;
18
+ };
19
+ }());
12
20
  function recursiveChildren(children, i = 0) {
13
21
  return react.Children.map(children, (child, index) => {
14
22
  if (!react.isValidElement(child)) {
@@ -19,7 +27,7 @@ function recursiveChildren(children, i = 0) {
19
27
  ...child.props,
20
28
  children: recursiveChildren(child.props.children, i++),
21
29
  ...(child?.type?.name === "AccordionItem" && {
22
- label: `${child?.type?.name}-${index}-${i}`,
30
+ label: uniqueId("id_") // `${(child?.type as any)?.name}-${index}-${i}`,
23
31
  }),
24
32
  });
25
33
  }
@@ -58,7 +66,7 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
58
66
 
59
67
  const AccordionContext = react.createContext(undefined);
60
68
  function AccordionProvider({ children, expanded = "all" }) {
61
- const newChildren = recursiveChildren(children, 0);
69
+ const newChildren = react.useMemo(() => recursiveChildren(children, 0), []);
62
70
  const [toggle, _setToggle] = react.useState(recursiveToggle(newChildren, {}, 0, { expanded }));
63
71
  const setToggle = (prev) => {
64
72
  _setToggle(prev);
@@ -84,7 +92,7 @@ function Accordion({ children, expanded = "all",
84
92
  function AccordionItem({ children, label, isExpanded = false, }) {
85
93
  const { toggle } = useAccordion();
86
94
  return (jsxRuntime.jsx("div", { className: "accordion-item", style: {
87
- paddingLeft: toggle && label && toggle[label].paddingLeft,
95
+ paddingLeft: toggle && label && toggle[label]?.paddingLeft,
88
96
  }, children: react.Children.map(children, (child) => react.cloneElement(child, {
89
97
  toggle: toggle,
90
98
  // setToggle: setToggle,
@@ -190,27 +198,35 @@ function Form({ children, onSubmit, submitButton = {
190
198
  return (jsxRuntime.jsxs("form", { className: "form", onSubmit: handleSubmit(async (data) => await onSubmit(data, setResult)), ...rest, children: [react.Children.map(children, (child) => {
191
199
  const { props: { name, error, isRequired, ...rest }, } = child;
192
200
  return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
193
- ...(isRequired ? {
194
- required: error?.message || "Field is required",
195
- } : {}),
196
- }, render: ({ field }) => react.cloneElement(child, {
197
- error: {
198
- is: Object.keys(errors).length > 0 && !!errors[name],
199
- message: errors &&
200
- Object.keys(errors).length > 0 &&
201
- errors[name]?.message,
202
- },
203
- ...field,
204
- ...rest,
205
- }) }));
201
+ ...(isRequired
202
+ ? {
203
+ required: error?.message || "Field is required",
204
+ }
205
+ : {}),
206
+ }, render: ({ field: { ...restField } }) => {
207
+ return react.cloneElement(child, {
208
+ error: {
209
+ is: Object.keys(errors).length > 0 && !!errors[name],
210
+ message: errors &&
211
+ Object.keys(errors).length > 0 &&
212
+ errors[name]?.message,
213
+ },
214
+ // name: name,
215
+ // value: value || rest.value,
216
+ ...restField,
217
+ ...rest,
218
+ });
219
+ } }));
206
220
  }), result.message && (jsxRuntime.jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsxRuntime.jsx(bs.BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsxRuntime.jsx(bs.BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsxRuntime.jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }));
207
221
  }
208
222
 
209
- function Input({ className = "", classNameGroup = "", error = {
223
+ function Input({ inputClassName = "", classNameGroup = "", error = {
210
224
  is: false,
211
225
  message: "",
212
- }, inputRef, styleGroup, placeholder = "Insert value", isRequired, label, labelClass, ...rest }) {
213
- return (jsxRuntime.jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [label && jsxRuntime.jsx("label", { className: labelClass, children: label }), jsxRuntime.jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", className), placeholder: placeholder, ...rest }), error && error.is && jsxRuntime.jsx("span", { className: "error", children: error.message })] }));
226
+ }, inputRef, styleGroup, placeholder = "Insert value", label, labelClass, icon, ...rest }) {
227
+ return (jsxRuntime.jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [label && jsxRuntime.jsx("label", { className: labelClass, children: label }), icon?.element && icon.position === "left" && (jsxRuntime.jsx("div", { className: clsx("input__icon", "input__icon--left", icon.className), children: icon.element })), jsxRuntime.jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", icon?.position === "left" && "input--icon", inputClassName), placeholder: placeholder, ...rest }), icon?.element && icon.position !== "left" && (jsxRuntime.jsx("div", { className: clsx("input__icon", "input__icon--right",
228
+ // `input__icon--${icon.position || "right"}`,
229
+ icon.className), children: icon.element })), error && error.is && (jsxRuntime.jsx("span", { className: "error", children: error.message }))] }));
214
230
  }
215
231
 
216
232
  function Loading({ img, children }) {
@@ -27,6 +27,8 @@
27
27
  --spacing-96: 6rem;
28
28
  --spacing-128: 8rem;
29
29
 
30
+ --size-m: 12rem;
31
+
30
32
  --color-black: #1d1d1d;
31
33
  --color-white: #eee;
32
34
 
@@ -152,7 +154,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
152
154
  }
153
155
 
154
156
  .accordion-button__button--dark.button {
155
- background-color: var(--color-neutral-200);
157
+ background-color: var(--color-neutral-400);
156
158
  }
157
159
 
158
160
  .accordion-button__button--light.button {
@@ -160,7 +162,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
160
162
  }
161
163
 
162
164
  .accordion-button__link--dark.button {
163
- background-color: var(--color-neutral-100) !important;
165
+ background-color: var(--color-neutral-200) !important;
164
166
  }
165
167
 
166
168
  .accordion-button__link--light.button {
@@ -309,6 +311,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
309
311
  display: flex;
310
312
  flex-direction: column;
311
313
  align-items: flex-start;
314
+ position: relative;
312
315
  width: 100%;
313
316
  }
314
317
 
@@ -319,16 +322,36 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
319
322
  border: 2px solid var(--color-primary);
320
323
  color: var(--color-black);
321
324
  padding: var(--spacing-16) var(--spacing-24);
322
- font-size:var(--font-size-16);
325
+ font-size: var(--font-size-16);
323
326
  width: 100%;
324
327
  }
325
328
 
329
+ .input--icon {
330
+ padding: var(--spacing-16) var(--spacing-40);
331
+ }
332
+
333
+ .input__icon {
334
+ /* padding-top: var(--spacing-8); */
335
+ padding: var(--spacing-16) var(--spacing-16);
336
+ position: absolute;
337
+ }
338
+
339
+ .input__icon--right {
340
+ right: 0;
341
+ }
342
+
343
+ .input__icon--left {
344
+ left: 0;
345
+ }
346
+
326
347
  .input:enabled:hover {
327
- border: 3px solid var(--color-primary-700);
348
+ box-shadow: 2px 6px 4px 0 var(--color-neutral-400);
349
+ transition: var(--transition-box-shadow-cubic-bezier);
328
350
  }
329
351
 
330
352
  .input:focus {
331
- border: 3px solid var(--color-primary-700);
353
+ box-shadow: 2px 6px 4px 0 var(--color-neutral-400);
354
+ transition: var(--transition-box-shadow-cubic-bezier);
332
355
  outline: none;
333
356
  }
334
357
 
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, useState, useContext, useEffect, useRef, useReducer } from 'react';
2
+ import { Children, isValidElement, cloneElement, createContext, useMemo, useState, useContext, useEffect, useRef, useReducer } from 'react';
3
3
  import clsx from 'clsx';
4
4
  import { TfiAngleDown, TfiAngleUp } from 'react-icons/tfi';
5
5
  import { BsCheckCircleFill, BsXCircleFill } from 'react-icons/bs';
@@ -7,6 +7,14 @@ import { useForm, Controller } from 'react-hook-form';
7
7
  import { IoClose } from 'react-icons/io5';
8
8
  import { TbArrowsDiagonal2 } from 'react-icons/tb';
9
9
 
10
+ let uniqueId = (function () {
11
+ let num = 0;
12
+ return function (prefix) {
13
+ prefix = String(prefix) || '';
14
+ num += 1;
15
+ return prefix + num;
16
+ };
17
+ }());
10
18
  function recursiveChildren(children, i = 0) {
11
19
  return Children.map(children, (child, index) => {
12
20
  if (!isValidElement(child)) {
@@ -17,7 +25,7 @@ function recursiveChildren(children, i = 0) {
17
25
  ...child.props,
18
26
  children: recursiveChildren(child.props.children, i++),
19
27
  ...(child?.type?.name === "AccordionItem" && {
20
- label: `${child?.type?.name}-${index}-${i}`,
28
+ label: uniqueId("id_") // `${(child?.type as any)?.name}-${index}-${i}`,
21
29
  }),
22
30
  });
23
31
  }
@@ -56,7 +64,7 @@ function recursiveToggle(children, toggleArray = {}, i = 0, props) {
56
64
 
57
65
  const AccordionContext = createContext(undefined);
58
66
  function AccordionProvider({ children, expanded = "all" }) {
59
- const newChildren = recursiveChildren(children, 0);
67
+ const newChildren = useMemo(() => recursiveChildren(children, 0), []);
60
68
  const [toggle, _setToggle] = useState(recursiveToggle(newChildren, {}, 0, { expanded }));
61
69
  const setToggle = (prev) => {
62
70
  _setToggle(prev);
@@ -82,7 +90,7 @@ function Accordion({ children, expanded = "all",
82
90
  function AccordionItem({ children, label, isExpanded = false, }) {
83
91
  const { toggle } = useAccordion();
84
92
  return (jsx("div", { className: "accordion-item", style: {
85
- paddingLeft: toggle && label && toggle[label].paddingLeft,
93
+ paddingLeft: toggle && label && toggle[label]?.paddingLeft,
86
94
  }, children: Children.map(children, (child) => cloneElement(child, {
87
95
  toggle: toggle,
88
96
  // setToggle: setToggle,
@@ -188,27 +196,35 @@ function Form({ children, onSubmit, submitButton = {
188
196
  return (jsxs("form", { className: "form", onSubmit: handleSubmit(async (data) => await onSubmit(data, setResult)), ...rest, children: [Children.map(children, (child) => {
189
197
  const { props: { name, error, isRequired, ...rest }, } = child;
190
198
  return (jsx(Controller, { name: name, control: control, rules: {
191
- ...(isRequired ? {
192
- required: error?.message || "Field is required",
193
- } : {}),
194
- }, render: ({ field }) => cloneElement(child, {
195
- error: {
196
- is: Object.keys(errors).length > 0 && !!errors[name],
197
- message: errors &&
198
- Object.keys(errors).length > 0 &&
199
- errors[name]?.message,
200
- },
201
- ...field,
202
- ...rest,
203
- }) }));
199
+ ...(isRequired
200
+ ? {
201
+ required: error?.message || "Field is required",
202
+ }
203
+ : {}),
204
+ }, render: ({ field: { ...restField } }) => {
205
+ return cloneElement(child, {
206
+ error: {
207
+ is: Object.keys(errors).length > 0 && !!errors[name],
208
+ message: errors &&
209
+ Object.keys(errors).length > 0 &&
210
+ errors[name]?.message,
211
+ },
212
+ // name: name,
213
+ // value: value || rest.value,
214
+ ...restField,
215
+ ...rest,
216
+ });
217
+ } }));
204
218
  }), result.message && (jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsx(BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsx(BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }));
205
219
  }
206
220
 
207
- function Input({ className = "", classNameGroup = "", error = {
221
+ function Input({ inputClassName = "", classNameGroup = "", error = {
208
222
  is: false,
209
223
  message: "",
210
- }, inputRef, styleGroup, placeholder = "Insert value", isRequired, label, labelClass, ...rest }) {
211
- return (jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [label && jsx("label", { className: labelClass, children: label }), jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", className), placeholder: placeholder, ...rest }), error && error.is && jsx("span", { className: "error", children: error.message })] }));
224
+ }, inputRef, styleGroup, placeholder = "Insert value", label, labelClass, icon, ...rest }) {
225
+ return (jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [label && jsx("label", { className: labelClass, children: label }), icon?.element && icon.position === "left" && (jsx("div", { className: clsx("input__icon", "input__icon--left", icon.className), children: icon.element })), jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", icon?.position === "left" && "input--icon", inputClassName), placeholder: placeholder, ...rest }), icon?.element && icon.position !== "left" && (jsx("div", { className: clsx("input__icon", "input__icon--right",
226
+ // `input__icon--${icon.position || "right"}`,
227
+ icon.className), children: icon.element })), error && error.is && (jsx("span", { className: "error", children: error.message }))] }));
212
228
  }
213
229
 
214
230
  function Loading({ img, children }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoinsight/react-components",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
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",
@@ -31,6 +31,7 @@
31
31
  "@rollup/plugin-node-resolve": "^15.0.1",
32
32
  "@rollup/plugin-typescript": "^11.0.0",
33
33
  "@storybook/addon-actions": "^7.0.7",
34
+ "@storybook/addon-console": "^2.0.0",
34
35
  "@storybook/addon-essentials": "^7.0.7",
35
36
  "@storybook/addon-interactions": "^7.0.7",
36
37
  "@storybook/addon-links": "^7.0.7",