@factorearth/component-library 4.3.7-alpha.0 → 4.4.0-alpha.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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Colors } from "Theme/types";
|
|
3
|
+
interface OptionsDropdownProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
4
|
+
colorPalette: Colors;
|
|
5
|
+
optionsObj: Record<string, Category>;
|
|
6
|
+
}
|
|
7
|
+
type Option = {
|
|
8
|
+
name: string;
|
|
9
|
+
onClick: () => void;
|
|
10
|
+
icon?: React.JSX.Element;
|
|
11
|
+
};
|
|
12
|
+
type Category = {
|
|
13
|
+
icon?: React.JSX.Element;
|
|
14
|
+
options: Option[];
|
|
15
|
+
};
|
|
16
|
+
export declare const OptionsDropdown: (props: OptionsDropdownProps) => React.JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect } from "react";
|
|
2
|
+
import styled from "@emotion/styled";
|
|
3
|
+
import { Typography } from "../Typography/Typography";
|
|
4
|
+
const OptionsDropdownDiv = styled.div `
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: flex-start;
|
|
7
|
+
width: fit-content;
|
|
8
|
+
border-radius: 4px;
|
|
9
|
+
border: ${({ colorPalette }) => colorPalette.text.tertiary} 1px solid;
|
|
10
|
+
`;
|
|
11
|
+
const CategoryDiv = styled.div `
|
|
12
|
+
padding: 8px;
|
|
13
|
+
border-left: ${({ colorPalette }) => colorPalette.text.tertiary} 1px solid;
|
|
14
|
+
background: ${({ expanded, colorPalette }) => expanded ? colorPalette.text.tertiary : "none"};
|
|
15
|
+
color: ${({ expanded, colorPalette }) => expanded ? colorPalette.background.primary : colorPalette.text.tertiary};
|
|
16
|
+
position: relative;
|
|
17
|
+
|
|
18
|
+
&:first-child {
|
|
19
|
+
border-left: none;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
const CategoryTitle = styled.div `
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
align-items: flex-start;
|
|
25
|
+
gap: 8px;
|
|
26
|
+
|
|
27
|
+
`;
|
|
28
|
+
const OptionsDiv = styled.div `
|
|
29
|
+
border-top: ${({ colorPalette }) => colorPalette.background.primary} 1px solid;
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
position: absolute;
|
|
33
|
+
left: 0;
|
|
34
|
+
top: calc(100% + 1px);
|
|
35
|
+
background: ${({ colorPalette }) => colorPalette.text.tertiary};
|
|
36
|
+
border-radius: 0 0 4px 4px;
|
|
37
|
+
padding: 8px;
|
|
38
|
+
`;
|
|
39
|
+
const OptionDiv = styled.div `
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: flex-start;
|
|
42
|
+
align-self: stretch;
|
|
43
|
+
gap: 8px;
|
|
44
|
+
padding: 8px;
|
|
45
|
+
width: max-content;
|
|
46
|
+
`;
|
|
47
|
+
export const OptionsDropdown = (props) => {
|
|
48
|
+
const { colorPalette, optionsObj, ...inputProps } = props;
|
|
49
|
+
const [open, setOpen] = useState(null);
|
|
50
|
+
const [categories, setCategories] = useState();
|
|
51
|
+
const ref = useRef(null);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
56
|
+
};
|
|
57
|
+
}, []);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
setCategories(Object.keys(optionsObj));
|
|
60
|
+
}, []);
|
|
61
|
+
const handleClickOutside = (event) => {
|
|
62
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
63
|
+
setOpen(null);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const toggleOpen = (location) => {
|
|
67
|
+
if (open === location) {
|
|
68
|
+
setOpen(null);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
setOpen(location);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return (React.createElement(OptionsDropdownDiv, { colorPalette: colorPalette, ref: ref }, categories?.map(cat => {
|
|
75
|
+
return (React.createElement(CategoryDiv, { colorPalette: colorPalette, expanded: open === cat },
|
|
76
|
+
React.createElement(CategoryTitle, { colorPalette: colorPalette, onClick: () => { toggleOpen(cat); } },
|
|
77
|
+
optionsObj[cat]?.icon,
|
|
78
|
+
React.createElement(Typography, { textColor: open === cat ? colorPalette.background.primary : colorPalette.text.tertiary, content: cat, variant: "Small" })),
|
|
79
|
+
open === cat && React.createElement(OptionsDiv, { colorPalette: colorPalette }, optionsObj[cat].options.map(op => React.createElement(OptionDiv, { colorPalette: colorPalette, onClick: op.onClick },
|
|
80
|
+
op?.icon,
|
|
81
|
+
React.createElement(Typography, { textColor: open === cat ? colorPalette.background.primary : colorPalette.text.tertiary, content: op.name, variant: "Small" }))))));
|
|
82
|
+
})));
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=OptionsDropdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionsDropdown.js","sourceRoot":"","sources":["../../../lib/Atoms/OptionsDropdown/OptionsDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAA2B;;;;;YAKpD,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ;CAC3D,CAAC;AAGF,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAA4C;;iBAEzD,CAAC,EAAE,YAAY,EAAE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AE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAI,CACtH;YACjB,IAAI,KAAK,GAAG,IAAI,oBAAC,UAAU,IAAC,YAAY,EAAE,YAAY,IACpD,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAChC,oBAAC,SAAS,IAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO;gBAAG,EAAE,EAAE,IAAI;gBACrE,oBAAC,UAAU,IAAC,SAAS,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAI,CAC9H,CACb,CACU,CACD,CACf,CAAA;IACH,CAAC,CACA,CACkB,CACtB,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorearth/component-library",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-alpha.0",
|
|
4
4
|
"description": " A storybook component library for FactorEarth",
|
|
5
5
|
"author": "madtrx <marlin.makori@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/FactorEarth/RecordMiddleware#readme",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public",
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c9ca193859a44e0b29388ae65b08d8c11b56e83d",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@emotion/react": "^11.13.0",
|
|
52
52
|
"@emotion/styled": "^11.13.0",
|