@geoinsight/react-components 0.3.4 → 0.3.6

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.
@@ -195,6 +195,47 @@
195
195
  padding: var(--spacing-16);
196
196
  }
197
197
 
198
+ .accordion {
199
+ display: flex;
200
+ flex-direction: column;
201
+ gap: var(--spacing-4)
202
+ }
203
+
204
+ .accordion__title {
205
+ border-radius: var(--spacing-8);
206
+ background-color: var(--color-neutral-700);
207
+ color: var(--color-neutral-100);
208
+ justify-content: flex-end;
209
+ gap: 8px;
210
+ padding: var(--spacing-8) var(--spacing-8) var(--spacing-8) var(--spacing-16);
211
+ }
212
+
213
+ .accordion__menu {
214
+ display: flex;
215
+ flex-direction: column;
216
+ gap: var(--spacing-4);
217
+ padding: 0 0 var(--spacing-8) var(--spacing-16);
218
+ }
219
+
220
+ .accordion__child {
221
+ border-radius: var(--spacing-8);
222
+ background-color: var(--color-neutral-200);
223
+ color: var(--color-neutral-900);
224
+ /* background: none !important; */
225
+ font-size: var(--font-size-14);
226
+ }
227
+
228
+ .accordion__child--active {
229
+ background-color: var(--color-neutral-500);
230
+ }
231
+
232
+ .accordion__check {
233
+ color: var(--color-neutral-500);
234
+ margin-right: calc(var(--spacing-24)*-1);
235
+ position: absolute;
236
+ right: 0;
237
+ }
238
+
198
239
  .input-group {
199
240
  display: flex;
200
241
  flex-direction: column;
package/dist/cjs/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
- var clsx = require('clsx');
5
4
  var react = require('react');
5
+ var clsx = require('clsx');
6
+ var tfi = require('react-icons/tfi');
7
+ var bs = require('react-icons/bs');
6
8
  var tb = require('react-icons/tb');
7
9
  var io5 = require('react-icons/io5');
8
10
 
@@ -11,6 +13,24 @@ function Button({ children = "Click me", className = "", icon = undefined, isNew
11
13
  return as === "link" ? (jsxRuntime.jsxs(Anchor, { Custom: CustomAnchor, ...(isNewWindow && { target: "_blank" }), className: clsx("button", mode === "secondary" ? `button button__${mode}` : "button__link", `button__${size}`, className), ...rest, children: [children, icon] })) : (jsxRuntime.jsxs("button", { className: clsx("button", `button__${mode}`, `button__${size}`, className), ...rest, children: [children, icon] }));
12
14
  }
13
15
 
16
+ function Accordion({ menu, allExpanded, defaultValue, selectValue, }) {
17
+ const [toggle, setToggle] = react.useState(Object.fromEntries(Object.entries(menu).map(([key, { isExpanded = false }]) => [
18
+ key,
19
+ allExpanded !== undefined ? allExpanded : isExpanded,
20
+ ])));
21
+ const [selected, setSelected] = react.useState(defaultValue);
22
+ const handleToggle = (name) => {
23
+ setToggle((prev) => {
24
+ return { ...prev, [name]: !prev[name] };
25
+ });
26
+ };
27
+ return (jsxRuntime.jsx("div", { className: "accordion", children: Object.keys(menu).map((item) => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Button, { className: "accordion__title", "data-theme": menu[item].dataTheme, icon: toggle[item] ? jsxRuntime.jsx(tfi.TfiAngleDown, {}) : jsxRuntime.jsx(tfi.TfiAngleUp, {}), onClick: () => handleToggle(item), children: menu[item].label }), toggle[item] && (jsxRuntime.jsx("div", { className: "accordion__menu", children: menu[item].children.map((child) => (jsxRuntime.jsx(Button, { mode: "secondary", "data-theme": menu[item].dataTheme, className: `accordion__child ${child.id === selected &&
28
+ ` accordion__child--active`}`, onClick: () => {
29
+ setSelected(child.id);
30
+ selectValue && selectValue(item, child);
31
+ }, children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [child.label, child.id === selected ? (jsxRuntime.jsx(bs.BsCheckLg, { className: "accordion__check", size: "1rem" })) : ("")] }) }))) }))] }))) }));
32
+ }
33
+
14
34
  function Input({ className = "", classNameGroup = "", errorMessage = "", inputRef, styleGroup, ...rest }) {
15
35
  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 })] }));
16
36
  }
@@ -211,6 +231,7 @@ function useModal({} = {}) {
211
231
  return context;
212
232
  }
213
233
 
234
+ exports.Accordion = Accordion;
214
235
  exports.Button = Button;
215
236
  exports.Input = Input;
216
237
  exports.Loading = Loading;
@@ -195,6 +195,47 @@
195
195
  padding: var(--spacing-16);
196
196
  }
197
197
 
