react-miui 0.5.1 → 0.8.0

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 (272) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/assets/sources/battery.fla +0 -0
  3. package/assets/sources/search.fla +0 -0
  4. package/dist/components/form/Input.d.ts +9 -0
  5. package/dist/components/form/Input.d.ts.map +1 -0
  6. package/dist/components/form/Input.js +62 -0
  7. package/dist/components/form/Input.js.map +1 -0
  8. package/dist/components/form/Input.module.scss +48 -0
  9. package/dist/components/form/Label.d.ts +8 -0
  10. package/dist/components/form/Label.d.ts.map +1 -0
  11. package/dist/components/form/Label.js +22 -0
  12. package/dist/components/form/Label.js.map +1 -0
  13. package/dist/components/form/Label.module.scss +15 -0
  14. package/dist/components/form/TextArea.d.ts +7 -0
  15. package/dist/components/form/TextArea.d.ts.map +1 -0
  16. package/dist/components/form/TextArea.js +57 -0
  17. package/dist/components/form/TextArea.js.map +1 -0
  18. package/dist/components/form/Toggle.d.ts +1 -1
  19. package/dist/components/form/Toggle.d.ts.map +1 -1
  20. package/dist/components/form/Toggle.js.map +1 -1
  21. package/dist/components/icons/Back.d.ts +1 -1
  22. package/dist/components/icons/Back.d.ts.map +1 -1
  23. package/dist/components/icons/Back.js.map +1 -1
  24. package/dist/components/icons/Battery.d.ts +7 -0
  25. package/dist/components/icons/Battery.d.ts.map +1 -0
  26. package/dist/components/icons/Battery.js +14 -0
  27. package/dist/components/icons/Battery.js.map +1 -0
  28. package/dist/components/icons/Forward.d.ts +1 -1
  29. package/dist/components/icons/Forward.d.ts.map +1 -1
  30. package/dist/components/icons/Forward.js.map +1 -1
  31. package/dist/components/icons/Icon.d.ts +3 -1
  32. package/dist/components/icons/Icon.d.ts.map +1 -1
  33. package/dist/components/icons/Icon.js +6 -0
  34. package/dist/components/icons/Icon.js.map +1 -1
  35. package/dist/components/icons/Search.d.ts +7 -0
  36. package/dist/components/icons/Search.d.ts.map +1 -0
  37. package/dist/components/icons/Search.js +13 -0
  38. package/dist/components/icons/Search.js.map +1 -0
  39. package/dist/components/layout/header/HeaderIconAction.d.ts +1 -1
  40. package/dist/components/layout/header/HeaderIconAction.d.ts.map +1 -1
  41. package/dist/components/layout/header/HeaderIconAction.js.map +1 -1
  42. package/dist/components/layout/list/Header.d.ts +5 -1
  43. package/dist/components/layout/list/Header.d.ts.map +1 -1
  44. package/dist/components/layout/list/Header.js +6 -1
  45. package/dist/components/layout/list/Header.js.map +1 -1
  46. package/dist/components/layout/list/Item.d.ts +3 -0
  47. package/dist/components/layout/list/Item.d.ts.map +1 -1
  48. package/dist/components/layout/list/Item.js +20 -6
  49. package/dist/components/layout/list/Item.js.map +1 -1
  50. package/dist/components/layout/list/Item.module.scss +16 -1
  51. package/dist/components/layout/list/List.d.ts +6 -1
  52. package/dist/components/layout/list/List.d.ts.map +1 -1
  53. package/dist/components/layout/list/List.js +15 -1
  54. package/dist/components/layout/list/List.js.map +1 -1
  55. package/dist/components/layout/list/List.module.scss +4 -0
  56. package/dist/components/layout/section/SearchContainer.d.ts +4 -0
  57. package/dist/components/layout/section/SearchContainer.d.ts.map +1 -0
  58. package/dist/components/layout/section/SearchContainer.js +13 -0
  59. package/dist/components/layout/section/SearchContainer.js.map +1 -0
  60. package/dist/components/layout/section/SearchContainer.module.scss +3 -0
  61. package/dist/components/layout/section/Section.module.scss +7 -0
  62. package/dist/components/ui/action/Action.d.ts +1 -1
  63. package/dist/components/ui/action/Action.d.ts.map +1 -1
  64. package/dist/components/ui/action/Action.js.map +1 -1
  65. package/dist/components/ui/button/Button.d.ts +1 -2
  66. package/dist/components/ui/button/Button.d.ts.map +1 -1
  67. package/dist/components/ui/button/Button.js +16 -4
  68. package/dist/components/ui/button/Button.js.map +1 -1
  69. package/dist/components/ui/modal/Modal.d.ts +18 -0
  70. package/dist/components/ui/modal/Modal.d.ts.map +1 -0
  71. package/dist/components/ui/modal/Modal.js +108 -0
  72. package/dist/components/ui/modal/Modal.js.map +1 -0
  73. package/dist/components/ui/modal/Modal.module.scss +92 -0
  74. package/dist/components/ui/modal/ModalButton.d.ts +8 -0
  75. package/dist/components/ui/modal/ModalButton.d.ts.map +1 -0
  76. package/dist/components/ui/modal/ModalButton.js +31 -0
  77. package/dist/components/ui/modal/ModalButton.js.map +1 -0
  78. package/dist/components/ui/modal/ModalButtons.d.ts +10 -0
  79. package/dist/components/ui/modal/ModalButtons.d.ts.map +1 -0
  80. package/dist/components/ui/modal/ModalButtons.js +15 -0
  81. package/dist/components/ui/modal/ModalButtons.js.map +1 -0
  82. package/dist/components/ui/modal/ModalButtons.module.scss +32 -0
  83. package/dist/components/ui/modal/ModalNoMargin.d.ts +6 -0
  84. package/dist/components/ui/modal/ModalNoMargin.d.ts.map +1 -0
  85. package/dist/components/ui/modal/ModalNoMargin.js +22 -0
  86. package/dist/components/ui/modal/ModalNoMargin.js.map +1 -0
  87. package/dist/components/ui/toaster/Notification.d.ts +9 -0
  88. package/dist/components/ui/toaster/Notification.d.ts.map +1 -0
  89. package/dist/components/ui/toaster/Notification.js +39 -0
  90. package/dist/components/ui/toaster/Notification.js.map +1 -0
  91. package/dist/components/ui/toaster/Toaster.d.ts +18 -0
  92. package/dist/components/ui/toaster/Toaster.d.ts.map +1 -0
  93. package/dist/components/ui/toaster/Toaster.js +79 -0
  94. package/dist/components/ui/toaster/Toaster.js.map +1 -0
  95. package/dist/components/ui/toaster/Toaster.module.scss +32 -0
  96. package/dist/components/ui/toaster/types.d.ts +7 -0
  97. package/dist/components/ui/toaster/types.d.ts.map +1 -0
  98. package/dist/components/ui/toaster/types.js +3 -0
  99. package/dist/components/ui/toaster/types.js.map +1 -0
  100. package/dist/global.scss +4 -0
  101. package/dist/index.d.ts +7 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +7 -0
  104. package/dist/index.js.map +1 -1
  105. package/dist/types.d.ts +1 -1
  106. package/dist/types.d.ts.map +1 -1
  107. package/docs/assets/js/search.js +1 -1
  108. package/docs/assets/js/search.json +1 -1
  109. package/docs/classes/ToasterProvider.html +1090 -0
  110. package/docs/enums/ICON.html +65 -6
  111. package/docs/index.html +41 -4
  112. package/docs/modules/Item.html +16 -3
  113. package/docs/modules/List.html +17 -4
  114. package/docs/modules/Modal.html +160 -0
  115. package/docs/modules/ModalButtons.html +160 -0
  116. package/docs/modules/Section.html +16 -3
  117. package/docs/modules/StickyHeader.html +17 -4
  118. package/docs/modules.html +160 -23
  119. package/docs/pages/Tutorials/Test.html +16 -3
  120. package/esm/components/form/Input.d.ts +9 -0
  121. package/esm/components/form/Input.d.ts.map +1 -0
  122. package/esm/components/form/Input.js +25 -0
  123. package/esm/components/form/Input.js.map +1 -0
  124. package/esm/components/form/Input.module.scss +48 -0
  125. package/esm/components/form/Label.d.ts +8 -0
  126. package/esm/components/form/Label.d.ts.map +1 -0
  127. package/esm/components/form/Label.js +16 -0
  128. package/esm/components/form/Label.js.map +1 -0
  129. package/esm/components/form/Label.module.scss +15 -0
  130. package/esm/components/form/TextArea.d.ts +7 -0
  131. package/esm/components/form/TextArea.d.ts.map +1 -0
  132. package/esm/components/form/TextArea.js +20 -0
  133. package/esm/components/form/TextArea.js.map +1 -0
  134. package/esm/components/form/Toggle.d.ts +1 -1
  135. package/esm/components/form/Toggle.d.ts.map +1 -1
  136. package/esm/components/form/Toggle.js.map +1 -1
  137. package/esm/components/icons/Back.d.ts +1 -1
  138. package/esm/components/icons/Back.d.ts.map +1 -1
  139. package/esm/components/icons/Back.js.map +1 -1
  140. package/esm/components/icons/Battery.d.ts +7 -0
  141. package/esm/components/icons/Battery.d.ts.map +1 -0
  142. package/esm/components/icons/Battery.js +8 -0
  143. package/esm/components/icons/Battery.js.map +1 -0
  144. package/esm/components/icons/Forward.d.ts +1 -1
  145. package/esm/components/icons/Forward.d.ts.map +1 -1
  146. package/esm/components/icons/Forward.js.map +1 -1
  147. package/esm/components/icons/Icon.d.ts +3 -1
  148. package/esm/components/icons/Icon.d.ts.map +1 -1
  149. package/esm/components/icons/Icon.js +6 -0
  150. package/esm/components/icons/Icon.js.map +1 -1
  151. package/esm/components/icons/Search.d.ts +7 -0
  152. package/esm/components/icons/Search.d.ts.map +1 -0
  153. package/esm/components/icons/Search.js +7 -0
  154. package/esm/components/icons/Search.js.map +1 -0
  155. package/esm/components/layout/header/HeaderIconAction.d.ts +1 -1
  156. package/esm/components/layout/header/HeaderIconAction.d.ts.map +1 -1
  157. package/esm/components/layout/header/HeaderIconAction.js.map +1 -1
  158. package/esm/components/layout/list/Header.d.ts +5 -1
  159. package/esm/components/layout/list/Header.d.ts.map +1 -1
  160. package/esm/components/layout/list/Header.js +6 -1
  161. package/esm/components/layout/list/Header.js.map +1 -1
  162. package/esm/components/layout/list/Item.d.ts +3 -0
  163. package/esm/components/layout/list/Item.d.ts.map +1 -1
  164. package/esm/components/layout/list/Item.js +20 -6
  165. package/esm/components/layout/list/Item.js.map +1 -1
  166. package/esm/components/layout/list/Item.module.scss +16 -1
  167. package/esm/components/layout/list/List.d.ts +6 -1
  168. package/esm/components/layout/list/List.d.ts.map +1 -1
  169. package/esm/components/layout/list/List.js +15 -1
  170. package/esm/components/layout/list/List.js.map +1 -1
  171. package/esm/components/layout/list/List.module.scss +4 -0
  172. package/esm/components/layout/section/SearchContainer.d.ts +4 -0
  173. package/esm/components/layout/section/SearchContainer.d.ts.map +1 -0
  174. package/esm/components/layout/section/SearchContainer.js +7 -0
  175. package/esm/components/layout/section/SearchContainer.js.map +1 -0
  176. package/esm/components/layout/section/SearchContainer.module.scss +3 -0
  177. package/esm/components/layout/section/Section.module.scss +7 -0
  178. package/esm/components/ui/action/Action.d.ts +1 -1
  179. package/esm/components/ui/action/Action.d.ts.map +1 -1
  180. package/esm/components/ui/action/Action.js.map +1 -1
  181. package/esm/components/ui/button/Button.d.ts +1 -2
  182. package/esm/components/ui/button/Button.d.ts.map +1 -1
  183. package/esm/components/ui/button/Button.js +4 -4
  184. package/esm/components/ui/button/Button.js.map +1 -1
  185. package/esm/components/ui/modal/Modal.d.ts +18 -0
  186. package/esm/components/ui/modal/Modal.d.ts.map +1 -0
  187. package/esm/components/ui/modal/Modal.js +83 -0
  188. package/esm/components/ui/modal/Modal.js.map +1 -0
  189. package/esm/components/ui/modal/Modal.module.scss +92 -0
  190. package/esm/components/ui/modal/ModalButton.d.ts +8 -0
  191. package/esm/components/ui/modal/ModalButton.d.ts.map +1 -0
  192. package/esm/components/ui/modal/ModalButton.js +13 -0
  193. package/esm/components/ui/modal/ModalButton.js.map +1 -0
  194. package/esm/components/ui/modal/ModalButtons.d.ts +10 -0
  195. package/esm/components/ui/modal/ModalButtons.d.ts.map +1 -0
  196. package/esm/components/ui/modal/ModalButtons.js +9 -0
  197. package/esm/components/ui/modal/ModalButtons.js.map +1 -0
  198. package/esm/components/ui/modal/ModalButtons.module.scss +32 -0
  199. package/esm/components/ui/modal/ModalNoMargin.d.ts +6 -0
  200. package/esm/components/ui/modal/ModalNoMargin.d.ts.map +1 -0
  201. package/esm/components/ui/modal/ModalNoMargin.js +16 -0
  202. package/esm/components/ui/modal/ModalNoMargin.js.map +1 -0
  203. package/esm/components/ui/toaster/Notification.d.ts +9 -0
  204. package/esm/components/ui/toaster/Notification.d.ts.map +1 -0
  205. package/esm/components/ui/toaster/Notification.js +14 -0
  206. package/esm/components/ui/toaster/Notification.js.map +1 -0
  207. package/esm/components/ui/toaster/Toaster.d.ts +18 -0
  208. package/esm/components/ui/toaster/Toaster.d.ts.map +1 -0
  209. package/esm/components/ui/toaster/Toaster.js +74 -0
  210. package/esm/components/ui/toaster/Toaster.js.map +1 -0
  211. package/esm/components/ui/toaster/Toaster.module.scss +32 -0
  212. package/esm/components/ui/toaster/types.d.ts +7 -0
  213. package/esm/components/ui/toaster/types.d.ts.map +1 -0
  214. package/esm/components/ui/toaster/types.js +2 -0
  215. package/esm/components/ui/toaster/types.js.map +1 -0
  216. package/esm/global.scss +4 -0
  217. package/esm/index.d.ts +7 -0
  218. package/esm/index.d.ts.map +1 -1
  219. package/esm/index.js +7 -0
  220. package/esm/index.js.map +1 -1
  221. package/esm/types.d.ts +1 -1
  222. package/esm/types.d.ts.map +1 -1
  223. package/package.json +2 -2
  224. package/src/components/form/Input.module.scss +48 -0
  225. package/src/components/form/Input.tsx +48 -0
  226. package/src/components/form/Label.module.scss +15 -0
  227. package/src/components/form/Label.tsx +29 -0
  228. package/src/components/form/TextArea.tsx +38 -0
  229. package/src/components/form/Toggle.tsx +1 -1
  230. package/src/components/icons/Back.tsx +1 -1
  231. package/src/components/icons/Battery.tsx +34 -0
  232. package/src/components/icons/Forward.tsx +1 -1
  233. package/src/components/icons/Icon.tsx +6 -0
  234. package/src/components/icons/Search.tsx +29 -0
  235. package/src/components/layout/header/HeaderIconAction.tsx +1 -1
  236. package/src/components/layout/list/Header.tsx +15 -2
  237. package/src/components/layout/list/Item.module.scss +16 -1
  238. package/src/components/layout/list/Item.tsx +28 -7
  239. package/src/components/layout/list/List.module.scss +4 -0
  240. package/src/components/layout/list/List.tsx +29 -2
  241. package/src/components/layout/section/SearchContainer.module.scss +3 -0
  242. package/src/components/layout/section/SearchContainer.tsx +11 -0
  243. package/src/components/layout/section/Section.module.scss +7 -0
  244. package/src/components/ui/action/Action.tsx +1 -1
  245. package/src/components/ui/button/Button.tsx +11 -5
  246. package/src/components/ui/modal/Modal.module.scss +92 -0
  247. package/src/components/ui/modal/Modal.tsx +136 -0
  248. package/src/components/ui/modal/ModalButton.tsx +25 -0
  249. package/src/components/ui/modal/ModalButtons.module.scss +32 -0
  250. package/src/components/ui/modal/ModalButtons.tsx +17 -0
  251. package/src/components/ui/modal/ModalNoMargin.tsx +22 -0
  252. package/src/components/ui/toaster/Notification.tsx +31 -0
  253. package/src/components/ui/toaster/Toaster.module.scss +32 -0
  254. package/src/components/ui/toaster/Toaster.tsx +101 -0
  255. package/src/components/ui/toaster/types.ts +9 -0
  256. package/src/demo/Demo.tsx +7 -4
  257. package/src/demo/Menu.module.scss +1 -0
  258. package/src/demo/components/form/Form.tsx +35 -0
  259. package/src/demo/components/form/Input.tsx +13 -0
  260. package/src/demo/components/form/Label.tsx +14 -0
  261. package/src/demo/components/form/Search.tsx +36 -0
  262. package/src/demo/components/form/TextArea.tsx +12 -0
  263. package/src/demo/components/form/Toggle.tsx +1 -1
  264. package/src/demo/components/layout/list/Inset.tsx +24 -0
  265. package/src/demo/components/layout/list/Selection.tsx +17 -0
  266. package/src/demo/components/ui/button/ButtonDemo.tsx +9 -5
  267. package/src/demo/components/ui/modal/Modal.tsx +110 -0
  268. package/src/demo/components/ui/toaster/Toaster.tsx +28 -0
  269. package/src/demo/componentsMap.ts +64 -11
  270. package/src/global.scss +4 -0
  271. package/src/index.ts +7 -0
  272. package/src/types.ts +1 -1
