@soul-refiner/design-system 0.1.22 → 0.1.24

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.24",
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,87 @@
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 AccordionContext = React.createContext<[number, (index: number) => void]>(
12
+ [-1, () => undefined]
13
+ );
14
+
15
+ const Accordion = ({ children, sx }: AccordionProps) => {
16
+ const [openIndex, setOpenIndex] = React.useState(-1);
17
+
18
+ const handleIndexChange = (index: number) => {
19
+ setOpenIndex((prev) => (prev === index ? -1 : index));
20
+ };
21
+
22
+ return (
23
+ <AccordionContext.Provider value={[openIndex, handleIndexChange]}>
24
+ <Wrapper $sx={sx}>
25
+ {React.Children.map(children, (child, index) => {
26
+ if (React.isValidElement(child))
27
+ return React.cloneElement(child, { index } as any);
28
+ return null;
29
+ })}
30
+ </Wrapper>
31
+ </AccordionContext.Provider>
32
+ );
33
+ };
34
+
35
+ const Wrapper = styled.div<{ $sx?: string }>`
36
+ ${({ $sx }) => ($sx ? $sx : '')};
37
+ `;
38
+
39
+ export interface AccordionItemProps extends React.PropsWithChildren {
40
+ index?: number;
41
+ sx?: string;
42
+ trigger: React.ReactNode;
43
+ }
44
+
45
+ const AccordionItem = ({
46
+ children,
47
+ index,
48
+ sx,
49
+ trigger,
50
+ }: AccordionItemProps) => {
51
+ const [openIndex, setOpenIndex] = React.useContext(AccordionContext);
52
+
53
+ return (
54
+ <Box $dir="column">
55
+ <TriggerWrapper
56
+ onClick={callAll(
57
+ // eslint-disable-next-line
58
+ () => setOpenIndex(index!),
59
+ (trigger as React.ReactElement)?.props?.onClick
60
+ )}
61
+ >
62
+ {trigger}
63
+ {openIndex === index ? <ChevronUp /> : <ChevronDown />}
64
+ </TriggerWrapper>
65
+ <Box sx={openIndex === index ? sx : 'visibility: hidden; height: 0px;'}>
66
+ {children}
67
+ </Box>
68
+ </Box>
69
+ );
70
+ };
71
+
72
+ const TriggerWrapper = styled.button`
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: space-between;
76
+ padding: 16px;
77
+ appearance: none;
78
+ border: none;
79
+ outline: none;
80
+ background-color: transparent;
81
+ cursor: pointer;
82
+ `;
83
+
84
+ Accordion.Item = AccordionItem;
85
+ AccordionItem.displayName = 'Accordion.Item';
86
+
87
+ export { Accordion };
@@ -0,0 +1,2 @@
1
+ export { Accordion } from './accordion';
2
+ export type { AccordionProps, AccordionItemProps } from './accordion';
@@ -0,0 +1,180 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { callAll } from 'utils';
4
+
5
+ const DrawerContext = React.createContext<
6
+ [boolean, React.Dispatch<React.SetStateAction<boolean>>]
7
+ >([false, (() => undefined) as React.Dispatch<React.SetStateAction<boolean>>]);
8
+
9
+ export interface DrawerProps extends React.PropsWithChildren {
10
+ /**
11
+ * This is to make the Modal a controlled component,
12
+ * instead of it managing its own state
13
+ */
14
+ controlledOpen?: boolean;
15
+ onOpenChange?: () => void;
16
+ }
17
+
18
+ export const Drawer = ({
19
+ children,
20
+ controlledOpen,
21
+ onOpenChange,
22
+ }: DrawerProps) => {
23
+ const [open, setOpen] = React.useState(controlledOpen || false);
24
+
25
+ React.useEffect(() => {
26
+ if (controlledOpen !== undefined) {
27
+ setOpen(controlledOpen);
28
+ }
29
+ }, [controlledOpen]);
30
+
31
+ const _children = React.Children.toArray(children);
32
+ const triggers: React.ReactNode[] = [];
33
+ const content: React.ReactNode[] = [];
34
+ let footer: React.ReactNode = null;
35
+ let header: React.ReactNode = null;
36
+
37
+ for (const child of _children) {
38
+ if (React.isValidElement(child)) {
39
+ const type = (child.type as any)?.displayName;
40
+
41
+ if (type === 'Drawer.Trigger') triggers.push(child);
42
+ else if (type === 'Drawer.Header') header = child;
43
+ else if (type === 'Drawer.Footer') footer = child;
44
+ else content.push(child);
45
+ }
46
+ }
47
+
48
+ return (
49
+ <DrawerContext.Provider value={[open, setOpen]}>
50
+ {triggers}
51
+ {open && (
52
+ <Background
53
+ onClick={callAll(
54
+ () => setOpen(false),
55
+ () => onOpenChange && onOpenChange()
56
+ )}
57
+ />
58
+ )}
59
+ <Component $open={open}>
60
+ {header && <HeaderWrapper>{header}</HeaderWrapper>}
61
+ <ContentWrapper>{content}</ContentWrapper>
62
+ {footer && <FooterWrapper>{footer}</FooterWrapper>}
63
+ </Component>
64
+ </DrawerContext.Provider>
65
+ );
66
+ };
67
+
68
+ const Background = styled.div`
69
+ position: fixed;
70
+ height: 100vh;
71
+ width: 100vw;
72
+ top: 0;
73
+ left: 0;
74
+ right: 0;
75
+ z-index: 149;
76
+ overflow: hidden;
77
+ background: #000000;
78
+ opacity: 0.5;
79
+ cursor: pointer;
80
+ `;
81
+
82
+ const Component = styled.div<{
83
+ $open: boolean;
84
+ }>`
85
+ position: fixed;
86
+ top: 0;
87
+ right: 0;
88
+ height: 100vh;
89
+ max-width: 880px;
90
+ width: 100%;
91
+ z-index: 150;
92
+ border-radius: 16px 0px 0px 16px;
93
+ background-color: var(--background-color);
94
+ margin-right: -100vw;
95
+ transition: margin-right 0.5s;
96
+ background-color: var(--color-grey-10);
97
+
98
+ ${({ $open }) => ($open ? 'margin-right: 0px;' : '')}
99
+ `;
100
+
101
+ const HeaderWrapper = styled.div`
102
+ background-color: var(--color-white);
103
+ box-shadow: var(--elevation-2);
104
+ position: -webkit-sticky; /* Safari */
105
+ position: sticky;
106
+ top: 0;
107
+ `;
108
+
109
+ const ContentWrapper = styled.div`
110
+ height: calc(100vh - 224px);
111
+ position: relative;
112
+ display: flex;
113
+ flex-flow: column nowrap;
114
+ padding: 24px 16px 24px 24px;
115
+ margin-right: 8px;
116
+ overflow-y: auto;
117
+
118
+ &::-webkit-scrollbar-track {
119
+ box-shadow: inset 0 4px 4px rgba(0, 0, 0, 0.15);
120
+ -webkit-box-shadow: inset 0 4px 4px rgba(0, 0, 0, 0.15);
121
+ border-radius: 4px;
122
+ background-color: var(--color-white);
123
+ margin: 40px 0px 15px 0px;
124
+ }
125
+ &::-webkit-scrollbar {
126
+ width: 8px;
127
+ border-radius: 4px;
128
+ }
129
+ &::-webkit-scrollbar-thumb {
130
+ border-radius: 4px;
131
+ background-color: var(--color-grey-6);
132
+ opacity: 30%;
133
+ }
134
+ `;
135
+
136
+ const FooterWrapper = styled.div`
137
+ background-color: var(--color-white);
138
+ box-shadow: var(--elevation-1);
139
+ position: -webkit-sticky; /* Safari */
140
+ position: sticky;
141
+ bottom: 0;
142
+ `;
143
+
144
+ const DrawerTrigger = ({
145
+ children: child,
146
+ }: {
147
+ children: React.ReactElement;
148
+ }) => {
149
+ const [, setOpen] = React.useContext(DrawerContext);
150
+ return (
151
+ child &&
152
+ React.cloneElement(child, {
153
+ onClick: callAll(() => setOpen((prev) => !prev), child.props.onClick),
154
+ })
155
+ );
156
+ };
157
+
158
+ DrawerTrigger.displayName = 'Drawer.Trigger';
159
+ Drawer.Trigger = DrawerTrigger;
160
+
161
+ const DrawerHeader = ({ children }: React.PropsWithChildren) => (
162
+ <div>{children}</div>
163
+ );
164
+
165
+ DrawerHeader.displayName = 'Drawer.Header';
166
+ Drawer.Header = DrawerHeader;
167
+
168
+ const DrawerContent = ({ children }: React.PropsWithChildren) => (
169
+ <div>{children}</div>
170
+ );
171
+
172
+ DrawerContent.displayName = 'Drawer.Content';
173
+ Drawer.Content = DrawerContent;
174
+
175
+ const DrawerFooter = ({ children }: React.PropsWithChildren) => (
176
+ <div>{children}</div>
177
+ );
178
+
179
+ DrawerFooter.displayName = 'Drawer.Footer';
180
+ Drawer.Footer = DrawerFooter;
@@ -0,0 +1,2 @@
1
+ export { Drawer } from './drawer';
2
+ export type { DrawerProps } from './drawer';
@@ -1,5 +1,9 @@
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';
5
+ export { Drawer } from './drawer';
6
+ export type { DrawerProps } from './drawer';
3
7
  export { Message } from './message';
4
8
  export type { MessageProps } from './message';
5
9
  export { Modal } from './modal';
@@ -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';