@soul-refiner/design-system 0.1.22 → 0.1.23
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/package.json +1 -1
- package/src/components/navigation/breadcrumb/breadcrumb.tsx +1 -1
- package/src/components/surfaces/accordion/accordion.tsx +88 -0
- package/src/components/surfaces/accordion/index.ts +2 -0
- package/src/components/surfaces/index.ts +2 -0
- package/src/components/surfaces/modal/modal.tsx +1 -5
- package/src/utils/function.ts +4 -0
- package/src/utils/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { Box } from 'components';
|
|
4
|
+
import { callAll } from 'utils';
|
|
5
|
+
import { ChevronDown, ChevronUp } from 'icons';
|
|
6
|
+
|
|
7
|
+
export interface AccordionProps extends React.PropsWithChildren {
|
|
8
|
+
sx?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ModalContext = React.createContext<[number, (index: number) => void]>([
|
|
12
|
+
-1,
|
|
13
|
+
() => undefined,
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const Accordion = ({ children, sx }: AccordionProps) => {
|
|
17
|
+
const [openIndex, setOpenIndex] = React.useState(-1);
|
|
18
|
+
|
|
19
|
+
const handleIndexChange = (index: number) => {
|
|
20
|
+
setOpenIndex((prev) => (prev === index ? -1 : index));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ModalContext.Provider value={[openIndex, handleIndexChange]}>
|
|
25
|
+
<Wrapper $sx={sx}>
|
|
26
|
+
{React.Children.map(children, (child, index) => {
|
|
27
|
+
if (React.isValidElement(child))
|
|
28
|
+
return React.cloneElement(child, { index } as any);
|
|
29
|
+
return null;
|
|
30
|
+
})}
|
|
31
|
+
</Wrapper>
|
|
32
|
+
</ModalContext.Provider>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const Wrapper = styled.div<{ $sx?: string }>`
|
|
37
|
+
${({ $sx }) => ($sx ? $sx : '')};
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
export interface AccordionItemProps extends React.PropsWithChildren {
|
|
41
|
+
index?: number;
|
|
42
|
+
sx?: string;
|
|
43
|
+
trigger: React.ReactNode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const AccordionItem = ({
|
|
47
|
+
children,
|
|
48
|
+
index,
|
|
49
|
+
sx,
|
|
50
|
+
trigger,
|
|
51
|
+
}: AccordionItemProps) => {
|
|
52
|
+
const [openIndex, setOpenIndex] = React.useContext(ModalContext);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Box $dir="column">
|
|
56
|
+
<TriggerWrapper
|
|
57
|
+
onClick={callAll(
|
|
58
|
+
// eslint-disable-next-line
|
|
59
|
+
() => setOpenIndex(index!),
|
|
60
|
+
(trigger as React.ReactElement)?.props?.onClick
|
|
61
|
+
)}
|
|
62
|
+
>
|
|
63
|
+
{trigger}
|
|
64
|
+
{openIndex === index ? <ChevronUp /> : <ChevronDown />}
|
|
65
|
+
</TriggerWrapper>
|
|
66
|
+
<Box sx={openIndex === index ? sx : 'visibility: hidden; height: 0px;'}>
|
|
67
|
+
{children}
|
|
68
|
+
</Box>
|
|
69
|
+
</Box>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const TriggerWrapper = styled.button`
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: space-between;
|
|
77
|
+
padding: 16px;
|
|
78
|
+
appearance: none;
|
|
79
|
+
border: none;
|
|
80
|
+
outline: none;
|
|
81
|
+
background-color: transparent;
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
Accordion.Item = AccordionItem;
|
|
86
|
+
AccordionItem.displayName = 'Accordion.Item';
|
|
87
|
+
|
|
88
|
+
export { Accordion };
|
|
@@ -2,11 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import { Button } from 'components';
|
|
4
4
|
import { Close } from 'icons';
|
|
5
|
-
|
|
6
|
-
const callAll =
|
|
7
|
-
(...fns: ((...args: unknown[]) => unknown)[]) =>
|
|
8
|
-
(...args: any) =>
|
|
9
|
-
fns.forEach((fn) => fn && fn(...args));
|
|
5
|
+
import { callAll } from 'utils';
|
|
10
6
|
|
|
11
7
|
const ModalContext = React.createContext<
|
|
12
8
|
[boolean, React.Dispatch<React.SetStateAction<boolean>>]
|
package/src/utils/index.ts
CHANGED