@@ -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,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
+ }
@@ -0,0 +1,101 @@
1
+ import React, { createContext, useContext } from "react";
2
+
3
+ import type { Toast } from "./types";
4
+ // eslint-disable-next-line @typescript-eslint/no-shadow
5
+ import { Notification } from "./Notification";
6
+
7
+ type ToasterFn = (text: string) => void;
8
+
9
+ const ToasterContext = createContext<ToasterFn>(() => {
10
+ throw new Error("Toaster Provider missing in the tree");
11
+ });
12
+
13
+ const prefix = `${Date.now()}_`;
14
+ let counter = 0;
15
+
16
+ interface Props {}
17
+ interface State {
18
+ list: Toast[];
19
+ }
20
+
21
+ const DEFAULT_TIMEOUT = 5000;
22
+
23
+ class ToasterProvider extends React.Component<Props, State> {
24
+ public constructor(props: Props, context: unknown) {
25
+ super(props, context);
26
+
27
+ this.state = {
28
+ list: [],
29
+ };
30
+ }
31
+
32
+ private readonly _add = (text: string) => {
33
+ this._removeAllToasts();
34
+
35
+ const id = prefix + String(counter++);
36
+ const hide = false;
37
+
38
+ this.setState(prev => ({
39
+ ...prev,
40
+ list: [...prev.list, {
41
+ id,
42
+ text,
43
+ hide,
44
+ }],
45
+ }));
46
+
47
+ setTimeout(() => {
48
+ this.setState(prev => ({
49
+ ...prev,
50
+ list: prev.list.map(p => {
51
+ if (p.id !== id) {
52
+ return p;
53
+ }
54
+ return {
55
+ ...p,
56
+ hide: true,
57
+ };
58
+ }),
59
+ }));
60
+ }, DEFAULT_TIMEOUT);
61
+ };
62
+
63
+ private readonly _handleRemove = (id: Toast["id"]) => {
64
+ this.setState(prev => ({
65
+ ...prev,
66
+ list: prev.list.filter(p => p.id !== id),
67
+ }));
68
+ };
69
+
70
+ private readonly _removeAllToasts = () => {
71
+ this.setState(prev => ({
72
+ ...prev,
73
+ list: prev.list.map(p => {
74
+ if (p.hide) {
75
+ return p;
76
+ }
77
+ return {
78
+ ...p,
79
+ hide: true,
80
+ };
81
+ }),
82
+ }));
83
+ };
84
+
85
+ public render() {
86
+ const notifications = this.state.list.map((t) => {
87
+ return <Notification onRemove={this._handleRemove} key={t.id} toast={t} />;
88
+ });
89
+
90
+ return (
91
+ <ToasterContext.Provider value={this._add}>
92
+ {notifications}
93
+ {this.props.children}
94
+ </ToasterContext.Provider>
95
+ );
96
+ }
97
+ }
98
+
99
+ const useToaster = () => useContext(ToasterContext);
100
+
101
+ export { ToasterProvider, useToaster };
@@ -0,0 +1,9 @@
1
+ interface Toast {
2
+ id: string;
3
+ text: string;
4
+ hide: boolean;
5
+ }
6
+
7
+ export type {
8
+ Toast,
9
+ };
package/src/demo/Demo.tsx CHANGED
@@ -4,13 +4,16 @@ import styles from "./Demo.module.scss";
4
4
  import { Menu } from "./Menu";
