@geoinsight/react-components 0.8.12 → 1.0.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.
- package/dist/cjs/index.css +463 -178
- package/dist/cjs/index.js +302 -219
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.css +463 -178
- package/dist/esm/index.js +303 -216
- package/dist/esm/index.js.map +1 -1
- package/package.json +13 -10
- package/storybook-static/115.875b767a.iframe.bundle.js +1 -0
- package/storybook-static/143.e6f5cdb6.iframe.bundle.js +2 -0
- package/storybook-static/143.e6f5cdb6.iframe.bundle.js.LICENSE.txt +5 -0
- package/storybook-static/155.77237ba4.iframe.bundle.js +1 -0
- package/storybook-static/439.c739b452.iframe.bundle.js +1 -0
- package/storybook-static/49.9b0e5ded.iframe.bundle.js +2 -0
- package/storybook-static/497.a86e867f.iframe.bundle.js +134 -0
- package/storybook-static/497.a86e867f.iframe.bundle.js.map +1 -0
- package/storybook-static/607.55c78741.iframe.bundle.js +1 -0
- package/storybook-static/729.0e069928.iframe.bundle.js +1 -0
- package/storybook-static/750.1274e780.iframe.bundle.js +1 -0
- package/storybook-static/751.ce4b4118.iframe.bundle.js +411 -0
- package/storybook-static/751.ce4b4118.iframe.bundle.js.map +1 -0
- package/storybook-static/797.7e13109b.iframe.bundle.js +1 -0
- package/storybook-static/887.40a58cdf.iframe.bundle.js +1 -0
- package/storybook-static/components-button-index-stories.6b018cc0.iframe.bundle.js +1 -0
- package/storybook-static/components-form-index-stories.847721d0.iframe.bundle.js +1 -0
- package/storybook-static/components-input-index-stories.dba32411.iframe.bundle.js +2 -0
- package/storybook-static/components-loading-index-stories.b0653762.iframe.bundle.js +2 -0
- package/storybook-static/components-map-index-stories.08759744.iframe.bundle.js +1 -0
- package/storybook-static/components-menu-index-stories.0c6eb18b.iframe.bundle.js +1 -0
- package/storybook-static/components-modal-index-stories.ef8c8dd0.iframe.bundle.js +2 -0
- package/storybook-static/components-select-index-stories.a5ffb2f5.iframe.bundle.js +1 -0
- package/storybook-static/components-text-area-index-stories.44892133.iframe.bundle.js +2 -0
- package/storybook-static/context-loading-index-stories.ad731185.iframe.bundle.js +2 -0
- package/storybook-static/context-modal-index-stories.a607105d.iframe.bundle.js +2 -0
- package/storybook-static/iframe.html +4 -4
- package/storybook-static/index.html +2 -1
- package/storybook-static/index.json +1 -1
- package/storybook-static/main.9dd1aacd.iframe.bundle.js +1 -0
- package/storybook-static/project.json +1 -1
- package/storybook-static/runtime~main.3725a291.iframe.bundle.js +1 -0
- package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js +4 -4
- package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js +37 -88
- package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js +1 -1
- package/storybook-static/sb-addons/interactions-8/manager-bundle.js +9 -24
- package/storybook-static/sb-addons/links-0/manager-bundle.js +1 -1
- package/storybook-static/sb-manager/WithTooltip-V3YHNWJZ-LVYLGZW2.js +1 -0
- package/storybook-static/sb-manager/chunk-2IXBUOFS.js +7 -0
- package/storybook-static/sb-manager/{chunk-DAJ4OSDJ.js → chunk-F4FCO4CF.js} +23 -23
- package/storybook-static/sb-manager/{chunk-NFZCBIX3.js → chunk-INSKDKQB.js} +6 -6
- package/storybook-static/sb-manager/chunk-NGTUFCUO.js +9 -0
- package/storybook-static/sb-manager/globals-module-info.js +1 -0
- package/storybook-static/sb-manager/globals.js +1 -1
- package/storybook-static/sb-manager/index.js +1 -1
- package/storybook-static/sb-manager/runtime.js +1 -1
- package/storybook-static/sb-manager/{syntaxhighlighter-NMPM6SWI-GZTSOZ5L.js → syntaxhighlighter-V7JZZA35-DXZCI2WR.js} +1 -1
- package/storybook-static/sb-preview/globals.js +1 -1
- package/storybook-static/sb-preview/runtime.js +16 -16
- package/storybook-static/static/media/loading.cbc96c95.gif +0 -0
- package/storybook-static/stories-Introduction-stories-mdx.d86fb94b.iframe.bundle.js +2 -0
- package/storybook-static/stories-Introduction-stories-mdx.d86fb94b.iframe.bundle.js.LICENSE.txt +9 -0
- package/storybook-static/stories.json +1 -1
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +0 -1
- package/dist/cjs/components/accordion/accordion-button.d.ts +0 -4
- package/dist/cjs/components/accordion/accordion-content.d.ts +0 -4
- package/dist/cjs/components/accordion/accordion-item.d.ts +0 -4
- package/dist/cjs/components/accordion/accordion.d.ts +0 -4
- package/dist/cjs/components/accordion/index.d.ts +0 -4
- package/dist/cjs/components/accordion/index.stories.d.ts +0 -7
- package/dist/cjs/components/accordion/index.types.d.ts +0 -36
- package/dist/cjs/components/button/index.d.ts +0 -5
- package/dist/cjs/components/button/index.stories.d.ts +0 -7
- package/dist/cjs/components/button/index.types.d.ts +0 -41
- package/dist/cjs/components/form/FormInput.d.ts +0 -4
- package/dist/cjs/components/form/FormSelect.d.ts +0 -4
- package/dist/cjs/components/form/FormTextArea.d.ts +0 -4
- package/dist/cjs/components/form/index.d.ts +0 -4
- package/dist/cjs/components/form/index.stories.d.ts +0 -7
- package/dist/cjs/components/form/index.types.d.ts +0 -45
- package/dist/cjs/components/input/index.d.ts +0 -4
- package/dist/cjs/components/input/index.stories.d.ts +0 -8
- package/dist/cjs/components/input/index.types.d.ts +0 -40
- package/dist/cjs/components/loading/index.d.ts +0 -4
- package/dist/cjs/components/loading/index.stories.d.ts +0 -6
- package/dist/cjs/components/loading/index.types.d.ts +0 -11
- package/dist/cjs/components/map/MapboxMap.d.ts +0 -2
- package/dist/cjs/components/map/index.d.ts +0 -4
- package/dist/cjs/components/map/index.stories.d.ts +0 -8
- package/dist/cjs/components/map/index.types.d.ts +0 -56
- package/dist/cjs/components/map/useAddMap.d.ts +0 -8
- package/dist/cjs/components/map-control/index.d.ts +0 -4
- package/dist/cjs/components/map-control/index.types.d.ts +0 -11
- package/dist/cjs/components/modal/index.d.ts +0 -4
- package/dist/cjs/components/modal/index.stories.d.ts +0 -6
- package/dist/cjs/components/modal/index.types.d.ts +0 -39
- package/dist/cjs/components/select/index.d.ts +0 -4
- package/dist/cjs/components/select/index.stories.d.ts +0 -7
- package/dist/cjs/components/select/index.types.d.ts +0 -30
- package/dist/cjs/components/text-area/index.d.ts +0 -5
- package/dist/cjs/components/text-area/index.stories.d.ts +0 -7
- package/dist/cjs/components/text-area/index.types.d.ts +0 -43
- package/dist/cjs/context/accordion/index.d.ts +0 -10
- package/dist/cjs/context/loading/index.d.ts +0 -24
- package/dist/cjs/context/loading/index.stories.d.ts +0 -8
- package/dist/cjs/context/modal/index.d.ts +0 -29
- package/dist/cjs/context/modal/index.stories.d.ts +0 -6
- package/dist/cjs/context/theme/index.d.ts +0 -18
- package/dist/cjs/decorators/withColorScheme.d.ts +0 -7
- package/dist/cjs/decorators/withLoading.d.ts +0 -2
- package/dist/cjs/decorators/withModal.d.ts +0 -2
- package/dist/cjs/decorators/withWrapper.d.ts +0 -2
- package/dist/cjs/index.d.ts +0 -18
- package/dist/cjs/utils/palette.d.ts +0 -1
- package/dist/cjs/utils/recursive.d.ts +0 -6
- package/dist/esm/components/accordion/accordion-button.d.ts +0 -4
- package/dist/esm/components/accordion/accordion-content.d.ts +0 -4
- package/dist/esm/components/accordion/accordion-item.d.ts +0 -4
- package/dist/esm/components/accordion/accordion.d.ts +0 -4
- package/dist/esm/components/accordion/index.d.ts +0 -4
- package/dist/esm/components/accordion/index.stories.d.ts +0 -7
- package/dist/esm/components/accordion/index.types.d.ts +0 -36
- package/dist/esm/components/button/index.d.ts +0 -5
- package/dist/esm/components/button/index.stories.d.ts +0 -7
- package/dist/esm/components/button/index.types.d.ts +0 -41
- package/dist/esm/components/form/FormInput.d.ts +0 -4
- package/dist/esm/components/form/FormSelect.d.ts +0 -4
- package/dist/esm/components/form/FormTextArea.d.ts +0 -4
- package/dist/esm/components/form/index.d.ts +0 -4
- package/dist/esm/components/form/index.stories.d.ts +0 -7
- package/dist/esm/components/form/index.types.d.ts +0 -45
- package/dist/esm/components/input/index.d.ts +0 -4
- package/dist/esm/components/input/index.stories.d.ts +0 -8
- package/dist/esm/components/input/index.types.d.ts +0 -40
- package/dist/esm/components/loading/index.d.ts +0 -4
- package/dist/esm/components/loading/index.stories.d.ts +0 -6
- package/dist/esm/components/loading/index.types.d.ts +0 -11
- package/dist/esm/components/map/MapboxMap.d.ts +0 -2
- package/dist/esm/components/map/index.d.ts +0 -4
- package/dist/esm/components/map/index.stories.d.ts +0 -8
- package/dist/esm/components/map/index.types.d.ts +0 -56
- package/dist/esm/components/map/useAddMap.d.ts +0 -8
- package/dist/esm/components/map-control/index.d.ts +0 -4
- package/dist/esm/components/map-control/index.types.d.ts +0 -11
- package/dist/esm/components/modal/index.d.ts +0 -4
- package/dist/esm/components/modal/index.stories.d.ts +0 -6
- package/dist/esm/components/modal/index.types.d.ts +0 -39
- package/dist/esm/components/select/index.d.ts +0 -4
- package/dist/esm/components/select/index.stories.d.ts +0 -7
- package/dist/esm/components/select/index.types.d.ts +0 -30
- package/dist/esm/components/text-area/index.d.ts +0 -5
- package/dist/esm/components/text-area/index.stories.d.ts +0 -7
- package/dist/esm/components/text-area/index.types.d.ts +0 -43
- package/dist/esm/context/accordion/index.d.ts +0 -10
- package/dist/esm/context/loading/index.d.ts +0 -24
- package/dist/esm/context/loading/index.stories.d.ts +0 -8
- package/dist/esm/context/modal/index.d.ts +0 -29
- package/dist/esm/context/modal/index.stories.d.ts +0 -6
- package/dist/esm/context/theme/index.d.ts +0 -18
- package/dist/esm/decorators/withColorScheme.d.ts +0 -7
- package/dist/esm/decorators/withLoading.d.ts +0 -2
- package/dist/esm/decorators/withModal.d.ts +0 -2
- package/dist/esm/decorators/withWrapper.d.ts +0 -2
- package/dist/esm/index.d.ts +0 -18
- package/dist/esm/utils/palette.d.ts +0 -1
- package/dist/esm/utils/recursive.d.ts +0 -6
- package/storybook-static/145.34858399.iframe.bundle.js +0 -2
- package/storybook-static/296.673fff81.iframe.bundle.js +0 -1
- package/storybook-static/439.51454c4d.iframe.bundle.js +0 -1
- package/storybook-static/471.f9d522fc.iframe.bundle.js +0 -402
- package/storybook-static/471.f9d522fc.iframe.bundle.js.map +0 -1
- package/storybook-static/497.dafe304f.iframe.bundle.js +0 -134
- package/storybook-static/497.dafe304f.iframe.bundle.js.map +0 -1
- package/storybook-static/659.1ad30476.iframe.bundle.js +0 -1
- package/storybook-static/677.e7db0cd6.iframe.bundle.js +0 -2
- package/storybook-static/677.e7db0cd6.iframe.bundle.js.LICENSE.txt +0 -15
- package/storybook-static/729.01f72d48.iframe.bundle.js +0 -1
- package/storybook-static/750.2215b5aa.iframe.bundle.js +0 -1
- package/storybook-static/796.09f6c96d.iframe.bundle.js +0 -1
- package/storybook-static/984.6be9debc.iframe.bundle.js +0 -1
- package/storybook-static/components-accordion-index-stories.ef18c840.iframe.bundle.js +0 -1
- package/storybook-static/components-button-index-stories.ab760bed.iframe.bundle.js +0 -2
- package/storybook-static/components-form-index-stories.3cba66b0.iframe.bundle.js +0 -1
- package/storybook-static/components-input-index-stories.52cb94b7.iframe.bundle.js +0 -2
- package/storybook-static/components-loading-index-stories.c03f4231.iframe.bundle.js +0 -2
- package/storybook-static/components-map-index-stories.df3b2a69.iframe.bundle.js +0 -1
- package/storybook-static/components-modal-index-stories.4204e0d1.iframe.bundle.js +0 -1
- package/storybook-static/components-select-index-stories.5d8e5e16.iframe.bundle.js +0 -1
- package/storybook-static/components-text-area-index-stories.c1412c7f.iframe.bundle.js +0 -2
- package/storybook-static/context-loading-index-stories.4d6c26b7.iframe.bundle.js +0 -2
- package/storybook-static/context-modal-index-stories.74348761.iframe.bundle.js +0 -1
- package/storybook-static/main.6ecf7d5b.iframe.bundle.js +0 -1
- package/storybook-static/runtime~main.b58604cf.iframe.bundle.js +0 -1
- package/storybook-static/sb-manager/WithTooltip-4HIR6TLV-YPPZ2DMB.js +0 -1
- package/storybook-static/sb-manager/chunk-FWZ33S65.js +0 -9
- package/storybook-static/sb-manager/chunk-SZNM6KS3.js +0 -7
- package/storybook-static/stories-Introduction-stories-mdx.7a2cd1ec.iframe.bundle.js +0 -2
- /package/storybook-static/{145.34858399.iframe.bundle.js.LICENSE.txt → 49.9b0e5ded.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{497.dafe304f.iframe.bundle.js.LICENSE.txt → 497.a86e867f.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{471.f9d522fc.iframe.bundle.js.LICENSE.txt → 751.ce4b4118.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{components-button-index-stories.ab760bed.iframe.bundle.js.LICENSE.txt → components-input-index-stories.dba32411.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{components-input-index-stories.52cb94b7.iframe.bundle.js.LICENSE.txt → components-loading-index-stories.b0653762.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{components-loading-index-stories.c03f4231.iframe.bundle.js.LICENSE.txt → components-modal-index-stories.ef8c8dd0.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{components-text-area-index-stories.c1412c7f.iframe.bundle.js.LICENSE.txt → components-text-area-index-stories.44892133.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{context-loading-index-stories.4d6c26b7.iframe.bundle.js.LICENSE.txt → context-loading-index-stories.ad731185.iframe.bundle.js.LICENSE.txt} +0 -0
- /package/storybook-static/{stories-Introduction-stories-mdx.7a2cd1ec.iframe.bundle.js.LICENSE.txt → context-modal-index-stories.a607105d.iframe.bundle.js.LICENSE.txt} +0 -0
package/dist/esm/index.js
CHANGED
|
@@ -1,216 +1,159 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Children, isValidElement, cloneElement, createContext,
|
|
2
|
+
import { useMemo, 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
|
-
import { BsCheckCircleFill, BsXCircleFill } from 'react-icons/bs';
|
|
5
|
+
import { BsCheckCircleFill, BsXCircleFill, BsFillMoonFill, BsFillSunFill } from 'react-icons/bs';
|
|
6
6
|
import { useForm, FormProvider, useFormContext, Controller } from 'react-hook-form';
|
|
7
7
|
import { TbArrowsDiagonal2 } from 'react-icons/tb';
|
|
8
8
|
import { IoClose } from 'react-icons/io5';
|
|
9
9
|
import DeckGL from '@deck.gl/react/typed';
|
|
10
10
|
import * as Layers from '@deck.gl/layers';
|
|
11
|
-
import { Map } from 'react-map-gl';
|
|
11
|
+
import { Popup, Map, Source, Layer } from 'react-map-gl';
|
|
12
12
|
import maplibregl from 'maplibre-gl';
|
|
13
13
|
import { FiSun, FiMoon } from 'react-icons/fi';
|
|
14
|
+
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (child.props.children) {
|
|
29
|
-
return cloneElement(child, {
|
|
30
|
-
...child.props,
|
|
31
|
-
children: recursiveChildren(child.props.children, i++),
|
|
32
|
-
...(child?.type?.name === "AccordionItem" && {
|
|
33
|
-
label: uniqueId("id_") // `${(child?.type as any)?.name}-${index}-${i}`,
|
|
34
|
-
}),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return child;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function recursiveToggle(children, toggleArray = {}, i = 0, props) {
|
|
43
|
-
if ((children && typeof children === "string") ||
|
|
44
|
-
(Array.isArray(children) && typeof children[0] === "string")) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
for (const child of children) {
|
|
48
|
-
if (isValidElement(child)) {
|
|
49
|
-
if (child?.type?.name === "AccordionItem" && child.props.label) {
|
|
50
|
-
toggleArray[child.props.label] = {
|
|
51
|
-
isToggle: props.expanded === "all"
|
|
52
|
-
? true
|
|
53
|
-
: props.expanded === "none"
|
|
54
|
-
? false
|
|
55
|
-
: props.expanded === "custom"
|
|
56
|
-
? child?.props.isExpanded
|
|
57
|
-
: false,
|
|
58
|
-
depth: i,
|
|
59
|
-
paddingLeft: `${16 * i}px`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (typeof child.props.children !== "string" &&
|
|
63
|
-
child.props.children.find((v) => v?.type?.name === "AccordionItem")) {
|
|
64
|
-
recursiveToggle(Array.isArray(child.props.children)
|
|
65
|
-
? child.props.children
|
|
66
|
-
: [child.props.children], toggleArray, i + 1, props);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return toggleArray;
|
|
16
|
+
const ALLOWED_CHILD_COMPONENT$1 = ["MenuItem"];
|
|
17
|
+
function MenuWrapper({ children }) {
|
|
18
|
+
const menuItemComponents = useMemo(() => {
|
|
19
|
+
return Children.map(children, (child) => {
|
|
20
|
+
if (!isValidElement(child))
|
|
21
|
+
return;
|
|
22
|
+
const childComponent = child.type;
|
|
23
|
+
if (!ALLOWED_CHILD_COMPONENT$1.includes(childComponent.name))
|
|
24
|
+
return;
|
|
25
|
+
return cloneElement(child);
|
|
26
|
+
});
|
|
27
|
+
}, [children]);
|
|
28
|
+
return jsx("div", { className: "menu", children: menuItemComponents });
|
|
71
29
|
}
|
|
72
30
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const [
|
|
77
|
-
const
|
|
78
|
-
|
|
31
|
+
/** Context */
|
|
32
|
+
const MenuContext = createContext({});
|
|
33
|
+
function MenuRoot({ children, isOpenByDefault }) {
|
|
34
|
+
const [items, setItems] = useState({});
|
|
35
|
+
const addItem = (item) => {
|
|
36
|
+
setItems((state) => ({
|
|
37
|
+
...state,
|
|
38
|
+
[item.id]: {
|
|
39
|
+
...item,
|
|
40
|
+
isExpanded: isOpenByDefault || false,
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
79
43
|
};
|
|
80
|
-
|
|
44
|
+
const toggle = (id) => {
|
|
45
|
+
setItems((state) => ({
|
|
46
|
+
...state,
|
|
47
|
+
[id]: {
|
|
48
|
+
...items[id],
|
|
49
|
+
isExpanded: !items[id].isExpanded || false,
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
return (jsx(MenuContext.Provider, { value: { items, addItem, toggle }, children: jsx(MenuWrapper, { children: children }) }));
|
|
81
54
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw new Error("useTheme must be used within a ThemeProvider");
|
|
55
|
+
function useMenu() {
|
|
56
|
+
if (MenuContext === undefined) {
|
|
57
|
+
throw new Error("useMenu must be used within a MenuContext Provider");
|
|
86
58
|
}
|
|
87
|
-
return
|
|
59
|
+
return MenuContext;
|
|
88
60
|
}
|
|
89
61
|
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
62
|
+
function MenuButton({ children, nested, subnested, dropdown, isLink, isSelected, handleCallbackClick, ...props }) {
|
|
63
|
+
const { toggle } = useContext(useMenu());
|
|
64
|
+
const [isToggled, setIsToggled] = useState(false);
|
|
65
|
+
const menuId = useMemo(() => props["data-menu-id"], [props]);
|
|
66
|
+
const handleClick = () => {
|
|
67
|
+
toggle(menuId);
|
|
68
|
+
setIsToggled(!isToggled);
|
|
69
|
+
handleCallbackClick && handleCallbackClick();
|
|
70
|
+
};
|
|
71
|
+
return (jsxs("div", { role: "button", className: clsx("menu-button", {
|
|
72
|
+
"menu-button-dropdown": dropdown,
|
|
73
|
+
"menu-button-nested": nested,
|
|
74
|
+
"menu-button-subnested": subnested,
|
|
75
|
+
"menu-button-is-link": isLink,
|
|
76
|
+
"menu-button-is-selected": isSelected,
|
|
77
|
+
}), onClick: handleClick, ...props, children: [children, dropdown ? (isToggled ? (jsx(TfiAngleDown, { size: "1rem" })) : (jsx(TfiAngleUp, { size: "1rem" }))) : null] }));
|
|
96
78
|
}
|
|
97
79
|
|
|
98
|
-
function
|
|
99
|
-
const {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}),
|
|
108
|
-
isExpanded: isExpanded,
|
|
109
|
-
})) }));
|
|
80
|
+
function MenuContent({ children, ...props }) {
|
|
81
|
+
const { items } = useContext(useMenu());
|
|
82
|
+
const menuId = useMemo(() => props["data-menu-id"], [props]);
|
|
83
|
+
const isExpanded = useMemo(() => {
|
|
84
|
+
return items[menuId]?.isExpanded;
|
|
85
|
+
}, [items, menuId]);
|
|
86
|
+
if (!isExpanded)
|
|
87
|
+
return;
|
|
88
|
+
return jsx("div", { ...props, children: children });
|
|
110
89
|
}
|
|
111
90
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
91
|
+
const generateId = () => {
|
|
92
|
+
return `id-${Math.random().toString(36).slice(2, 11)}`;
|
|
93
|
+
};
|
|
116
94
|
|
|
117
|
-
const
|
|
118
|
-
function
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (dataPaletteProp) {
|
|
123
|
-
switchDataPalette(dataPaletteProp);
|
|
124
|
-
}
|
|
125
|
-
}, [dataPaletteProp]);
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
if (dataThemeProp) {
|
|
128
|
-
switchDataTheme(dataThemeProp);
|
|
129
|
-
}
|
|
130
|
-
}, [dataThemeProp]);
|
|
95
|
+
const ALLOWED_CHILD_COMPONENT = ["MenuButton", "MenuContent"];
|
|
96
|
+
function MenuItem({ children, ...props }) {
|
|
97
|
+
const { addItem } = useContext(useMenu());
|
|
98
|
+
const menuId = useRef("");
|
|
131
99
|
useEffect(() => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
138
|
-
document.documentElement.setAttribute("data-theme", "dark");
|
|
139
|
-
setDataTheme("dark");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
100
|
+
menuId.current = generateId();
|
|
101
|
+
addItem({
|
|
102
|
+
id: menuId.current,
|
|
103
|
+
isExpanded: true,
|
|
104
|
+
});
|
|
142
105
|
}, []);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return (jsx(ThemeContext.Provider, { value: { dataTheme, switchDataTheme, dataPalette, switchDataPalette }, children: children }));
|
|
154
|
-
}
|
|
155
|
-
function useTheme() {
|
|
156
|
-
const context = useContext(ThemeContext);
|
|
157
|
-
if (context === undefined) {
|
|
158
|
-
throw new Error("useTheme must be used within a ThemeProvider");
|
|
159
|
-
}
|
|
160
|
-
return context;
|
|
106
|
+
return (jsx("div", { "data-menu-id": menuId.current, ...props, children: Children.map(children, (child) => {
|
|
107
|
+
if (!isValidElement(child))
|
|
108
|
+
return;
|
|
109
|
+
const childComponent = child.type;
|
|
110
|
+
if (!ALLOWED_CHILD_COMPONENT.includes(childComponent.name))
|
|
111
|
+
return;
|
|
112
|
+
return cloneElement(child, {
|
|
113
|
+
"data-menu-id": menuId.current,
|
|
114
|
+
});
|
|
115
|
+
}) }));
|
|
161
116
|
}
|
|
162
117
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
[label]: {
|
|
175
|
-
...(prev && label && prev[label]),
|
|
176
|
-
isToggle: prev && !prev[label].isToggle,
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return prev;
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
return (jsx(Button, { as: is, className: clsx("accordion-button", `accordion-button__${is}`, `accordion-button__${is}--${dataTheme}`, className), ...(is !== "link" && {
|
|
186
|
-
icon: label && toggle && toggle[label].isToggle ? (jsx(TfiAngleDown, {})) : (jsx(TfiAngleUp, {})),
|
|
187
|
-
}), ...(is !== "link" && { onClick: handleToggle }), ...rest, children: children }));
|
|
188
|
-
}
|
|
118
|
+
const Menu = {
|
|
119
|
+
Root: MenuRoot,
|
|
120
|
+
Item: MenuItem,
|
|
121
|
+
Button: MenuButton,
|
|
122
|
+
Content: MenuContent,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
126
|
+
__proto__: null,
|
|
127
|
+
default: Menu
|
|
128
|
+
});
|
|
189
129
|
|
|
190
|
-
const
|
|
191
|
-
return (
|
|
192
|
-
toggle &&
|
|
193
|
-
toggle[label].isToggle && (jsx("div", { className: clsx("accordion-content", className), children: children })));
|
|
130
|
+
const Anchor = ({ Custom, children, ...rest }) => {
|
|
131
|
+
return Custom ? (jsx(Custom, { ...rest, children: children })) : (jsx("a", { ...rest, children: children }));
|
|
194
132
|
};
|
|
133
|
+
function Button({ children = "Click me", className = "", icon = undefined, isNewWindow = false, mode = "primary", size = "medium", as = "button", CustomAnchor, ...rest }) {
|
|
134
|
+
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] }));
|
|
135
|
+
}
|
|
195
136
|
|
|
196
137
|
// how do I solve reseting the form outside the form
|
|
197
138
|
function Form({ children, onSubmit, submitButton = {
|
|
198
139
|
label: "Submit",
|
|
199
|
-
}, initialState, ...rest }) {
|
|
140
|
+
}, initialState, backgroundColor, ...rest }) {
|
|
200
141
|
const methods = useForm(initialState);
|
|
201
142
|
const { formState: { isValid }, } = methods;
|
|
202
143
|
const [result, setResult] = useState({
|
|
203
144
|
message: "",
|
|
204
145
|
isSuccess: false,
|
|
205
146
|
});
|
|
206
|
-
return (jsx(FormProvider, { ...methods, children: jsxs("form", { className: "form",
|
|
147
|
+
return (jsx(FormProvider, { ...methods, children: jsxs("form", { className: "form", style: { backgroundColor: backgroundColor }, onSubmit: methods.handleSubmit((data) => {
|
|
148
|
+
return onSubmit(data, methods, setResult);
|
|
149
|
+
}), ...rest, children: [children, 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 })] }) }));
|
|
207
150
|
}
|
|
208
151
|
|
|
209
152
|
function Input({ inputClassName = "", classNameGroup = "", error = {
|
|
210
153
|
is: false,
|
|
211
154
|
message: "",
|
|
212
|
-
}, inputRef, styleGroup, placeholder = "Insert value", label,
|
|
213
|
-
return (jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [jsxs("div", { className: "input__header", children: [label && jsx("label", { className:
|
|
155
|
+
}, inputRef, styleGroup, placeholder = "Insert value", label, labelClassName, icon, isRequired, backgroundColor, ...rest }) {
|
|
156
|
+
return (jsxs("div", { className: clsx("input-group", classNameGroup), style: { backgroundColor: backgroundColor, ...styleGroup }, children: [jsxs("div", { className: "input__header", children: [label && jsx("label", { className: labelClassName, children: label }), error && error.is && (jsx("span", { className: "input__header--error", children: error.message }))] }), jsxs("div", { className: "input-subgroup", children: [icon?.element && icon.position === "left" && (jsx("div", { className: clsx("input__icon", "input__icon--left", icon.className), children: icon.element })), jsx("input", { ref: inputRef, required: isRequired, 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",
|
|
214
157
|
// `input__icon--${icon.position || "right"}`,
|
|
215
158
|
icon.className), children: icon.element }))] })] }));
|
|
216
159
|
}
|
|
@@ -234,7 +177,7 @@ function FormInput({ name, isRequired, error, defaultValue, ...rest }) {
|
|
|
234
177
|
function TextArea({ buttonDisabled = false, className = "", disabled = true, error = {
|
|
235
178
|
is: false,
|
|
236
179
|
message: "",
|
|
237
|
-
}, hasToggleButton = true, hideHeight = "5rem", label,
|
|
180
|
+
}, hasToggleButton = true, hideHeight = "5rem", label, labelClassName, isRequired, placeholder = "Insert value", showHeight = "10rem", backgroundColor, style = {}, textareaClassName = "", ...rest }) {
|
|
238
181
|
const ref = useRef();
|
|
239
182
|
const [isShow, setIsShow] = useState(false);
|
|
240
183
|
const handleClickToggle = () => {
|
|
@@ -248,9 +191,9 @@ function TextArea({ buttonDisabled = false, className = "", disabled = true, err
|
|
|
248
191
|
setIsShow((prev) => !prev);
|
|
249
192
|
}
|
|
250
193
|
};
|
|
251
|
-
return (jsxs("div", { className: clsx("textarea", className), style: style, children: [jsxs("div", { className: "textarea__header", children: [label && jsx("label", { className:
|
|
194
|
+
return (jsxs("div", { className: clsx("textarea", className), style: { backgroundColor: backgroundColor, ...style }, children: [jsxs("div", { className: "textarea__header", children: [label && jsx("label", { className: labelClassName, children: label }), error && error.is && (jsx("span", { className: "textarea__header--error", children: error.message }))] }), jsx("textarea", { ref: ref, className: clsx("textarea__input", error.is && "textarea__input--error", textareaClassName), style: {
|
|
252
195
|
height: hasToggleButton ? hideHeight : showHeight,
|
|
253
|
-
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsx(
|
|
196
|
+
}, placeholder: placeholder, disabled: disabled, required: isRequired, ...rest }), hasToggleButton && (jsx(Button, { type: "button", className: clsx("textarea__button", isShow && "textarea__button--show", error.is && "textarea__button--error"), onClick: handleClickToggle, disabled: buttonDisabled, children: jsx(TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
254
197
|
}
|
|
255
198
|
|
|
256
199
|
function FormTextArea({ name, isRequired, error, ...rest }) {
|
|
@@ -269,9 +212,7 @@ function FormTextArea({ name, isRequired, error, ...rest }) {
|
|
|
269
212
|
} }));
|
|
270
213
|
}
|
|
271
214
|
|
|
272
|
-
function Select({ inputClassName = "", classNameGroup = "", options, styleGroup, defaultValue,
|
|
273
|
-
// inputProps,
|
|
274
|
-
setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
|
|
215
|
+
function Select({ inputClassName = "", classNameGroup = "", options, styleGroup, defaultValue, setFormSelected, clearError, resetForm, onFormBlur, handleSelect, label, labelClassName, error, backgroundColor, isRequired, ...rest }) {
|
|
275
216
|
const [isOpen, setIsOpen] = useState(false);
|
|
276
217
|
const [value, setValue] = useState(defaultValue || (options && options[0]));
|
|
277
218
|
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
@@ -294,9 +235,6 @@ setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
|
|
|
294
235
|
const handleValueChange = (e) => {
|
|
295
236
|
const { value } = e.target;
|
|
296
237
|
setValue(value);
|
|
297
|
-
// for autocomplete
|
|
298
|
-
// const { value } = e.target;
|
|
299
|
-
// setValue(value);
|
|
300
238
|
};
|
|
301
239
|
const handleSelectChange = (e) => {
|
|
302
240
|
const { name: value } = e.target;
|
|
@@ -317,25 +255,17 @@ setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
|
|
|
317
255
|
}
|
|
318
256
|
handleClose();
|
|
319
257
|
};
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
// console.log(filteredOptions);
|
|
324
|
-
// setFilteredOptions((prev: string[]) => {
|
|
325
|
-
// return options
|
|
326
|
-
// .filter((option: string) => option.includes(value))
|
|
327
|
-
// });
|
|
328
|
-
// } else {
|
|
329
|
-
// setFilteredOptions(options)
|
|
330
|
-
// }
|
|
331
|
-
// }, [value]);
|
|
332
|
-
return (jsxs("div", { className: clsx("select-group", classNameGroup), style: styleGroup, children: [jsx(Input, { inputClassName: clsx("select", inputClassName), value: value, placeholder: "Select a value", icon: {
|
|
258
|
+
return (jsxs("div", { className: clsx("select-group", classNameGroup), style: { backgroundColor: backgroundColor, ...styleGroup }, children: [jsx(Input, { inputClassName: clsx("select", {
|
|
259
|
+
"select--focus": isOpen,
|
|
260
|
+
}, inputClassName), value: value, error: error, required: isRequired, placeholder: "Select a value", icon: {
|
|
333
261
|
className: "select__arrow",
|
|
334
|
-
element: (jsx(Button, { type: "button", mode: "icon", className: "select__arrow-button",
|
|
335
|
-
|
|
262
|
+
element: (jsx(Button, { type: "button", size: "large", mode: "icon", className: clsx("select__arrow-button", {
|
|
263
|
+
"select__arrow-button--open": isOpen
|
|
264
|
+
}), onClick: handleToggle, onBlur: handleClose, children: jsx(TfiAngleDown, { size: 24 }) })),
|
|
265
|
+
}, onFocus: handleOpen, onBlur: handleInputClose, onChange: handleValueChange, autoComplete: "off", label: label, labelClassName: labelClassName, ...rest }), isOpen && (jsx("div", { className: "select__box", children: filteredOptions.map((option, index) => (jsx(Button, { type: "button", mode: "secondary", className: "select__option", name: option, onMouseDown: handleSelectChange, children: option }, `index-${index}`))) }))] }));
|
|
336
266
|
}
|
|
337
267
|
|
|
338
|
-
function FormSelect({ name, isRequired, error, fieldsToReset, ...rest }) {
|
|
268
|
+
function FormSelect({ name, isRequired, error, fieldsToReset, label, ...rest }) {
|
|
339
269
|
const { control, setValue, clearErrors, unregister, resetField } = useFormContext();
|
|
340
270
|
return (jsx(Controller, { name: name, control: control, rules: {
|
|
341
271
|
...(isRequired
|
|
@@ -344,29 +274,110 @@ function FormSelect({ name, isRequired, error, fieldsToReset, ...rest }) {
|
|
|
344
274
|
}
|
|
345
275
|
: {}),
|
|
346
276
|
}, render: ({ field: { onBlur, ...restField }, fieldState: { error } }) => {
|
|
347
|
-
return (jsx(Select, { isRequired: true, error: {
|
|
277
|
+
return (jsx(Select, { isRequired: true, label: label, error: {
|
|
348
278
|
is: !!error,
|
|
349
|
-
message: error?.message,
|
|
350
|
-
}, setFormSelected: setValue, resetForm: () => fieldsToReset &&
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
279
|
+
message: error?.message || "",
|
|
280
|
+
}, setFormSelected: setValue, resetForm: () => fieldsToReset &&
|
|
281
|
+
fieldsToReset.map((field) => {
|
|
282
|
+
setValue(field, undefined);
|
|
283
|
+
unregister(field);
|
|
284
|
+
}), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
354
285
|
} }));
|
|
355
286
|
}
|
|
356
287
|
|
|
357
|
-
|
|
358
|
-
|
|
288
|
+
var img = "data:image/gif;base64,R0lGODlhUABLAPcAAAAAAABYjwBYkAZclAlglhBmnRdrohpxpR50qSB1qiF2rCd7sFKg1Fak11ur3G667HO/8HXB8nnE9nvI9n3J+IDL+4PP/4XP/4PQ/4XQ/wBXjwBZjwRckghglQphmAxjmQ1kmg1lnBJpnxhtoip/sjGEuDSHu1+u3mSy4mWz5WW05Gu56W+77XLA8HfF9HnG9XzI94DL+oDN+wBXkARbkgVdkwdelAZglQlglwxkmRduohltoxtxph90qiB3qiV4rih8sS+EtkiYylKh1VWl13bD8nfE83vI933K+YHN+oHM/AFZkQVckwVdlAhelQpimA9lmxBlnD6Qw1Wk1l2s3WGv32Sy5Gi25mq46Wy562+87HrH+H7K+oHM+4LN/QNckhdsohpwpR90qSZ5ryh8sDGDuEGUxkqazVCi1GOy42i45m+962+97XK97nfD83jF83rG9n3H93vJ9n7K+QdelgtimBFmnBdtoxpxpiN2qyV5rSp9sy+DuDGFtzSHujeKvTmMvz2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/FHx20gBIkueTDnMW8N/KWvWbMltSbWSNouWHErt3q4XEo0eTUOw3s9dzaxe/QisRNSqZ4++FPY2Vkq6Z4vyGhdq7uCiFREvPrQS8tmQypIdevy56Exop+/EZH12oiNstf7iVNR9Nh3XWb8mRN+pvO5PfhdSjbnD/ehG4bXHHEXD/mZP2aU1FCj+UcZIXQIeNUmBknUCVYJHOcLgIlhRdNUo1ZXHSW81YcWCf3TY1iFWobm3yVkQqSVCecqZBltXGHanyVovgrWCdS3SSNBbJjyHiVyOMSZkQju6hR5iNQ6p0JFTYaakQ0yylOKTUKI4ZVhUNsRcll1tyeWDFn5ZIYRZRqmleF+aSSSaYjapXkxSXebUmzrOyaaIdtLZZZ4dWcmnnmD+CWh+gnKkZnqFDhpToittxWijrz3aZ6SSKrremTQFBAA7";
|
|
289
|
+
|
|
290
|
+
function Loading({ img: img$1, children }) {
|
|
291
|
+
return (jsxs("div", { className: "loading", children: [jsx("img", { src: img$1 ?? img }), jsx("div", { className: "loading-message", children: children })] }));
|
|
359
292
|
}
|
|
360
293
|
|
|
361
294
|
function Modal({ className, modalref, children, title, subtitle, footer, hasOverlay = true, hasCloseButton = true, handleClose, ...rest }) {
|
|
362
295
|
return (jsxs(Fragment, { children: [hasOverlay && jsx("div", { className: "modal-overlay" }), jsxs("div", { ref: modalref, className: clsx("modal", className), ...rest, 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 })] })] })] }));
|
|
363
296
|
}
|
|
364
297
|
|
|
365
|
-
|
|
366
|
-
|
|
298
|
+
const ThemeContext = createContext(undefined);
|
|
299
|
+
function ThemeProvider({ children, dataTheme: dataThemeProp, dataPalette: dataPaletteProp = "water", }) {
|
|
300
|
+
const [dataTheme, setDataTheme] = useState();
|
|
301
|
+
const [dataPalette, setDataPalette] = useState();
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
if (dataPaletteProp) {
|
|
304
|
+
switchDataPalette(dataPaletteProp);
|
|
305
|
+
}
|
|
306
|
+
}, [dataPaletteProp]);
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
if (dataThemeProp) {
|
|
309
|
+
switchDataTheme(dataThemeProp);
|
|
310
|
+
}
|
|
311
|
+
}, [dataThemeProp]);
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
if (window.matchMedia) {
|
|
314
|
+
if (localStorage.getItem("data-theme")) {
|
|
315
|
+
document.documentElement.setAttribute("data-theme", localStorage.getItem("data-theme"));
|
|
316
|
+
setDataTheme(localStorage.getItem("data-theme"));
|
|
317
|
+
}
|
|
318
|
+
else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
319
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
320
|
+
setDataTheme("dark");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}, []);
|
|
324
|
+
const switchDataTheme = (mode) => {
|
|
325
|
+
document.documentElement.setAttribute("data-theme", mode);
|
|
326
|
+
setDataTheme(mode);
|
|
327
|
+
localStorage.setItem("data-theme", mode);
|
|
328
|
+
};
|
|
329
|
+
const switchDataPalette = (mode) => {
|
|
330
|
+
document.documentElement.setAttribute("data-palette", mode);
|
|
331
|
+
setDataPalette(mode);
|
|
332
|
+
localStorage.setItem("palette-theme", mode);
|
|
333
|
+
};
|
|
334
|
+
return (jsx(ThemeContext.Provider, { value: { dataTheme, switchDataTheme, dataPalette, switchDataPalette }, children: children }));
|
|
367
335
|
}
|
|
336
|
+
function useTheme() {
|
|
337
|
+
const context = useContext(ThemeContext);
|
|
338
|
+
if (context === undefined) {
|
|
339
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
340
|
+
}
|
|
341
|
+
return context;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function MapControl({ children, position = "top-right", ...rest }) {
|
|
345
|
+
return (jsx("div", { className: `control control--${position}`, ...rest, children: children }));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function MapToc({ items, selected, setSelected }) {
|
|
349
|
+
return (jsx(Menu.Root, { children: Object.entries(items).map(([parentId, parent], index) => (jsxs(Menu.Item, { children: [jsx(Menu.Button, { dropdown: true, children: parent.title }), jsx(Menu.Content, { children: Object.entries(parent.children).map(([childId, child], index) => (jsx(Menu.Item, { children: jsx(Menu.Button, { isSelected: childId === selected.id, nested: true, handleCallbackClick: () => setSelected({ id: childId, ...child }), children: child.label }) }))) })] }, `first-level-${index}`))) }));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Context */
|
|
353
|
+
const MapContext = createContext(undefined);
|
|
354
|
+
function MapProvider({ children }) {
|
|
355
|
+
const [currentLayer, setCurrentLayer] = useState(undefined);
|
|
356
|
+
return (jsx(MapContext.Provider, { value: { state: { currentLayer }, setCurrentLayer }, children: children }));
|
|
357
|
+
}
|
|
358
|
+
function useMap({ defaultLayer }) {
|
|
359
|
+
const context = useContext(MapContext);
|
|
360
|
+
useEffect(() => {
|
|
361
|
+
if (context) {
|
|
362
|
+
context.setCurrentLayer(defaultLayer);
|
|
363
|
+
}
|
|
364
|
+
}, []);
|
|
365
|
+
if (context === undefined) {
|
|
366
|
+
throw new Error("useMap must be used within a MapProvider");
|
|
367
|
+
}
|
|
368
|
+
return context;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const DefaultPopup = ({ popup }) => {
|
|
372
|
+
const { isDefault, data, render } = popup.model;
|
|
373
|
+
return isDefault || true ? (jsxs("div", { className: "map__popup-content", children: [jsx("div", { className: "map__popup-list", children: data.fields.map((field) => (jsxs("h5", { children: [field, ":"] }))) }), jsx("div", { className: "map__popup-list", children: data.values.map((value) => (jsx("span", { children: typeof value === "string"
|
|
374
|
+
? new Function("v", `return (${value})(${JSON.stringify(popup.info)})`)()
|
|
375
|
+
: value(popup.info) }))) })] })) : (render);
|
|
376
|
+
};
|
|
377
|
+
const MapPopup = ({ popup, framework = "deck.gl", setPopupData, longitude, latitude, }) => {
|
|
378
|
+
return framework === "deck.gl" ? (jsx("div", { className: "map__popup", style: { left: longitude, top: latitude }, children: jsx(DefaultPopup, { popup: popup }) })) : (jsx(Popup, { anchor: "top", longitude: Number(longitude), latitude: Number(latitude), onClose: () => setPopupData && setPopupData(undefined), children: jsx(DefaultPopup, { popup: popup }) }));
|
|
379
|
+
};
|
|
368
380
|
|
|
369
|
-
// import MapboxMap from "./MapboxMap";
|
|
370
381
|
const INITIAL_VIEW_STATE = {
|
|
371
382
|
longitude: -122.41669,
|
|
372
383
|
latitude: 37.7853,
|
|
@@ -374,21 +385,97 @@ const INITIAL_VIEW_STATE = {
|
|
|
374
385
|
pitch: 0,
|
|
375
386
|
bearing: 0,
|
|
376
387
|
};
|
|
377
|
-
function
|
|
378
|
-
|
|
388
|
+
function MapDeckgl({ attribution, basemap, basemapToken, initialViewState, hasSwitchBasemap = true, layers, mapProps, renderControls = {}, toc, }) {
|
|
389
|
+
// @ts-ignore
|
|
390
|
+
const { onClick, ...restMapProps } = mapProps;
|
|
379
391
|
const theme = useTheme();
|
|
380
|
-
const
|
|
381
|
-
useState(
|
|
392
|
+
const [lngLat, setLngLat] = useState();
|
|
393
|
+
const [popupData, setPopupData] = useState();
|
|
394
|
+
const _layers = layers &&
|
|
395
|
+
useMemo(() => layers.map(({ type, layer }) => new Layers[type](layer)), []);
|
|
396
|
+
const { "bottom-left": bottomLeft, "center-left": centerLeft, ..._controls } = renderControls;
|
|
397
|
+
const mapContext = toc &&
|
|
398
|
+
useMap({
|
|
399
|
+
defaultLayer: {
|
|
400
|
+
id: toc.defaultIds[1],
|
|
401
|
+
...toc?.parents[toc.defaultIds[0]].children[toc.defaultIds[1]],
|
|
402
|
+
},
|
|
403
|
+
});
|
|
382
404
|
const handleToggle = () => {
|
|
383
405
|
theme.switchDataTheme(theme.dataTheme === "dark" ? "light" : "dark");
|
|
384
406
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
407
|
+
const handeSelectedLayer = (layer) => {
|
|
408
|
+
mapContext.setCurrentLayer(layer);
|
|
409
|
+
};
|
|
410
|
+
const handleClick = (event) => {
|
|
411
|
+
if (event.object) {
|
|
412
|
+
if (event.layer?.props?.popup) {
|
|
413
|
+
setPopupData({ model: event.layer?.props.popup, info: event.object });
|
|
414
|
+
}
|
|
415
|
+
setLngLat([event.pixel[0], event.pixel[1]]);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
setLngLat(undefined);
|
|
419
|
+
}
|
|
420
|
+
if (onClick) {
|
|
421
|
+
onClick(event);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
return (jsxs("div", { className: "map", children: [jsxs(DeckGL, { initialViewState: initialViewState || INITIAL_VIEW_STATE, controller: true, layers: _layers, onClick: handleClick, ...restMapProps, children: [jsx(Map, { attributionControl: false, mapLib: maplibregl, mapStyle: basemap || theme.dataTheme === "dark"
|
|
425
|
+
? `https://api.maptiler.com/maps/darkmatter/style.json?key=${basemapToken || process.env.STORYBOOK_OPEN_TILES_TOKEN}`
|
|
426
|
+
: `https://api.maptiler.com/maps/positron/style.json?key=${basemapToken || process.env.STORYBOOK_OPEN_TILES_TOKEN}` }), Object.keys(_controls).map((key) => {
|
|
427
|
+
// @ts-ignore
|
|
428
|
+
return jsx(MapControl, { position: key, children: _controls[key] });
|
|
429
|
+
}), jsxs(MapControl, { position: "center-left", children: [centerLeft, mapContext?.state.currentLayer && (jsx(MapToc, { items: toc.parents, selected: mapContext.state.currentLayer, setSelected: handeSelectedLayer }))] }), jsx(MapControl, { position: "bottom-left", children: hasSwitchBasemap ? (jsxs(Fragment, { children: [bottomLeft, jsx(Button, { mode: "icon", size: "small", onClick: handleToggle, children: theme.dataTheme === "dark" ? (jsx(FiSun, { size: "1.25rem" })) : (jsx(FiMoon, { size: "1.25rem", color: "var(--color-black)" })) })] })) : (bottomLeft) }), jsx("div", { className: "map__attribution", children: attribution || (jsxs(Fragment, { children: [jsx(Button, { as: "link", href: "https://www.maptiler.com/copyright/", target: "_blank", children: "\u00A9 MapTiler" }), jsx(Button, { as: "link", href: "https://www.openstreetmap.org/copyright", target: "_blank", children: "\u00A9 OpenStreetMap contributors" })] })) })] }), popupData && lngLat && (jsx(MapPopup, { longitude: lngLat[0], latitude: lngLat[1],
|
|
430
|
+
// framework="deck.gl"
|
|
431
|
+
popup: popupData }))] }));
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function MapMapbox({ basemap, mapProps, hasSwitchBasemap, hasSwitchProjection, renderControls, sources, toc, }) {
|
|
435
|
+
// @ts-ignore
|
|
436
|
+
const { onClick, ...restMapProps } = mapProps;
|
|
437
|
+
const { dataTheme, switchDataTheme } = useTheme();
|
|
438
|
+
const [projection, setProjection] = useState("globe");
|
|
439
|
+
const { "bottom-left": bottomLeft, "center-left": centerLeft, ..._controls } = renderControls;
|
|
440
|
+
const [popupData, setPopupData] = useState();
|
|
441
|
+
const [lngLat, setLngLat] = useState();
|
|
442
|
+
const mapContext = toc &&
|
|
443
|
+
useMap({
|
|
444
|
+
defaultLayer: {
|
|
445
|
+
id: toc.defaultIds[1],
|
|
446
|
+
...toc?.parents[toc.defaultIds[0]].children[toc.defaultIds[1]],
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
const handeSelectedLayer = (layer) => {
|
|
450
|
+
mapContext.setCurrentLayer(layer);
|
|
451
|
+
};
|
|
452
|
+
const handleClick = (event) => {
|
|
453
|
+
const { features, point: { x, y }, lngLat: { lng, lat }, } = event;
|
|
454
|
+
const hoveredFeature = features && features[0];
|
|
455
|
+
if (hoveredFeature) {
|
|
456
|
+
setPopupData({
|
|
457
|
+
model: hoveredFeature.layer.metadata["mapbox:popup"],
|
|
458
|
+
info: hoveredFeature,
|
|
459
|
+
});
|
|
460
|
+
setLngLat([lng, lat]);
|
|
461
|
+
}
|
|
462
|
+
if (onClick) {
|
|
463
|
+
onClick(event);
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
return mapProps?.mapboxAccessToken ? (jsx(Fragment, { children: jsxs(Map, { mapboxAccessToken: mapProps.mapboxAccessToken, projection: projection, mapStyle: basemap ||
|
|
467
|
+
`mapbox://styles/mapbox/${dataTheme === "dark" ? "light" : "dark"}-v11`, ...((mapProps.interactiveLayerIds && { onClick: handleClick }) ||
|
|
468
|
+
(onClick && { onClick })), ...restMapProps, children: [sources &&
|
|
469
|
+
sources.map(({ id, layers, ...restSource }) => (
|
|
470
|
+
// @ts-ignore
|
|
471
|
+
jsx(Source, { id: id, ...restSource, children: layers && layers.map((layer) => jsx(Layer, { ...layer })) }))), Object.keys(_controls).map((key) => {
|
|
472
|
+
// @ts-ignore
|
|
388
473
|
return jsx(MapControl, { position: key, children: _controls[key] });
|
|
389
|
-
}),
|
|
390
|
-
|
|
391
|
-
|
|
474
|
+
}), jsxs(MapControl, { position: "center-left", children: [centerLeft, mapContext?.state.currentLayer && (jsx(MapToc, { items: toc.parents, selected: mapContext.state.currentLayer, setSelected: handeSelectedLayer }))] }), jsxs(MapControl, { position: "bottom-left", children: [bottomLeft, hasSwitchBasemap && (jsx(Button, { className: "map__button", mode: "icon", onClick: () => switchDataTheme(dataTheme === "dark" ? "light" : "dark"), children: dataTheme === "dark" ? jsx(BsFillMoonFill, {}) : jsx(BsFillSunFill, {}) })), hasSwitchProjection && (jsx(Button, { className: "map__button", mode: "icon", onClick: () => setProjection((prev) => prev === "globe" ? "mercator" : "globe"), children: projection === "globe" ? "2D" : "3D" }))] }), popupData && lngLat && (jsx(MapPopup, { longitude: lngLat[0], latitude: lngLat[1], framework: "mapboxgl", setPopupData: setPopupData, popup: popupData }))] }) })) : (jsx(Modal, { hasCloseButton: false, children: jsx("p", { className: "map__mapbox-error", children: "You need to add the mapbox token to the prop mapboxAccessToken." }) }));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function MapComponent({ attribution, basemap, basemapToken, framework = "deck.gl", mapProps, hasSwitchBasemap = true, hasSwitchProjection = true, layers, renderControls = {}, sources, toc, }) {
|
|
478
|
+
return framework === "deck.gl" ? (jsx(MapDeckgl, { attribution: attribution, basemap: basemap, basemapToken: basemapToken, hasSwitchBasemap: hasSwitchBasemap, layers: layers, mapProps: mapProps, renderControls: renderControls, toc: toc })) : framework === "mapboxgl" ? (jsx(MapMapbox, { basemap: basemap, hasSwitchBasemap: hasSwitchBasemap, hasSwitchProjection: hasSwitchProjection, mapProps: mapProps, renderControls: renderControls, sources: sources, toc: toc })) : (jsx("div", { children: "The component needs a framework" }));
|
|
392
479
|
}
|
|
393
480
|
|
|
394
481
|
const LoadingContext = createContext(undefined);
|
|
@@ -522,5 +609,5 @@ function useModal({} = {}) {
|
|
|
522
609
|
return context;
|
|
523
610
|
}
|
|
524
611
|
|
|
525
|
-
export {
|
|
612
|
+
export { Button, Form, FormInput, FormSelect, FormTextArea, Input, Loading, LoadingContext, LoadingProvider, MapComponent, MapControl, MapProvider, index as Menu, Modal, ModalContext, ModalProvider, Select, TextArea, ThemeContext, ThemeProvider, useLoading, useMap, useModal, useTheme };
|
|
526
613
|
//# sourceMappingURL=index.js.map
|