react-miui 0.7.0 → 0.9.2

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.
Files changed (238) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/components/form/choice/Choice.d.ts +11 -0
  3. package/dist/components/form/choice/Choice.d.ts.map +1 -0
  4. package/dist/components/form/choice/Choice.js +19 -0
  5. package/dist/components/form/choice/Choice.js.map +1 -0
  6. package/dist/components/form/choice/Choice.module.scss +43 -0
  7. package/dist/components/form/choice/ChoiceItem.d.ts +11 -0
  8. package/dist/components/form/choice/ChoiceItem.d.ts.map +1 -0
  9. package/dist/components/form/choice/ChoiceItem.js +33 -0
  10. package/dist/components/form/choice/ChoiceItem.js.map +1 -0
  11. package/dist/components/layout/list/Header.d.ts +6 -1
  12. package/dist/components/layout/list/Header.d.ts.map +1 -1
  13. package/dist/components/layout/list/Header.js +6 -1
  14. package/dist/components/layout/list/Header.js.map +1 -1
  15. package/dist/components/layout/list/Item.d.ts +3 -0
  16. package/dist/components/layout/list/Item.d.ts.map +1 -1
  17. package/dist/components/layout/list/Item.js +20 -6
  18. package/dist/components/layout/list/Item.js.map +1 -1
  19. package/dist/components/layout/list/Item.module.scss +16 -1
  20. package/dist/components/layout/list/Label.d.ts +1 -0
  21. package/dist/components/layout/list/Label.d.ts.map +1 -1
  22. package/dist/components/layout/list/Label.js +2 -1
  23. package/dist/components/layout/list/Label.js.map +1 -1
  24. package/dist/components/layout/list/List.d.ts +6 -1
  25. package/dist/components/layout/list/List.d.ts.map +1 -1
  26. package/dist/components/layout/list/List.js +16 -1
  27. package/dist/components/layout/list/List.js.map +1 -1
  28. package/dist/components/layout/list/List.module.scss +4 -0
  29. package/dist/components/layout/list/Value.d.ts +4 -1
  30. package/dist/components/layout/list/Value.d.ts.map +1 -1
  31. package/dist/components/layout/list/Value.js +2 -1
  32. package/dist/components/layout/list/Value.js.map +1 -1
  33. package/dist/components/ui/button/Button.d.ts.map +1 -1
  34. package/dist/components/ui/button/Button.js +2 -2
  35. package/dist/components/ui/button/Button.js.map +1 -1
  36. package/dist/components/ui/modal/Modal.d.ts +18 -0
  37. package/dist/components/ui/modal/Modal.d.ts.map +1 -0
  38. package/dist/components/ui/modal/Modal.js +108 -0
  39. package/dist/components/ui/modal/Modal.js.map +1 -0
  40. package/dist/components/ui/modal/Modal.module.scss +92 -0
  41. package/dist/components/ui/modal/ModalButton.d.ts +8 -0
  42. package/dist/components/ui/modal/ModalButton.d.ts.map +1 -0
  43. package/dist/components/ui/modal/ModalButton.js +31 -0
  44. package/dist/components/ui/modal/ModalButton.js.map +1 -0
  45. package/dist/components/ui/modal/ModalButtons.d.ts +10 -0
  46. package/dist/components/ui/modal/ModalButtons.d.ts.map +1 -0
  47. package/dist/components/ui/modal/ModalButtons.js +15 -0
  48. package/dist/components/ui/modal/ModalButtons.js.map +1 -0
  49. package/dist/components/ui/modal/ModalButtons.module.scss +32 -0
  50. package/dist/components/ui/modal/ModalNoMargin.d.ts +6 -0
  51. package/dist/components/ui/modal/ModalNoMargin.d.ts.map +1 -0
  52. package/dist/components/ui/modal/ModalNoMargin.js +22 -0
  53. package/dist/components/ui/modal/ModalNoMargin.js.map +1 -0
  54. package/dist/components/ui/tabs/Item.d.ts +10 -0
  55. package/dist/components/ui/tabs/Item.d.ts.map +1 -0
  56. package/dist/components/ui/tabs/Item.js +39 -0
  57. package/dist/components/ui/tabs/Item.js.map +1 -0
  58. package/dist/components/ui/tabs/Item.module.scss +11 -0
  59. package/dist/components/ui/tabs/Selector.d.ts +10 -0
  60. package/dist/components/ui/tabs/Selector.d.ts.map +1 -0
  61. package/dist/components/ui/tabs/Selector.js +46 -0
  62. package/dist/components/ui/tabs/Selector.js.map +1 -0
  63. package/dist/components/ui/tabs/Selector.module.scss +6 -0
  64. package/dist/components/ui/toaster/Notification.d.ts +9 -0
  65. package/dist/components/ui/toaster/Notification.d.ts.map +1 -0
  66. package/dist/components/ui/toaster/Notification.js +39 -0
  67. package/dist/components/ui/toaster/Notification.js.map +1 -0
  68. package/dist/components/ui/toaster/Toaster.d.ts +18 -0
  69. package/dist/components/ui/toaster/Toaster.d.ts.map +1 -0
  70. package/dist/components/ui/toaster/Toaster.js +79 -0
  71. package/dist/components/ui/toaster/Toaster.js.map +1 -0
  72. package/dist/components/ui/toaster/Toaster.module.scss +32 -0
  73. package/dist/components/ui/toaster/types.d.ts +7 -0
  74. package/dist/components/ui/toaster/types.d.ts.map +1 -0
  75. package/dist/components/ui/toaster/types.js +3 -0
  76. package/dist/components/ui/toaster/types.js.map +1 -0
  77. package/dist/global.scss +12 -0
  78. package/dist/index.d.ts +5 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +5 -0
  81. package/dist/index.js.map +1 -1
  82. package/dist/types/form.d.ts +7 -0
  83. package/dist/types/form.d.ts.map +1 -0
  84. package/dist/types/form.js +3 -0
  85. package/dist/types/form.js.map +1 -0
  86. package/dist/utils/index.d.ts +3 -0
  87. package/dist/utils/index.d.ts.map +1 -0
  88. package/dist/utils/index.js +15 -0
  89. package/dist/utils/index.js.map +1 -0
  90. package/dist/utils/toObjectValue.d.ts +4 -0
  91. package/dist/utils/toObjectValue.d.ts.map +1 -0
  92. package/dist/utils/toObjectValue.js +8 -0
  93. package/dist/utils/toObjectValue.js.map +1 -0
  94. package/docs/assets/js/search.js +1 -1
  95. package/docs/assets/js/search.json +1 -1
  96. package/docs/classes/ToasterProvider.html +1096 -0
  97. package/docs/enums/ICON.html +33 -8
  98. package/docs/index.html +35 -4
  99. package/docs/modules/Item.html +17 -4
  100. package/docs/modules/List.html +17 -4
  101. package/docs/modules/Modal.html +160 -0
  102. package/docs/modules/ModalButtons.html +160 -0
  103. package/docs/modules/Section.html +16 -3
  104. package/docs/modules/StickyHeader.html +17 -4
  105. package/docs/modules.html +132 -23
  106. package/docs/pages/Tutorials/Test.html +16 -3
  107. package/esm/components/form/choice/Choice.d.ts +11 -0
  108. package/esm/components/form/choice/Choice.d.ts.map +1 -0
  109. package/esm/components/form/choice/Choice.js +13 -0
  110. package/esm/components/form/choice/Choice.js.map +1 -0
  111. package/esm/components/form/choice/Choice.module.scss +43 -0
  112. package/esm/components/form/choice/ChoiceItem.d.ts +11 -0
  113. package/esm/components/form/choice/ChoiceItem.d.ts.map +1 -0
  114. package/esm/components/form/choice/ChoiceItem.js +11 -0
  115. package/esm/components/form/choice/ChoiceItem.js.map +1 -0
  116. package/esm/components/layout/list/Header.d.ts +6 -1
  117. package/esm/components/layout/list/Header.d.ts.map +1 -1
  118. package/esm/components/layout/list/Header.js +6 -1
  119. package/esm/components/layout/list/Header.js.map +1 -1
  120. package/esm/components/layout/list/Item.d.ts +3 -0
  121. package/esm/components/layout/list/Item.d.ts.map +1 -1
  122. package/esm/components/layout/list/Item.js +20 -6
  123. package/esm/components/layout/list/Item.js.map +1 -1
  124. package/esm/components/layout/list/Item.module.scss +16 -1
  125. package/esm/components/layout/list/Label.d.ts +1 -0
  126. package/esm/components/layout/list/Label.d.ts.map +1 -1
  127. package/esm/components/layout/list/Label.js +2 -1
  128. package/esm/components/layout/list/Label.js.map +1 -1
  129. package/esm/components/layout/list/List.d.ts +6 -1
  130. package/esm/components/layout/list/List.d.ts.map +1 -1
  131. package/esm/components/layout/list/List.js +16 -1
  132. package/esm/components/layout/list/List.js.map +1 -1
  133. package/esm/components/layout/list/List.module.scss +4 -0
  134. package/esm/components/layout/list/Value.d.ts +4 -1
  135. package/esm/components/layout/list/Value.d.ts.map +1 -1
  136. package/esm/components/layout/list/Value.js +2 -1
  137. package/esm/components/layout/list/Value.js.map +1 -1
  138. package/esm/components/ui/button/Button.d.ts.map +1 -1
  139. package/esm/components/ui/button/Button.js +2 -2
  140. package/esm/components/ui/button/Button.js.map +1 -1
  141. package/esm/components/ui/modal/Modal.d.ts +18 -0
  142. package/esm/components/ui/modal/Modal.d.ts.map +1 -0
  143. package/esm/components/ui/modal/Modal.js +83 -0
  144. package/esm/components/ui/modal/Modal.js.map +1 -0
  145. package/esm/components/ui/modal/Modal.module.scss +92 -0
  146. package/esm/components/ui/modal/ModalButton.d.ts +8 -0
  147. package/esm/components/ui/modal/ModalButton.d.ts.map +1 -0
  148. package/esm/components/ui/modal/ModalButton.js +13 -0
  149. package/esm/components/ui/modal/ModalButton.js.map +1 -0
  150. package/esm/components/ui/modal/ModalButtons.d.ts +10 -0
  151. package/esm/components/ui/modal/ModalButtons.d.ts.map +1 -0
  152. package/esm/components/ui/modal/ModalButtons.js +9 -0
  153. package/esm/components/ui/modal/ModalButtons.js.map +1 -0
  154. package/esm/components/ui/modal/ModalButtons.module.scss +32 -0
  155. package/esm/components/ui/modal/ModalNoMargin.d.ts +6 -0
  156. package/esm/components/ui/modal/ModalNoMargin.d.ts.map +1 -0
  157. package/esm/components/ui/modal/ModalNoMargin.js +16 -0
  158. package/esm/components/ui/modal/ModalNoMargin.js.map +1 -0
  159. package/esm/components/ui/tabs/Item.d.ts +10 -0
  160. package/esm/components/ui/tabs/Item.d.ts.map +1 -0
  161. package/esm/components/ui/tabs/Item.js +14 -0
  162. package/esm/components/ui/tabs/Item.js.map +1 -0
  163. package/esm/components/ui/tabs/Item.module.scss +11 -0
  164. package/esm/components/ui/tabs/Selector.d.ts +10 -0
  165. package/esm/components/ui/tabs/Selector.d.ts.map +1 -0
  166. package/esm/components/ui/tabs/Selector.js +21 -0
  167. package/esm/components/ui/tabs/Selector.js.map +1 -0
  168. package/esm/components/ui/tabs/Selector.module.scss +6 -0
  169. package/esm/components/ui/toaster/Notification.d.ts +9 -0
  170. package/esm/components/ui/toaster/Notification.d.ts.map +1 -0
  171. package/esm/components/ui/toaster/Notification.js +14 -0
  172. package/esm/components/ui/toaster/Notification.js.map +1 -0
  173. package/esm/components/ui/toaster/Toaster.d.ts +18 -0
  174. package/esm/components/ui/toaster/Toaster.d.ts.map +1 -0
  175. package/esm/components/ui/toaster/Toaster.js +74 -0
  176. package/esm/components/ui/toaster/Toaster.js.map +1 -0
  177. package/esm/components/ui/toaster/Toaster.module.scss +32 -0
  178. package/esm/components/ui/toaster/types.d.ts +7 -0
  179. package/esm/components/ui/toaster/types.d.ts.map +1 -0
  180. package/esm/components/ui/toaster/types.js +2 -0
  181. package/esm/components/ui/toaster/types.js.map +1 -0
  182. package/esm/global.scss +12 -0
  183. package/esm/index.d.ts +5 -0
  184. package/esm/index.d.ts.map +1 -1
  185. package/esm/index.js +5 -0
  186. package/esm/index.js.map +1 -1
  187. package/esm/types/form.d.ts +7 -0
  188. package/esm/types/form.d.ts.map +1 -0
  189. package/esm/types/form.js +2 -0
  190. package/esm/types/form.js.map +1 -0
  191. package/esm/utils/index.d.ts +3 -0
  192. package/esm/utils/index.d.ts.map +1 -0
  193. package/esm/utils/index.js +3 -0
  194. package/esm/utils/index.js.map +1 -0
  195. package/esm/utils/toObjectValue.d.ts +4 -0
  196. package/esm/utils/toObjectValue.d.ts.map +1 -0
  197. package/esm/utils/toObjectValue.js +5 -0
  198. package/esm/utils/toObjectValue.js.map +1 -0
  199. package/package.json +6 -6
  200. package/src/components/form/choice/Choice.module.scss +43 -0
  201. package/src/components/form/choice/Choice.tsx +32 -0
  202. package/src/components/form/choice/ChoiceItem.tsx +30 -0
  203. package/src/components/layout/list/Header.tsx +16 -2
  204. package/src/components/layout/list/Item.module.scss +16 -1
  205. package/src/components/layout/list/Item.tsx +28 -7
  206. package/src/components/layout/list/Label.tsx +3 -1
  207. package/src/components/layout/list/List.module.scss +4 -0
  208. package/src/components/layout/list/List.tsx +28 -2
  209. package/src/components/layout/list/Value.tsx +7 -2
  210. package/src/components/ui/button/Button.tsx +4 -2
  211. package/src/components/ui/modal/Modal.module.scss +92 -0
  212. package/src/components/ui/modal/Modal.tsx +136 -0
  213. package/src/components/ui/modal/ModalButton.tsx +25 -0
  214. package/src/components/ui/modal/ModalButtons.module.scss +32 -0
  215. package/src/components/ui/modal/ModalButtons.tsx +17 -0
  216. package/src/components/ui/modal/ModalNoMargin.tsx +22 -0
  217. package/src/components/ui/tabs/Item.module.scss +11 -0
  218. package/src/components/ui/tabs/Item.tsx +26 -0
  219. package/src/components/ui/tabs/Selector.module.scss +6 -0
  220. package/src/components/ui/tabs/Selector.tsx +31 -0
  221. package/src/components/ui/toaster/Notification.tsx +31 -0
  222. package/src/components/ui/toaster/Toaster.module.scss +32 -0
  223. package/src/components/ui/toaster/Toaster.tsx +101 -0
  224. package/src/components/ui/toaster/types.ts +9 -0
  225. package/src/demo/Demo.tsx +7 -4
  226. package/src/demo/Menu.module.scss +1 -0
  227. package/src/demo/components/form/Choice.tsx +19 -0
  228. package/src/demo/components/layout/list/Inset.tsx +24 -0
  229. package/src/demo/components/layout/list/Selection.tsx +17 -0
  230. package/src/demo/components/ui/modal/Modal.tsx +110 -0
  231. package/src/demo/components/ui/tabs/Tabs.tsx +15 -0
  232. package/src/demo/components/ui/toaster/Toaster.tsx +28 -0
  233. package/src/demo/componentsMap.ts +41 -0
  234. package/src/global.scss +12 -0
  235. package/src/index.ts +5 -0
  236. package/src/types/form.ts +7 -0
  237. package/src/utils/index.ts +2 -0
  238. package/src/utils/toObjectValue.ts +9 -0
