@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -61,7 +61,7 @@ export interface BreadcrumbItemProps extends React.PropsWithChildren {
61
61
  onClick?: React.MouseEventHandler;
62
62
  }
63
63
 
64
- export const BreadcrumbItem = ({
64
+ const BreadcrumbItem = ({
65
65
  avatar,
66
66
  children,
67
67
  href,
@@ -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 };
@@ -0,0 +1,2 @@
1
+ export { Accordion } from './accordion';
2
+ export type { AccordionProps, AccordionItemProps } from './accordion';
@@ -1,3 +1,5 @@
1
+ export { Accordion } from './accordion';
2
+ export type { AccordionProps, AccordionItemProps } from './accordion';
1
3
  export { Comment } from './comment';
2
4
  export type { CommentProps } from './comment';
3
5
  export { Message } from './message';
@@ -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>>]
@@ -0,0 +1,4 @@
1
+ export const callAll =
2
+ (...fns: ((...args: unknown[]) => unknown)[]) =>
3
+ (...args: any) =>
4
+ fns.forEach((fn) => fn && fn(...args));
@@ -11,3 +11,4 @@ export {
11
11
  isSameMonth,
12
12
  zeroPad,
13
13
  } from './date';
14
+ export { callAll } from './function';