@uxf/ui 1.0.0-beta.113 → 1.0.0-beta.115
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/css/modal.css +69 -0
- package/modal/modal-dialog.d.ts +10 -0
- package/modal/modal-dialog.js +38 -0
- package/modal/modal-service.d.ts +5 -0
- package/modal/modal-service.js +21 -0
- package/modal/modal.d.ts +13 -0
- package/modal/modal.js +51 -0
- package/modal/modal.stories.d.ts +7 -0
- package/modal/modal.stories.js +38 -0
- package/modal/theme.d.ts +5 -0
- package/modal/theme.js +2 -0
- package/package.json +1 -1
package/css/modal.css
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
.uxf-modal {
|
|
2
|
+
position: relative;
|
|
3
|
+
z-index: theme("zIndex.modal");
|
|
4
|
+
|
|
5
|
+
&__backdrop {
|
|
6
|
+
position: fixed;
|
|
7
|
+
left: 0;
|
|
8
|
+
right: 0;
|
|
9
|
+
top: 0;
|
|
10
|
+
bottom: 0;
|
|
11
|
+
background-color: rgb(0 0 0 / 75%);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&__wrapper {
|
|
15
|
+
position: fixed;
|
|
16
|
+
left: 0;
|
|
17
|
+
right: 0;
|
|
18
|
+
top: 0;
|
|
19
|
+
bottom: 0;
|
|
20
|
+
overflow-y: auto;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&__body {
|
|
24
|
+
display: flex;
|
|
25
|
+
min-height: 100%;
|
|
26
|
+
align-items: flex-end;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
padding-top: theme("spacing.4");
|
|
29
|
+
|
|
30
|
+
@media screen(sm) {
|
|
31
|
+
align-items: center;
|
|
32
|
+
padding: theme("spacing.4");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&__panel {
|
|
37
|
+
position: relative;
|
|
38
|
+
width: 100%;
|
|
39
|
+
border-top-left-radius: theme("borderRadius.2xl");
|
|
40
|
+
border-top-right-radius: theme("borderRadius.2xl");
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
|
|
43
|
+
:root .light & {
|
|
44
|
+
background-color: theme("colors.white");
|
|
45
|
+
color: theme("colors.black");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:root .dark & {
|
|
49
|
+
background-color: theme("colors.gray.900");
|
|
50
|
+
color: theme("colors.white");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@media screen(sm) {
|
|
54
|
+
border-radius: theme("borderRadius.2xl");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&--width-sm .uxf-modal__panel {
|
|
59
|
+
max-width: theme("maxWidth.sm");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&--width-default .uxf-modal__panel {
|
|
63
|
+
max-width: theme("maxWidth.lg");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&--width-lg .uxf-modal__panel {
|
|
67
|
+
max-width: theme("maxWidth.3xl");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { ModalWidths } from "@uxf/ui/modal/theme";
|
|
3
|
+
export interface ModalDialogProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
open: boolean;
|
|
7
|
+
width?: keyof ModalWidths;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const ModalDialog: React.NamedExoticComponent<ModalDialogProps>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ModalDialog = void 0;
|
|
27
|
+
const react_1 = require("@headlessui/react");
|
|
28
|
+
const cx_1 = require("@uxf/core/utils/cx");
|
|
29
|
+
const react_2 = __importStar(require("react"));
|
|
30
|
+
exports.ModalDialog = (0, react_2.memo)((props) => {
|
|
31
|
+
var _a;
|
|
32
|
+
return (react_2.default.createElement(react_1.Dialog, { className: (0, cx_1.cx)("uxf-modal", "uxf-modal--width-" + ((_a = props.width) !== null && _a !== void 0 ? _a : "default"), props.className), open: props.open, onClose: props.onClose },
|
|
33
|
+
react_2.default.createElement(react_1.Dialog.Overlay, { className: "uxf-modal__backdrop" }),
|
|
34
|
+
react_2.default.createElement("div", { className: "uxf-modal__wrapper" },
|
|
35
|
+
react_2.default.createElement("div", { className: "uxf-modal__body" },
|
|
36
|
+
react_2.default.createElement(react_1.Dialog.Panel, { className: "uxf-modal__panel" }, props.children)))));
|
|
37
|
+
});
|
|
38
|
+
exports.ModalDialog.displayName = "ModalDialog";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.closeModal = exports.openModal = exports.getModalRef = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const modalRef = (0, react_1.createRef)();
|
|
6
|
+
function getModalRef() {
|
|
7
|
+
return modalRef;
|
|
8
|
+
}
|
|
9
|
+
exports.getModalRef = getModalRef;
|
|
10
|
+
function openModal(modal) {
|
|
11
|
+
if (modalRef.current) {
|
|
12
|
+
modalRef.current.open(modal);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.openModal = openModal;
|
|
16
|
+
function closeModal() {
|
|
17
|
+
if (modalRef.current) {
|
|
18
|
+
modalRef.current.close();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.closeModal = closeModal;
|
package/modal/modal.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import type { ModalDialogProps } from "./modal-dialog";
|
|
3
|
+
export interface ModalProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
width?: ModalDialogProps["width"];
|
|
7
|
+
className?: ModalDialogProps["className"];
|
|
8
|
+
}
|
|
9
|
+
export interface ModalRef {
|
|
10
|
+
close: () => void;
|
|
11
|
+
open: (modal: ModalProps) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const Modal: React.ForwardRefExoticComponent<React.RefAttributes<ModalRef>>;
|
package/modal/modal.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Modal = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const modal_dialog_1 = require("./modal-dialog");
|
|
29
|
+
exports.Modal = (0, react_1.forwardRef)((props, ref) => {
|
|
30
|
+
const [modal, setModal] = (0, react_1.useState)();
|
|
31
|
+
const open = (0, react_1.useCallback)((newModal) => setModal(newModal), []);
|
|
32
|
+
const close = (0, react_1.useCallback)(() => setModal(null), []);
|
|
33
|
+
const innerRef = (0, react_1.useRef)({
|
|
34
|
+
close,
|
|
35
|
+
open,
|
|
36
|
+
});
|
|
37
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
38
|
+
close: innerRef.current.close,
|
|
39
|
+
open: innerRef.current.open,
|
|
40
|
+
}), []);
|
|
41
|
+
const onClose = (0, react_1.useCallback)(() => {
|
|
42
|
+
setModal((prev) => {
|
|
43
|
+
if (prev === null || prev === void 0 ? void 0 : prev.onClose) {
|
|
44
|
+
prev.onClose();
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
});
|
|
48
|
+
}, []);
|
|
49
|
+
return modal ? (react_1.default.createElement(modal_dialog_1.ModalDialog, { open: !!modal, onClose: onClose, width: modal.width, className: modal.className }, modal.children)) : null;
|
|
50
|
+
});
|
|
51
|
+
exports.Modal.displayName = "Modal";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Default = void 0;
|
|
7
|
+
const button_1 = require("@uxf/ui/button");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const modal_1 = require("./modal");
|
|
10
|
+
const modal_service_1 = require("./modal-service");
|
|
11
|
+
exports.default = {
|
|
12
|
+
title: "UI/Modal",
|
|
13
|
+
component: modal_1.Modal,
|
|
14
|
+
};
|
|
15
|
+
function Default() {
|
|
16
|
+
const storyModals = (react_1.default.createElement("div", { className: "light inline-flex flex-col space-y-4" },
|
|
17
|
+
react_1.default.createElement(button_1.Button, { onClick: () => (0, modal_service_1.openModal)({
|
|
18
|
+
children: (react_1.default.createElement("div", { className: "p-4" },
|
|
19
|
+
react_1.default.createElement("p", { className: "mb-3 text-lg font-bold" }, "Modal - default size"),
|
|
20
|
+
react_1.default.createElement(button_1.Button, { isFullWidth: true, onClick: modal_service_1.closeModal }, "Close modal"))),
|
|
21
|
+
}) }, "Click to open modal - default"),
|
|
22
|
+
react_1.default.createElement(button_1.Button, { onClick: () => (0, modal_service_1.openModal)({
|
|
23
|
+
children: (react_1.default.createElement("div", { className: "p-4" },
|
|
24
|
+
react_1.default.createElement("p", { className: "mb-3 text-lg font-bold" }, "Modal - sm size"),
|
|
25
|
+
react_1.default.createElement(button_1.Button, { isFullWidth: true, onClick: modal_service_1.closeModal }, "Close modal"))),
|
|
26
|
+
width: "sm",
|
|
27
|
+
}) }, "Click to open modal - sm"),
|
|
28
|
+
react_1.default.createElement(button_1.Button, { onClick: () => (0, modal_service_1.openModal)({
|
|
29
|
+
children: (react_1.default.createElement("div", { className: "p-4" },
|
|
30
|
+
react_1.default.createElement("p", { className: "mb-3 text-lg font-bold" }, "Modal - lg size"),
|
|
31
|
+
react_1.default.createElement(button_1.Button, { isFullWidth: true, onClick: modal_service_1.closeModal }, "Close modal"))),
|
|
32
|
+
width: "lg",
|
|
33
|
+
}) }, "Click to open modal - lg")));
|
|
34
|
+
return (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
|
|
35
|
+
react_1.default.createElement("div", { className: "light space-y-2 p-20 lg:w-1/2" }, storyModals),
|
|
36
|
+
react_1.default.createElement("div", { className: "dark space-y-2 bg-gray-900 p-20 lg:w-1/2" }, storyModals)));
|
|
37
|
+
}
|
|
38
|
+
exports.Default = Default;
|
package/modal/theme.d.ts
ADDED
package/modal/theme.js
ADDED