@soul-refiner/design-system 0.1.23 → 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.23",
3
+ "version": "0.1.24",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -8,10 +8,9 @@ export interface AccordionProps extends React.PropsWithChildren {
8
8
  sx?: string;
9
9
  }
10
10
 
11
- const ModalContext = React.createContext<[number, (index: number) => void]>([
12
- -1,
13
- () => undefined,
14
- ]);
11
+ const AccordionContext = React.createContext<[number, (index: number) => void]>(
12
+ [-1, () => undefined]
13
+ );
15
14
 
16
15
  const Accordion = ({ children, sx }: AccordionProps) => {
17
16
  const [openIndex, setOpenIndex] = React.useState(-1);
@@ -21,7 +20,7 @@ const Accordion = ({ children, sx }: AccordionProps) => {
21
20
  };
22
21
 
23
22
  return (
24
- <ModalContext.Provider value={[openIndex, handleIndexChange]}>
23
+ <AccordionContext.Provider value={[openIndex, handleIndexChange]}>
25
24
  <Wrapper $sx={sx}>
26
25
  {React.Children.map(children, (child, index) => {
27
26
  if (React.isValidElement(child))
@@ -29,7 +28,7 @@ const Accordion = ({ children, sx }: AccordionProps) => {
29
28
  return null;
30
29
  })}
31
30
  </Wrapper>
32
- </ModalContext.Provider>
31
+ </AccordionContext.Provider>
33
32
  );
34
33
  };
35
34
 
@@ -49,7 +48,7 @@ const AccordionItem = ({
49
48
  sx,
50
49
  trigger,
51
50
  }: AccordionItemProps) => {
52
- const [openIndex, setOpenIndex] = React.useContext(ModalContext);
51
+ const [openIndex, setOpenIndex] = React.useContext(AccordionContext);
53
52
 
54
53
  return (
55
54
  <Box $dir="column">
@@ -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';
@@ -2,6 +2,8 @@ export { Accordion } from './accordion';
2
2
  export type { AccordionProps, AccordionItemProps } from './accordion';
3
3
  export { Comment } from './comment';
4
4
  export type { CommentProps } from './comment';
5
+ export { Drawer } from './drawer';
6
+ export type { DrawerProps } from './drawer';
5
7
  export { Message } from './message';
6
8
  export type { MessageProps } from './message';
7
9
  export { Modal } from './modal';