@@ -4,11 +4,15 @@ import classnames from "classnames";
4
4
  import styles from "./Item.module.scss";
5
5
  import { Value } from "./Value.js";
6
6
  import { Label } from "./Label.js";
7
+ import { makeVariants } from "../../../utils/makeVariants";
8
+ import { ICON, Icon } from "../../icons/Icon";
7
9
 
8
10
  interface LinkProps {
9
11
  href: string;
10
12
  }
11
13
 
14
+ type Variant = "inset";
15
+
12
16
  interface Props {
13
17
  href?: string;
14
18
  to?: string;
@@ -16,6 +20,8 @@ interface Props {
16
20
  className?: string;
17
21
  Link?: React.ComponentClass<LinkProps> | React.FC<LinkProps>;
18
22
  ratio?: string; // @TODO number/number/number/.. type?
23
+ variant?: Variant | Variant[];
24
+ selected?: boolean | undefined;
19
25
  }
20
26
 
21
27
  interface SubComponents {
@@ -23,11 +29,26 @@ interface SubComponents {
23
29
  Value: typeof Value;
24
30
  }
25
31
 
26
- // eslint-disable-next-line max-statements
32
+ const icon = <Icon className={styles.icon} name={ICON.forward} />;
33
+ const noIcon = <span className={styles.icon} />;
34
+
35
+ // eslint-disable-next-line max-statements,max-lines-per-function
27
36
  const Item: React.FC<Props> & SubComponents = (props) => {
28
- const { className, children, href, to, onClick, Link, ratio, ...restProps } = props;
37
+ const { className, children, href, to, onClick, Link, ratio, variant, selected, ...restProps } = props;
38
+ const v = makeVariants(variant);
29
39
  const cls = classnames(styles.item, className);
30
40
 
41
+ const innerCls = classnames(styles.content, {
42
+ [styles.inset]: v.includes("inset"),
43
+ [styles.selected]: selected,
44
+ });
45
+
46
+ const pre = typeof selected === "boolean"
47
+ ? (
48
+ selected ? icon : noIcon
49
+ )
50
+ : null;
51
+
31
52
  const liProps = {
32
53
  className: cls,
33
54
  };
@@ -42,7 +63,7 @@ const Item: React.FC<Props> & SubComponents = (props) => {
42
63
  if (index in r) {
43
64
  flex = r[index];
44
65
  }
45
- return <div style={{ flex }}>{child}</div>;
66
+ return <div style={{ flex }}>{pre}{child}</div>;
46
67
  });
47
68
 
48
69
  if (to) {
@@ -50,25 +71,25 @@ const Item: React.FC<Props> & SubComponents = (props) => {
50
71
  throw new TypeError("`to` prop given without `Link` component");
51
72
  }
52
73
 
53
- return <li {...liProps}><Link href={to} {...restProps}><a className={styles.content}>{ren}</a></Link></li>;
74
+ return <li {...liProps}><Link href={to} {...restProps}><a className={innerCls}>{ren}</a></Link></li>;
54
75
  }
55
76
  if (href) {
56
77
  const aProps: typeof restProps & { onClick?: Props["onClick"]} = { ...restProps };
57
78
  if (onClick) {
58
79
  aProps.onClick = onClick;
59
80
  }
60
- return <li {...liProps}><a href={href} {...aProps} className={styles.content}>{ren}</a></li>;
81
+ return <li {...liProps}><a href={href} {...aProps} className={innerCls}>{ren}</a></li>;
61
82
  }
62
83
  if (onClick) {
63
84
  return (
64
85
  <li {...liProps}>
65
- <button className={classnames(styles.button, styles.content)} onClick={props.onClick}{...restProps}>
86
+ <button className={classnames(styles.button, innerCls)} onClick={props.onClick} {...restProps}>
66
87
  {ren}
67
88
  </button>
68
89
  </li>
69
90
  );
70
91
  }
71
- return <li {...liProps}><div {...restProps} className={styles.content}>{ren}</div></li>;
92
+ return <li {...liProps}><div {...restProps} className={innerCls}>{ren}</div></li>;
72
93
  };
73
94
 
74
95
  Item.Label = Label;
@@ -1,17 +1,19 @@
1
1
  import React from "react";
2
+ import classnames from "classnames";
2
3
  import type { ReactNode } from "react";
3
4
 
4
5
  import styles from "./Label.module.scss";
5
6
 
6
7
  interface Props {
7
8
  sub?: ReactNode;
9
+ className?: string;
8
10
  }
9
11
 
10
12
  const Label: React.FC<Props> = (props) => {
11
13
  const sub = props.sub ? <div className={styles.sub}>{props.sub}</div> : null;
12
14
 
13
15
  return (
14
- <div className={styles.root}>
16
+ <div className={classnames(styles.root, props.className)}>
15
17
  <div>{props.children}</div>
16
18
  {sub}
17
19
  </div>
@@ -2,3 +2,7 @@
2
2
  margin: 0 23px;
3
3
  padding: 0;
4
4
  }
5
+
6
+ .inset {
7
+ margin: 0;
8
+ }
@@ -1,15 +1,41 @@
1
1
  import React from "react";
2
+ import classnames from "classnames";
2
3
 
3
4
  import { Header } from "./Header.js";
5
+ import { makeVariants } from "../../../utils/makeVariants";
6
+ import { Item } from "./Item";
4
7
  import styles from "./List.module.scss";
5
8
 
9
+ type Variant = "inset";
10
+
11
+ interface Props {
12
+ className?: string;
13
+ variant?: Variant | Variant[];
14
+ }
15
+
6
16
  interface SubComponents {
7
17
  Header: typeof Header;
8
18
  }
9
19
 
10
- const List: React.FC & SubComponents = (props) => {
20
+ const List: React.FC<Props> & SubComponents = (props) => {
21
+ const v = makeVariants(props.variant);
22
+
23
+ const chld = React.Children.map(props.children, (child) => {
24
+ if (child && typeof child === "object" && "type" in child && (child.type === Item || child.type === Header)) {
25
+ return React.cloneElement(child, {
26
+ // @TODO this will override but should merge?
27
+ variant: props.variant,
28
+ });
29
+ }
30
+ return child;
31
+ });
32
+
33
+ const cls = classnames(props.className, styles.list, {
34
+ [styles.inset]: v.includes("inset"),
35
+ });
36
+
11
37
  return (
12
- <ul className={styles.list}>{props.children}</ul>
38
+ <ul className={cls}>{chld}</ul>
13
39
  );
14
40
  };
15
41
 
@@ -1,10 +1,15 @@
1
1
  import React from "react";
2
+ import classnames from "classnames";
2
3
 
3
4
  import styles from "./Value.module.scss";
4
5
 
5
- const Value: React.FC = (props) => {
6
+ interface Props {
7
+ className?: string;
8
+ }
9
+
10
+ const Value: React.FC<Props> = (props) => {
6
11
  return (
7
- <div className={styles.value}>{props.children}</div>
12
+ <div className={classnames(styles.value, props.className)}>{props.children}</div>
8
13
  );
9
14
  };
10
15
 
@@ -8,8 +8,10 @@ interface Props {
8
8
  variant?: "inline" | "outline";
9
9
  }
10
10
 
11
- const Button: React.FC<React.ButtonHTMLAttributes<HTMLButtonElement> & Props> = ({ className, children, ...props }) => {
12
- const variants = makeVariants(props.variant);
11
+ const Button: React.FC<React.ButtonHTMLAttributes<HTMLButtonElement> & Props> = ({
12
+ className, children, variant, ...props
13
+ }) => {
14
+ const variants = makeVariants(variant);
13
15
 
14
16
  const cls = classnames(styles.btn, {
15
17
  [styles["btn--inline"]]: variants.includes("inline"),
@@ -0,0 +1,92 @@
1
+ @keyframes overlay {
2
+ from {
3
+ background: #00000000;
4
+ }
5
+
6
+ to {
7
+ background: #0000004c;
8
+ }
9
+ }
10
+
11
+ .overlay {
12
+ position: fixed;
13
+ z-index: 4;
14
+ top: 0;
15
+ bottom: 0;
16
+ left: 0;
17
+ right: 0;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ animation: overlay 300ms;
22
+ animation-fill-mode: forwards;
23
+ }
24
+
25
+ .overlayOnBottom {
26
+ align-items: flex-end;
27
+ padding-bottom: calc(24px / var(--ratio-dimensions));
28
+ }
29
+
30
+ @keyframes container {
31
+ from {
32
+ transform: translateY(30px);
33
+ opacity: 0;
34
+ }
35
+
36
+ to {
37
+ transform: translateY(0);
38
+ opacity: 1;
39
+ }
40
+ }
41
+
42
+ .container {
43
+ background: var(--modal-bg);
44
+ border-radius: calc(12px / var(--ratio-dimensions));
45
+ max-width: 333px;
46
+ width: calc(100% - 30px);
47
+ padding: 20px;
48
+ position: relative;
49
+ box-sizing: border-box;
50
+ animation: container 300ms;
51
+ animation-fill-mode: forwards;
52
+ }
53
+
54
+ .full {
55
+ width: calc(100vw - 30px);
56
+ max-width: 1000px;
57
+ }
58
+
59
+ .isClosing {
60
+ // keep this after .overlay .container to prevent overwriting
61
+ animation-direction: reverse;
62
+ }
63
+
64
+ .close {
65
+ position: absolute;
66
+ top: 20px;
67
+ right: 20px;
68
+ background: none;
69
+ border: none;
70
+ padding: 0;
71
+ margin: 0;
72
+
73
+ + .title {
74
+ margin-right: 40px;
75
+ margin-top: -4px;
76
+ }
77
+ }
78
+
79
+ .title {
80
+ font-size: calc(40px / var(--ratio-font));
81
+ text-align: center;
82
+ color: black;
83
+ margin: calc(90px / var(--ratio-dimensions)) 0;
84
+ }
85
+
86
+ .negateMargin {
87
+ margin: 0 -20px -20px;
88
+ }
89
+
90
+ .removeMargin {
91
+ margin: 0;
92
+ }
@@ -0,0 +1,136 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from "react";
2
+ import classnames from "classnames";
3
+
4
+ import styles from "./Modal.module.scss";
5
+ import { makeVariants } from "../../../utils/makeVariants";
6
+ import { ModalNegateMargin } from "./ModalNoMargin";
7
+
8
+ type Variant = "bottom" | "full";
9
+
10
+ interface Props {
11
+ onOverlayClick?: (() => void) | "close" | null;
12
+ closeOnEsc?: boolean;
13
+ onClose: () => void;
14
+ isOpen: boolean;
15
+ title?: React.ReactNode;
16
+ className?: string;
17
+ variant?: Variant | Variant[];
18
+ }
19
+
20
+ interface SubComponents {
21
+ NegateMargin: typeof ModalNegateMargin;
22
+ }
23
+
24
+ // eslint-disable-next-line max-lines-per-function,max-statements
25
+ const Modal: React.FC<Props> & SubComponents = ({
26
+ children,
27
+ onClose,
28
+ isOpen,
29
+ title,
30
+ className,
31
+ onOverlayClick = "close",
32
+ closeOnEsc = true,
33
+ variant,
34
+ }) => {
35
+ const [isClosing, setIsClosing] = useState(false);
36
+ const [isRendered, setIsRendered] = useState(false);
37
+ const overlayRef = useRef<HTMLDivElement>(null);
38
+ const containerRef = useRef<HTMLDivElement>(null);
39
+
40
+ const v = makeVariants(variant);
41
+
42
+ useEffect(() => {
43
+ if (!isOpen || !closeOnEsc) {
44
+ return;
45
+ }
46
+
47
+ const onKeyDown = (e: KeyboardEvent) => {
48
+ if (e.key === "Escape") {
49
+ onClose();
50
+ }
51
+ };
52
+ document.addEventListener("keydown", onKeyDown);
53
+ return () => {
54
+ document.removeEventListener("keydown", onKeyDown);
55
+ };
56
+ }, [isOpen, closeOnEsc]);
57
+
58
+ useEffect(() => {
59
+ if (!isOpen) {
60
+ setIsClosing(true);
61
+ return;
62
+ }
63
+ setIsRendered(true);
64
+ setIsClosing(false);
65
+ }, [isOpen]);
66
+
67
+ useEffect(() => {
68
+ if (!isClosing) {
69
+ return;
70
+ }
71
+
72
+ if (!overlayRef.current || !containerRef.current) {
73
+ return;
74
+ }
75
+
76
+ overlayRef.current.style.animation = "none";
77
+ containerRef.current.style.animation = "none";
78
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
79
+ overlayRef.current.offsetHeight; // force sync document reflow
80
+ overlayRef.current.style.removeProperty("animation");
81
+ containerRef.current.style.removeProperty("animation");
82
+ }, [isClosing]);
83
+
84
+ const titleElem = title && <div className={styles.title}>{title}</div>;
85
+
86
+ const handleOverlayClick = useCallback((e: React.MouseEvent) => {
87
+ if (e.target !== e.currentTarget) {
88
+ return;
89
+ }
90
+ if (onOverlayClick === "close") {
91
+ onClose();
92
+ }
93
+ if (typeof onOverlayClick === "function") {
94
+ onOverlayClick();
95
+ }
96
+ }, [onOverlayClick, onClose]);
97
+
98
+ const handleAnimationEnd = useCallback(() => {
99
+ if (isOpen) {
100
+ return;
101
+ }
102
+
103
+ setIsRendered(false);
104
+ }, [isOpen]);
105
+
106
+ if (!isRendered) {
107
+ return null;
108
+ }
109
+
110
+ const overlayCls = classnames(styles.overlay, {
111
+ [styles.isClosing]: isClosing,
112
+ [styles.overlayOnBottom]: v.includes("bottom"),
113
+ });
114
+
115
+ const containerCls = classnames(styles.container, className, {
116
+ [styles.isClosing]: isClosing,
117
+ [styles.full]: v.includes("full"),
118
+ });
119
+
120
+ return (
121
+ <div
122
+ className={overlayCls}
123
+ onClick={handleOverlayClick}
124
+ ref={overlayRef}
125
+ onAnimationEnd={handleAnimationEnd}
126
+ >
127
+ <div className={containerCls} ref={containerRef}>
128
+ {titleElem}
129
+ {children}
130
+ </div>
131
+ </div>
132
+ );
133
+ };
134
+ Modal.NegateMargin = ModalNegateMargin;
135
+
136
+ export { Modal };
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+
3
+ import styles from "./ModalButtons.module.scss";
4
+ import { makeVariants } from "../../../utils/makeVariants";
5
+ import classnames from "classnames";
6
+
7
+ type Variant = "main";
8
+
9
+ interface Props {
10
+ variant?: Variant | Variant[];
11
+ }
12
+
13
+ const ModalButton: React.FC<React.ButtonHTMLAttributes<HTMLButtonElement> & Props> = ({
14
+ className, children, variant, ...props
15
+ }) => {
16
+ const v = makeVariants(variant);
17
+
18
+ const cls = classnames(styles.button, {
19
+ [styles.buttonMain]: v.includes("main"),
20
+ }, className);
21
+
22
+ return <button {...props} className={cls}>{children}</button>;
23
+ };
24
+
25
+ export { ModalButton };
@@ -0,0 +1,32 @@
1
+ .container {
2
+ display: flex;
3
+ margin-top: calc(100px / var(--ratio-dimensions));
4
+ margin-left: -20px;
5
+ margin-right: -20px;
6
+ margin-bottom: -20px;
7
+ }
8
+
9
+ .button {
10
+ border: none;
11
+ border-top: 1px solid var(--modal-button-border);
12
+ background: var(--modal-button-bg);
13
+ flex: 1;
14
+ height: calc(156px / var(--ratio-dimensions));
15
+ font-weight: 500;
16
+
17
+ &:not(:first-child) {
18
+ border-left: 1px solid var(--modal-button-border);
19
+ }
20
+
21
+ &:first-child {
22
+ border-bottom-left-radius: calc(12px / var(--ratio-dimensions));
23
+ }
24
+
25
+ &:last-child {
26
+ border-bottom-right-radius: calc(12px / var(--ratio-dimensions));
27
+ }
28
+ }
29
+
30
+ .buttonMain {
31
+ color: var(--main-color);
32
+ }
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { ModalButton } from "./ModalButton";
3
+
4
+ import styles from "./ModalButtons.module.scss";
5
+
6
+ interface Props {}
7
+
8
+ interface SubComponents {
9
+ Button: typeof ModalButton;
10
+ }
11
+
12
+ const ModalButtons: React.FC<Props> & SubComponents = (props) => {
13
+ return <div className={styles.container}>{props.children}</div>;
14
+ };
15
+ ModalButtons.Button = ModalButton;
16
+
17
+ export { ModalButtons };
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+
3
+ import styles from "./Modal.module.scss";
4
+ import { List } from "../../layout/list/List";
5
+
6
+ interface Props {}
7
+
8
+ const ModalNegateMargin: React.FC<Props> = (props) => {
9
+ const chld = React.Children.map(props.children, (child, index) => {
10
+ if (child && typeof child === "object" && "type" in child && child.type === List) {
11
+ return React.cloneElement(child, {
12
+ // @TODO this will overwrite className
13
+ className: styles.removeMargin,
14
+ });
15
+ }
16
+
17
+ return child;
18
+ });
19
+ return <div className={styles.negateMargin}>{chld}</div>;
20
+ };
21
+
22
+ export { ModalNegateMargin };
@@ -0,0 +1,11 @@
1
+ .button {
2
+ border: none;
3
+ padding: 0;
4
+ font-size: calc(29px / var(--ratio-font));
5
+ color: var(--selector-text);
6
+ background: none;
7
+ }
8
+
9
+ .active {
10
+ color: var(--selector-active);
11
+ }
@@ -0,0 +1,26 @@
1
+ import React, { useCallback } from "react";
2
+ import classnames from "classnames";
3
+
4
+ import type { ObjectValue } from "../../../types/form";
5
+
6
+ import styles from "./Item.module.scss";
7
+
8
+ interface Props {
9
+ value: ObjectValue;
10
+ onClick: (value: string) => void;
11
+ active: boolean;
12
+ }
13
+
14
+ const Item: React.FC<Props> = (props) => {
15
+ const handleClick = useCallback(() => {
16
+ props.onClick(props.value.value);
17
+ }, [props.onClick, props.value.value, props.value.label]);
18
+
19
+ const cls = classnames(styles.button, {
20
+ [styles.active]: props.active,
21
+ });
22
+
23
+ return <button onClick={handleClick} className={cls} type={"button"}>{props.value.label}</button>;
24
+ };
25
+
26
+ export { Item };
@@ -0,0 +1,6 @@
1
+ .selector {
2
+ display: flex;
3
+ flex: 1;
4
+ justify-content: center;
5
+ gap: calc(114px / var(--ratio-dimensions));
6
+ }
@@ -0,0 +1,31 @@
1
+ import React, { useCallback, useState } from "react";
2
+
3
+ import type { Value } from "../../../types/form";
4
+ import { toObjectValue } from "../../../utils";
5
+ import { Item } from "./Item";
6
+ import styles from "./Selector.module.scss";
7
+
8
+ interface Props {
9
+ values: Value[];
10
+ value?: string;
11
+ onChange?: (value: string) => void;
12
+ }
13
+
14
+ const Selector: React.FC<Props> = (props) => {
15
+ const [current, setCurrent] = useState(props.value);
16
+
17
+ const handleCurrent = useCallback((value: string) => {
18
+ setCurrent(value);
19
+ props.onChange?.(value);
20
+ }, [props.onChange]);
21
+
22
+ const crr = props.value ?? current;
23
+
24
+ const vals = props.values.map(v => {
25
+ const ov = toObjectValue(v);
26
+ return <Item key={ov.value} value={ov} onClick={handleCurrent} active={crr === ov.value} />;
27
+ });
28
+ return <div className={styles.selector}>{vals}</div>;
29
+ };
30
+
31
+ export { Selector };
@@ -0,0 +1,31 @@
1
+ import React, { useCallback } from "react";
2
+ import classnames from "classnames";
3
+
4
+ import type { Toast } from "./types";
5
+ import styles from "./Toaster.module.scss";
6
+
7
+ interface Props {
8
+ toast: Toast;
9
+ onRemove: (id: Toast["id"]) => void;
10
+ }
11
+
12
+ // eslint-disable-next-line @typescript-eslint/no-shadow
13
+ const Notification: React.FC<Props> = (props) => {
14
+ const handleRemove = useCallback(() => {
15
+ props.onRemove(props.toast.id);
16
+ }, [props.toast.id]);
17
+
18
+ return (
19
+ <div
20
+ className={classnames(styles.toast, {
21
+ [styles.hide]: props.toast.hide,
22
+ })}
23
+ key={props.toast.id}
24
+ onTransitionEnd={handleRemove}
25
+ >
26
+ <span>{props.toast.text}</span>
27
+ </div>
28
+ );
29
+ };
30
+
31
+ export { Notification };
@@ -0,0 +1,32 @@
1
+ @keyframes show {
2
+ from {
3
+ transform: translateY(calc(100% + calc(190px / var(--ratio-dimensions))))
4
+ }
5
+ }
6
+
7
+ .toast {
8
+ position: fixed;
9
+ bottom: 0;
10
+ left: 40px;
11
+ right: 40px;
12
+ display: flex;
13
+ justify-content: center;
14
+ z-index: 1;
15
+
16
+ span {
17
+ background: rgba(56, 50, 46, 0.85);
18
+ color: #F9F6F2;
19
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.37);
20
+ border-radius: 12px; // around 22 @TODO use calc here
21
+ display: inline-block;
22
+ padding: 1em 1em;
23
+ animation: show 500ms 1;
24
+ animation-fill-mode: forwards;
25
+ margin-bottom: calc(190px / var(--ratio-dimensions));
26
+ }
27
+ }
28
+
29
+ .hide {
30
+ transition: opacity 300ms;
31
+ opacity: 0;
32
+ }