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.
- package/CHANGELOG.md +30 -0
- package/assets/sources/battery.fla +0 -0
- package/assets/sources/search.fla +0 -0
- package/dist/components/form/Input.d.ts +9 -0
- package/dist/components/form/Input.d.ts.map +1 -0
- package/dist/components/form/Input.js +62 -0
- package/dist/components/form/Input.js.map +1 -0
- package/dist/components/form/Input.module.scss +48 -0
- package/dist/components/form/Label.d.ts +8 -0
- package/dist/components/form/Label.d.ts.map +1 -0
- package/dist/components/form/Label.js +22 -0
- package/dist/components/form/Label.js.map +1 -0
- package/dist/components/form/Label.module.scss +15 -0
- package/dist/components/form/TextArea.d.ts +7 -0
- package/dist/components/form/TextArea.d.ts.map +1 -0
- package/dist/components/form/TextArea.js +57 -0
- package/dist/components/form/TextArea.js.map +1 -0
- package/dist/components/form/Toggle.d.ts +1 -1
- package/dist/components/form/Toggle.d.ts.map +1 -1
- package/dist/components/form/Toggle.js.map +1 -1
- package/dist/components/icons/Back.d.ts +1 -1
- package/dist/components/icons/Back.d.ts.map +1 -1
- package/dist/components/icons/Back.js.map +1 -1
- package/dist/components/icons/Battery.d.ts +7 -0
- package/dist/components/icons/Battery.d.ts.map +1 -0
- package/dist/components/icons/Battery.js +14 -0
- package/dist/components/icons/Battery.js.map +1 -0
- package/dist/components/icons/Forward.d.ts +1 -1
- package/dist/components/icons/Forward.d.ts.map +1 -1
- package/dist/components/icons/Forward.js.map +1 -1
- package/dist/components/icons/Icon.d.ts +3 -1
- package/dist/components/icons/Icon.d.ts.map +1 -1
- package/dist/components/icons/Icon.js +6 -0
- package/dist/components/icons/Icon.js.map +1 -1
- package/dist/components/icons/Search.d.ts +7 -0
- package/dist/components/icons/Search.d.ts.map +1 -0
- package/dist/components/icons/Search.js +13 -0
- package/dist/components/icons/Search.js.map +1 -0
- package/dist/components/layout/header/HeaderIconAction.d.ts +1 -1
- package/dist/components/layout/header/HeaderIconAction.d.ts.map +1 -1
- package/dist/components/layout/header/HeaderIconAction.js.map +1 -1
- package/dist/components/layout/list/Header.d.ts +5 -1
- package/dist/components/layout/list/Header.d.ts.map +1 -1
- package/dist/components/layout/list/Header.js +6 -1
- package/dist/components/layout/list/Header.js.map +1 -1
- package/dist/components/layout/list/Item.d.ts +3 -0
- package/dist/components/layout/list/Item.d.ts.map +1 -1
- package/dist/components/layout/list/Item.js +20 -6
- package/dist/components/layout/list/Item.js.map +1 -1
- package/dist/components/layout/list/Item.module.scss +16 -1
- package/dist/components/layout/list/List.d.ts +6 -1
- package/dist/components/layout/list/List.d.ts.map +1 -1
- package/dist/components/layout/list/List.js +15 -1
- package/dist/components/layout/list/List.js.map +1 -1
- package/dist/components/layout/list/List.module.scss +4 -0
- package/dist/components/layout/section/SearchContainer.d.ts +4 -0
- package/dist/components/layout/section/SearchContainer.d.ts.map +1 -0
- package/dist/components/layout/section/SearchContainer.js +13 -0
- package/dist/components/layout/section/SearchContainer.js.map +1 -0
- package/dist/components/layout/section/SearchContainer.module.scss +3 -0
- package/dist/components/layout/section/Section.module.scss +7 -0
- package/dist/components/ui/action/Action.d.ts +1 -1
- package/dist/components/ui/action/Action.d.ts.map +1 -1
- package/dist/components/ui/action/Action.js.map +1 -1
- package/dist/components/ui/button/Button.d.ts +1 -2
- package/dist/components/ui/button/Button.d.ts.map +1 -1
- package/dist/components/ui/button/Button.js +16 -4
- package/dist/components/ui/button/Button.js.map +1 -1
- package/dist/components/ui/modal/Modal.d.ts +18 -0
- package/dist/components/ui/modal/Modal.d.ts.map +1 -0
- package/dist/components/ui/modal/Modal.js +108 -0
- package/dist/components/ui/modal/Modal.js.map +1 -0
- package/dist/components/ui/modal/Modal.module.scss +92 -0
- package/dist/components/ui/modal/ModalButton.d.ts +8 -0
- package/dist/components/ui/modal/ModalButton.d.ts.map +1 -0
- package/dist/components/ui/modal/ModalButton.js +31 -0
- package/dist/components/ui/modal/ModalButton.js.map +1 -0
- package/dist/components/ui/modal/ModalButtons.d.ts +10 -0
- package/dist/components/ui/modal/ModalButtons.d.ts.map +1 -0
- package/dist/components/ui/modal/ModalButtons.js +15 -0
- package/dist/components/ui/modal/ModalButtons.js.map +1 -0
- package/dist/components/ui/modal/ModalButtons.module.scss +32 -0
- package/dist/components/ui/modal/ModalNoMargin.d.ts +6 -0
- package/dist/components/ui/modal/ModalNoMargin.d.ts.map +1 -0
- package/dist/components/ui/modal/ModalNoMargin.js +22 -0
- package/dist/components/ui/modal/ModalNoMargin.js.map +1 -0
- package/dist/components/ui/toaster/Notification.d.ts +9 -0
- package/dist/components/ui/toaster/Notification.d.ts.map +1 -0
- package/dist/components/ui/toaster/Notification.js +39 -0
- package/dist/components/ui/toaster/Notification.js.map +1 -0
- package/dist/components/ui/toaster/Toaster.d.ts +18 -0
- package/dist/components/ui/toaster/Toaster.d.ts.map +1 -0
- package/dist/components/ui/toaster/Toaster.js +79 -0
- package/dist/components/ui/toaster/Toaster.js.map +1 -0
- package/dist/components/ui/toaster/Toaster.module.scss +32 -0
- package/dist/components/ui/toaster/types.d.ts +7 -0
- package/dist/components/ui/toaster/types.d.ts.map +1 -0
- package/dist/components/ui/toaster/types.js +3 -0
- package/dist/components/ui/toaster/types.js.map +1 -0
- package/dist/global.scss +4 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/assets/js/search.json +1 -1
- package/docs/classes/ToasterProvider.html +1090 -0
- package/docs/enums/ICON.html +65 -6
- package/docs/index.html +41 -4
- package/docs/modules/Item.html +16 -3
- package/docs/modules/List.html +17 -4
- package/docs/modules/Modal.html +160 -0
- package/docs/modules/ModalButtons.html +160 -0
- package/docs/modules/Section.html +16 -3
- package/docs/modules/StickyHeader.html +17 -4
- package/docs/modules.html +160 -23
- package/docs/pages/Tutorials/Test.html +16 -3
- package/esm/components/form/Input.d.ts +9 -0
- package/esm/components/form/Input.d.ts.map +1 -0
- package/esm/components/form/Input.js +25 -0
- package/esm/components/form/Input.js.map +1 -0
- package/esm/components/form/Input.module.scss +48 -0
- package/esm/components/form/Label.d.ts +8 -0
- package/esm/components/form/Label.d.ts.map +1 -0
- package/esm/components/form/Label.js +16 -0
- package/esm/components/form/Label.js.map +1 -0
- package/esm/components/form/Label.module.scss +15 -0
- package/esm/components/form/TextArea.d.ts +7 -0
- package/esm/components/form/TextArea.d.ts.map +1 -0
- package/esm/components/form/TextArea.js +20 -0
- package/esm/components/form/TextArea.js.map +1 -0
- package/esm/components/form/Toggle.d.ts +1 -1
- package/esm/components/form/Toggle.d.ts.map +1 -1
- package/esm/components/form/Toggle.js.map +1 -1
- package/esm/components/icons/Back.d.ts +1 -1
- package/esm/components/icons/Back.d.ts.map +1 -1
- package/esm/components/icons/Back.js.map +1 -1
- package/esm/components/icons/Battery.d.ts +7 -0
- package/esm/components/icons/Battery.d.ts.map +1 -0
- package/esm/components/icons/Battery.js +8 -0
- package/esm/components/icons/Battery.js.map +1 -0
- package/esm/components/icons/Forward.d.ts +1 -1
- package/esm/components/icons/Forward.d.ts.map +1 -1
- package/esm/components/icons/Forward.js.map +1 -1
- package/esm/components/icons/Icon.d.ts +3 -1
- package/esm/components/icons/Icon.d.ts.map +1 -1
- package/esm/components/icons/Icon.js +6 -0
- package/esm/components/icons/Icon.js.map +1 -1
- package/esm/components/icons/Search.d.ts +7 -0
- package/esm/components/icons/Search.d.ts.map +1 -0
- package/esm/components/icons/Search.js +7 -0
- package/esm/components/icons/Search.js.map +1 -0
- package/esm/components/layout/header/HeaderIconAction.d.ts +1 -1
- package/esm/components/layout/header/HeaderIconAction.d.ts.map +1 -1
- package/esm/components/layout/header/HeaderIconAction.js.map +1 -1
- package/esm/components/layout/list/Header.d.ts +5 -1
- package/esm/components/layout/list/Header.d.ts.map +1 -1
- package/esm/components/layout/list/Header.js +6 -1
- package/esm/components/layout/list/Header.js.map +1 -1
- package/esm/components/layout/list/Item.d.ts +3 -0
- package/esm/components/layout/list/Item.d.ts.map +1 -1
- package/esm/components/layout/list/Item.js +20 -6
- package/esm/components/layout/list/Item.js.map +1 -1
- package/esm/components/layout/list/Item.module.scss +16 -1
- package/esm/components/layout/list/List.d.ts +6 -1
- package/esm/components/layout/list/List.d.ts.map +1 -1
- package/esm/components/layout/list/List.js +15 -1
- package/esm/components/layout/list/List.js.map +1 -1
- package/esm/components/layout/list/List.module.scss +4 -0
- package/esm/components/layout/section/SearchContainer.d.ts +4 -0
- package/esm/components/layout/section/SearchContainer.d.ts.map +1 -0
- package/esm/components/layout/section/SearchContainer.js +7 -0
- package/esm/components/layout/section/SearchContainer.js.map +1 -0
- package/esm/components/layout/section/SearchContainer.module.scss +3 -0
- package/esm/components/layout/section/Section.module.scss +7 -0
- package/esm/components/ui/action/Action.d.ts +1 -1
- package/esm/components/ui/action/Action.d.ts.map +1 -1
- package/esm/components/ui/action/Action.js.map +1 -1
- package/esm/components/ui/button/Button.d.ts +1 -2
- package/esm/components/ui/button/Button.d.ts.map +1 -1
- package/esm/components/ui/button/Button.js +4 -4
- package/esm/components/ui/button/Button.js.map +1 -1
- package/esm/components/ui/modal/Modal.d.ts +18 -0
- package/esm/components/ui/modal/Modal.d.ts.map +1 -0
- package/esm/components/ui/modal/Modal.js +83 -0
- package/esm/components/ui/modal/Modal.js.map +1 -0
- package/esm/components/ui/modal/Modal.module.scss +92 -0
- package/esm/components/ui/modal/ModalButton.d.ts +8 -0
- package/esm/components/ui/modal/ModalButton.d.ts.map +1 -0
- package/esm/components/ui/modal/ModalButton.js +13 -0
- package/esm/components/ui/modal/ModalButton.js.map +1 -0
- package/esm/components/ui/modal/ModalButtons.d.ts +10 -0
- package/esm/components/ui/modal/ModalButtons.d.ts.map +1 -0
- package/esm/components/ui/modal/ModalButtons.js +9 -0
- package/esm/components/ui/modal/ModalButtons.js.map +1 -0
- package/esm/components/ui/modal/ModalButtons.module.scss +32 -0
- package/esm/components/ui/modal/ModalNoMargin.d.ts +6 -0
- package/esm/components/ui/modal/ModalNoMargin.d.ts.map +1 -0
- package/esm/components/ui/modal/ModalNoMargin.js +16 -0
- package/esm/components/ui/modal/ModalNoMargin.js.map +1 -0
- package/esm/components/ui/toaster/Notification.d.ts +9 -0
- package/esm/components/ui/toaster/Notification.d.ts.map +1 -0
- package/esm/components/ui/toaster/Notification.js +14 -0
- package/esm/components/ui/toaster/Notification.js.map +1 -0
- package/esm/components/ui/toaster/Toaster.d.ts +18 -0
- package/esm/components/ui/toaster/Toaster.d.ts.map +1 -0
- package/esm/components/ui/toaster/Toaster.js +74 -0
- package/esm/components/ui/toaster/Toaster.js.map +1 -0
- package/esm/components/ui/toaster/Toaster.module.scss +32 -0
- package/esm/components/ui/toaster/types.d.ts +7 -0
- package/esm/components/ui/toaster/types.d.ts.map +1 -0
- package/esm/components/ui/toaster/types.js +2 -0
- package/esm/components/ui/toaster/types.js.map +1 -0
- package/esm/global.scss +4 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +7 -0
- package/esm/index.js.map +1 -1
- package/esm/types.d.ts +1 -1
- package/esm/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/form/Input.module.scss +48 -0
- package/src/components/form/Input.tsx +48 -0
- package/src/components/form/Label.module.scss +15 -0
- package/src/components/form/Label.tsx +29 -0
- package/src/components/form/TextArea.tsx +38 -0
- package/src/components/form/Toggle.tsx +1 -1
- package/src/components/icons/Back.tsx +1 -1
- package/src/components/icons/Battery.tsx +34 -0
- package/src/components/icons/Forward.tsx +1 -1
- package/src/components/icons/Icon.tsx +6 -0
- package/src/components/icons/Search.tsx +29 -0
- package/src/components/layout/header/HeaderIconAction.tsx +1 -1
- package/src/components/layout/list/Header.tsx +15 -2
- package/src/components/layout/list/Item.module.scss +16 -1
- package/src/components/layout/list/Item.tsx +28 -7
- package/src/components/layout/list/List.module.scss +4 -0
- package/src/components/layout/list/List.tsx +29 -2
- package/src/components/layout/section/SearchContainer.module.scss +3 -0
- package/src/components/layout/section/SearchContainer.tsx +11 -0
- package/src/components/layout/section/Section.module.scss +7 -0
- package/src/components/ui/action/Action.tsx +1 -1
- package/src/components/ui/button/Button.tsx +11 -5
- package/src/components/ui/modal/Modal.module.scss +92 -0
- package/src/components/ui/modal/Modal.tsx +136 -0
- package/src/components/ui/modal/ModalButton.tsx +25 -0
- package/src/components/ui/modal/ModalButtons.module.scss +32 -0
- package/src/components/ui/modal/ModalButtons.tsx +17 -0
- package/src/components/ui/modal/ModalNoMargin.tsx +22 -0
- package/src/components/ui/toaster/Notification.tsx +31 -0
- package/src/components/ui/toaster/Toaster.module.scss +32 -0
- package/src/components/ui/toaster/Toaster.tsx +101 -0
- package/src/components/ui/toaster/types.ts +9 -0
- package/src/demo/Demo.tsx +7 -4
- package/src/demo/Menu.module.scss +1 -0
- package/src/demo/components/form/Form.tsx +35 -0
- package/src/demo/components/form/Input.tsx +13 -0
- package/src/demo/components/form/Label.tsx +14 -0
- package/src/demo/components/form/Search.tsx +36 -0
- package/src/demo/components/form/TextArea.tsx +12 -0
- package/src/demo/components/form/Toggle.tsx +1 -1
- package/src/demo/components/layout/list/Inset.tsx +24 -0
- package/src/demo/components/layout/list/Selection.tsx +17 -0
- package/src/demo/components/ui/button/ButtonDemo.tsx +9 -5
- package/src/demo/components/ui/modal/Modal.tsx +110 -0
- package/src/demo/components/ui/toaster/Toaster.tsx +28 -0
- package/src/demo/componentsMap.ts +64 -11
- package/src/global.scss +4 -0
- package/src/index.ts +7 -0
- 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 };
|
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
|
-
<
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
<ToasterProvider>
|
|
12
|
+
<div className={styles.container}>
|
|
13
|
+
<Menu list={componentsMap} />
|
|
14
|
+
<Main />
|
|
15
|
+
</div>
|
|
16
|
+
</ToasterProvider>
|
|
14
17
|
);
|
|
15
18
|
};
|
|
16
19
|
|
|
@@ -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,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
|
};
|