5
5
  import { Main } from "./Main";
6
6
  import { componentsMap } from "./componentsMap";
7
+ import { ToasterProvider } from "../components/ui/toaster/Toaster";
7
8
 
8
9
  const Demo: React.FC = (props) => {
9
10
  return (
10
- <div className={styles.container}>
11
- <Menu list={componentsMap} />
12
- <Main />
13
- </div>
11
+ <ToasterProvider>
12
+ <div className={styles.container}>
13
+ <Menu list={componentsMap} />
14
+ <Main />
15
+ </div>
16
+ </ToasterProvider>
14
17
  );
15
18
  };
16
19
 
@@ -2,6 +2,7 @@
2
2
  margin: 0;
3
3
  padding: 0;
4
4
  border-right: 1px solid black;
5
+ overflow: auto;
5
6
 
6
7
  ul {
7
8
  margin: 0 0 0 15px;
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ import { Section } from "../../../components/layout/section/Section";
3
+ import { SectionContainer } from "../../../components/layout/section/SectionContainer";
4
+ import { Input } from "../../../components/form/Input";
5
+ import { Label } from "../../../components/form/Label";
6
+ import { Button } from "../../../components/ui/button/Button";
7
+ import { TextArea } from "../../../components/form/TextArea";
8
+
9
+ // @TODO add checkbox
10
+ // @TODO add toggle
11
+ // @TODO some kind of `form` wrapper which also takes cares of margins?
12
+ const FormDemo = () => {
13
+ return (
14
+ <SectionContainer>
15
+ <Section>
16
+ <Section variant={["vertical", "horizontal"]}>
17
+ <Label label={"First name"}>
18
+ <Input placeholder={""} />
19
+ </Label>
20
+ <Label label={"E-mail"}>
21
+ <Input placeholder={"Don't forget the @"} suffix={".com"} />
22
+ </Label>
23
+ <Label label={"Your story"}>
24
+ <TextArea placeholder={"Hello"} />
25
+ </Label>
26
+ <Label>
27
+ <Button>Submit</Button>
28
+ </Label>
29
+ </Section>
30
+ </Section>
31
+ </SectionContainer>
32
+ );
33
+ };
34
+
35
+ export { FormDemo };
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import { Input } from "../../../components/form/Input";
3
+ import { ICON, Icon } from "../../../components/icons/Icon";
4
+
5
+ const InputDemo: React.FC = () => {
6
+ return (
7
+ <>
8
+ <Input placeholder={"Capacity"} prefix={<Icon name={ICON.battery} />} suffix={"kWh"} />
9
+ </>
10
+ );
11
+ };
12
+
13
+ export { InputDemo };
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import { Label } from "../../../components/form/Label";
3
+ import { Input } from "../../../components/form/Input";
4
+ import { ICON, Icon } from "../../../components/icons/Icon";
5
+
6
+ const LabelDemo = () => {
7
+ return (
8
+ <Label label={"Capacity"}>
9
+ <Input placeholder={"ie: 500"} prefix={<Icon name={ICON.battery} />} suffix={"kWh"} />
10
+ </Label>
11
+ );
12
+ };
13
+
14
+ export { LabelDemo };
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import { SearchContainer } from "../../../components/layout/section/SearchContainer";
3
+ import { Input } from "../../../components/form/Input";
4
+ import { ICON, Icon } from "../../../components/icons/Icon";
5
+ import { Section } from "../../../components/layout/section/Section";
6
+ import { SectionContainer } from "../../../components/layout/section/SectionContainer";
7
+ import { List } from "../../../components/layout/list/List";
8
+ import { Item } from "../../../components/layout/list/Item";
9
+
10
+ const SearchDemo = () => {
11
+ return (
12
+ <SectionContainer>
13
+ <SearchContainer>
14
+ <Input placeholder={"Search..."} prefix={<Icon name={ICON.search} />} />
15
+ </SearchContainer>
16
+ <Section>
17
+ <List>
18
+ <List.Header>Messages</List.Header>
19
+ <Item>Lorem</Item>
20
+ <Item>Ipsum</Item>
21
+ <Item>Dolor</Item>
22
+ </List>
23
+ </Section>
24
+ <Section>
25
+ <List>
26
+ <List.Header>Contacts</List.Header>
27
+ <Item>Lorem</Item>
28
+ <Item>Ipsum</Item>
29
+ <Item>Dolor</Item>
30
+ </List>
31
+ </Section>
32
+ </SectionContainer>
33
+ );
34
+ };
35
+
36
+ export { SearchDemo };
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { TextArea } from "../../../components/form/TextArea";
3
+
4
+ const TextAreaDemo: React.FC = () => {
5
+ return (
6
+ <>
7
+ <TextArea placeholder={"Capacity"} />
8
+ </>
9
+ );
10
+ };
11
+
12
+ export { TextAreaDemo };
@@ -5,7 +5,7 @@ import { Item } from "../../../components/layout/list/Item";
5
5
 
6
6
  const handleNoop = () => undefined;
7
7
 
8
- const ToggleDemo: React.VFC = () => {
8
+ const ToggleDemo: React.FC = () => {
9
9
  const [state, ss] = useState<boolean | null>(null);
10
10
 
11
11
  useEffect(() => {
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { List } from "../../../../components/layout/list/List";
3
+ import { Item } from "../../../../components/layout/list/Item";
4
+ import { Header } from "../../../../components/layout/list/Header";
5
+
6
+ const ListInsetDemo = () => {
7
+ return (
8
+ <List variant={"inset"}>
9
+ <Header>Section name</Header>
10
+ <Item>Item</Item>
11
+ <Item>Another item</Item>
12
+ <Item>One more</Item>
13
+ <Header>Status section</Header>
14
+ <Item>Item</Item>
15
+ <Item>One more</Item>
16
+ <Header>Selection</Header>
17
+ <Item>Item</Item>
18
+ <Item>Another item</Item>
19
+ <Item>One more</Item>
20
+ </List>
21
+ );
22
+ };
23
+
24
+ export { ListInsetDemo };
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { List } from "../../../../components/layout/list/List";
3
+ import { Item } from "../../../../components/layout/list/Item";
4
+ import { Header } from "../../../../components/layout/list/Header";
5
+
6
+ const ListSelectionDemo = () => {
7
+ return (
8
+ <List>
9
+ <Header>Select your favourite meal</Header>
10
+ <Item selected={false}>Stick</Item>
11
+ <Item selected={true}>Stone</Item>
12
+ <Item selected={false}>Bone</Item>
13
+ </List>
14
+ );
15
+ };
16
+
17
+ export { ListSelectionDemo };
@@ -1,16 +1,20 @@
1
- import React from "react";
1
+ import React, { useCallback } from "react";
2
2
  import { Button } from "../../../../index.js";
3
3
 
4
4
  const ButtonDemo = () => {
5
+ const handleClick = useCallback(() => {
6
+ alert("Clicked");
7
+ }, []);
8
+
5
9
  return (
6
10
  <div>
7
- <Button>Basic button</Button>
11
+ <Button onClick={handleClick}>Basic button</Button>
8
12
  <br />
9
- <Button disabled={true}>Disabled button</Button>
13
+ <Button disabled={true} onClick={handleClick}>Disabled button</Button>
10
14
  <br />
11
- <Button variant={"inline"}>Inline button</Button>
15
+ <Button variant={"inline"} onClick={handleClick}>Inline button</Button>
12
16
  <br />
13
- <Button variant={"outline"}>Outline button</Button>
17
+ <Button variant={"outline"} onClick={handleClick}>Outline button</Button>
14
18
  </div>
15
19
  );
16
20
  };