198
+ .accordion {
199
+ display: flex;
200
+ flex-direction: column;
201
+ gap: var(--spacing-4)
202
+ }
203
+
204
+ .accordion__title {
205
+ border-radius: var(--spacing-8);
206
+ background-color: var(--color-neutral-700);
207
+ color: var(--color-neutral-100);
208
+ justify-content: flex-end;
209
+ gap: 8px;
210
+ padding: var(--spacing-8) var(--spacing-8) var(--spacing-8) var(--spacing-16);
211
+ }
212
+
213
+ .accordion__menu {
214
+ display: flex;
215
+ flex-direction: column;
216
+ gap: var(--spacing-4);
217
+ padding: 0 0 var(--spacing-8) var(--spacing-16);
218
+ }
219
+
220
+ .accordion__child {
221
+ border-radius: var(--spacing-8);
222
+ background-color: var(--color-neutral-200);
223
+ color: var(--color-neutral-900);
224
+ /* background: none !important; */
225
+ font-size: var(--font-size-14);
226
+ }
227
+
228
+ .accordion__child--active {
229
+ background-color: var(--color-neutral-500);
230
+ }
231
+
232
+ .accordion__check {
233
+ color: var(--color-neutral-500);
234
+ margin-right: calc(var(--spacing-24)*-1);
235
+ position: absolute;
236
+ right: 0;
237
+ }
238
+
198
239
  .input-group {
199
240
  display: flex;
200
241
  flex-direction: column;
package/dist/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { useState, useRef, createContext, useEffect, useContext, useReducer } from 'react';
2
3
  import clsx from 'clsx';
3
- import { useRef, useState, createContext, useEffect, useContext, useReducer } from 'react';
4
+ import { TfiAngleDown, TfiAngleUp } from 'react-icons/tfi';
5
+ import { BsCheckLg } from 'react-icons/bs';
4
6
  import { TbArrowsDiagonal2 } from 'react-icons/tb';
5
7
  import { IoClose } from 'react-icons/io5';
6
8
 
@@ -9,6 +11,24 @@ function Button({ children = "Click me", className = "", icon = undefined, isNew
9
11
  return as === "link" ? (jsxs(Anchor, { Custom: CustomAnchor, ...(isNewWindow && { target: "_blank" }), className: clsx("button", mode === "secondary" ? `button button__${mode}` : "button__link", `button__${size}`, className), ...rest, children: [children, icon] })) : (jsxs("button", { className: clsx("button", `button__${mode}`, `button__${size}`, className), ...rest, children: [children, icon] }));
10
12
  }
11
13
 
14
+ function Accordion({ menu, allExpanded, defaultValue, selectValue, }) {
15
+ const [toggle, setToggle] = useState(Object.fromEntries(Object.entries(menu).map(([key, { isExpanded = false }]) => [
16
+ key,
17
+ allExpanded !== undefined ? allExpanded : isExpanded,
18
+ ])));
19
+ const [selected, setSelected] = useState(defaultValue);
20
+ const handleToggle = (name) => {
21
+ setToggle((prev) => {
22
+ return { ...prev, [name]: !prev[name] };
23
+ });
24
+ };
25
+ return (jsx("div", { className: "accordion", children: Object.keys(menu).map((item) => (jsxs(Fragment, { children: [jsx(Button, { className: "accordion__title", "data-theme": menu[item].dataTheme, icon: toggle[item] ? jsx(TfiAngleDown, {}) : jsx(TfiAngleUp, {}), onClick: () => handleToggle(item), children: menu[item].label }), toggle[item] && (jsx("div", { className: "accordion__menu", children: menu[item].children.map((child) => (jsx(Button, { mode: "secondary", "data-theme": menu[item].dataTheme, className: `accordion__child ${child.id === selected &&
26
+ ` accordion__child--active`}`, onClick: () => {
27
+ setSelected(child.id);
28
+ selectValue && selectValue(item, child);
29
+ }, children: jsxs(Fragment, { children: [child.label, child.id === selected ? (jsx(BsCheckLg, { className: "accordion__check", size: "1rem" })) : ("")] }) }))) }))] }))) }));
30
+ }
31
+
12
32
  function Input({ className = "", classNameGroup = "", errorMessage = "", inputRef, styleGroup, ...rest }) {
13
33
  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 })] }));
14
34
  }
@@ -209,4 +229,4 @@ function useModal({} = {}) {
209
229
  return context;
210
230
  }
211
231
 
212
- export { Button, Input, Loading, LoadingContext, LoadingProvider, Modal, ModalContext, ModalProvider, TextArea, ThemeContext, ThemeProvider, useLoading, useModal, useTheme };
232
+ export { Accordion, Button, Input, Loading, LoadingContext, LoadingProvider, Modal, ModalContext, ModalProvider, TextArea, ThemeContext, ThemeProvider, useLoading, useModal, useTheme };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoinsight/react-components",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
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",