@bouku/modal 0.0.1 → 0.0.3

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/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from "./ui/index.js";
2
- export { default as ModalProvider } from "./state/provider";
3
- export { default as useModal } from "./state/context";
1
+ export * from "./state";
2
+ export * from "./ui";
package/dist/index.js CHANGED
@@ -13,13 +13,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.useModal = exports.ModalProvider = void 0;
21
- __exportStar(require("./ui/index.js"), exports);
22
- var provider_1 = require("./state/provider");
23
- Object.defineProperty(exports, "ModalProvider", { enumerable: true, get: function () { return __importDefault(provider_1).default; } });
24
- var context_1 = require("./state/context");
25
- Object.defineProperty(exports, "useModal", { enumerable: true, get: function () { return __importDefault(context_1).default; } });
17
+ __exportStar(require("./state"), exports);
18
+ __exportStar(require("./ui"), exports);
@@ -1,12 +1,15 @@
1
- import { JsonMap } from "ts-helper-kit";
2
- import { ReactNode } from "react";
3
- export type Props = {
4
- activeId?: string;
5
- modal: ReactNode;
6
- parameters: JsonMap;
7
- openModal: (modal: string, params?: JsonMap) => void;
1
+ import { type ComponentType } from "react";
2
+ export type ModalConfig = Record<string, ComponentType<any>>;
3
+ export type RawActive = {
4
+ id: string;
5
+ props: any;
6
+ } | null;
7
+ type ContextValue = {
8
+ active: RawActive;
9
+ openModal: (id: string, props?: any) => void;
8
10
  closeModal: () => void;
9
11
  };
10
- export declare const Context: import("react").Context<Props>;
11
- export declare const useModal: () => Props;
12
- export default useModal;
12
+ export declare const Context: import("react").Context<ContextValue>;
13
+ export declare const useRawModal: () => ContextValue;
14
+ export default function useModal<T extends ModalConfig>(): void;
15
+ export {};
@@ -1,14 +1,15 @@
1
1
  "use client";
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useModal = exports.Context = void 0;
4
+ exports.useRawModal = exports.Context = void 0;
5
+ exports.default = useModal;
5
6
  const react_1 = require("react");
6
7
  exports.Context = (0, react_1.createContext)({
7
- modal: null,
8
- parameters: {},
8
+ active: null,
9
9
  openModal: () => undefined,
10
- closeModal: () => undefined
10
+ closeModal: () => undefined,
11
11
  });
12
- const useModal = () => (0, react_1.useContext)(exports.Context);
13
- exports.useModal = useModal;
14
- exports.default = exports.useModal;
12
+ const useRawModal = () => (0, react_1.useContext)(exports.Context);
13
+ exports.useRawModal = useRawModal;
14
+ function useModal() {
15
+ }
@@ -0,0 +1,20 @@
1
+ import { type ModalConfig } from "./context";
2
+ import type { ComponentProps } from "react";
3
+ type ArgsFor<P> = {} extends P ? [props?: P] : [props: P];
4
+ type ActiveModal<T extends ModalConfig> = {
5
+ [K in keyof T]: {
6
+ id: K;
7
+ props: ComponentProps<T[K]>;
8
+ };
9
+ }[keyof T];
10
+ export declare const createModalSystem: <T extends ModalConfig>(config: T) => {
11
+ ModalProvider: (props: {
12
+ children: React.ReactNode;
13
+ }) => import("react/jsx-runtime").JSX.Element;
14
+ useModal: () => {
15
+ active: ActiveModal<T> | null;
16
+ openModal: <K extends keyof T>(id: K, ...args: ArgsFor<ComponentProps<T[K]>>) => void;
17
+ closeModal: () => void;
18
+ };
19
+ };
20
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createModalSystem = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const provider_1 = require("./provider");
6
+ const context_1 = require("./context");
7
+ const createModalSystem = (config) => ({
8
+ ModalProvider: (props) => ((0, jsx_runtime_1.jsx)(provider_1.ModalProvider, { config: config, ...props })),
9
+ useModal: () => {
10
+ const { active, openModal, closeModal } = (0, context_1.useRawModal)();
11
+ function open(id, ...args) {
12
+ openModal(id, args[0]);
13
+ }
14
+ return {
15
+ active: active, // cast happens only here, at the typed edge
16
+ openModal: open,
17
+ closeModal
18
+ };
19
+ }
20
+ });
21
+ exports.createModalSystem = createModalSystem;
@@ -1,29 +1,6 @@
1
- import type { ReactElement, ReactNode } from "react";
2
- /**
3
- * React Context Provider for Modal component.
4
- *
5
- * Supplies modal state and control functions to its children,
6
- * enabling centralized management of modal configuration, visibility,
7
- * and parameters throughout the app.
8
- *
9
- * Features:
10
- * - Tracks the currently active modal by its key from the `config` object.
11
- * - Stores and provides `parameters` for the active modal instance.
12
- * - Exposes `openModal` and `closeModal` functions for controlling modal state.
13
- * - Passes modal configuration and state to consumers via context value.
14
- * - Renders the `RootModal` component for global modal handling.
15
- *
16
- * @param {Record<string, ReactElement>} config - A map of modal ID keys to the component itself.
17
- * @param {ReactNode} children - Child components that will have access to modals.
18
- **/
19
- export default function ModalProvider({ config, children }: {
20
- config: Record<string, ReactElement>;
1
+ import type { ReactNode } from "react";
2
+ import type { ModalConfig } from "./context";
3
+ export declare function ModalProvider<T extends ModalConfig>({ config, children }: {
4
+ config: T;
21
5
  children: ReactNode;
22
6
  }): import("react/jsx-runtime").JSX.Element;
23
- /**
24
- * Problems:
25
- *
26
- * - Perfect `Context`.
27
- * - Perfect `RootModal`.
28
- * - Perfect `Config`.
29
- **/
@@ -1,47 +1,21 @@
1
1
  "use client";
2
2
  "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
3
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.default = ModalProvider;
4
+ exports.ModalProvider = ModalProvider;
8
5
  const jsx_runtime_1 = require("react/jsx-runtime");
9
6
  const react_1 = require("react");
7
+ const animate_1 = require("@bouku/animate");
10
8
  const context_1 = require("./context");
11
- const root_1 = __importDefault(require("./root"));
12
- /**
13
- * React Context Provider for Modal component.
14
- *
15
- * Supplies modal state and control functions to its children,
16
- * enabling centralized management of modal configuration, visibility,
17
- * and parameters throughout the app.
18
- *
19
- * Features:
20
- * - Tracks the currently active modal by its key from the `config` object.
21
- * - Stores and provides `parameters` for the active modal instance.
22
- * - Exposes `openModal` and `closeModal` functions for controlling modal state.
23
- * - Passes modal configuration and state to consumers via context value.
24
- * - Renders the `RootModal` component for global modal handling.
25
- *
26
- * @param {Record<string, ReactElement>} config - A map of modal ID keys to the component itself.
27
- * @param {ReactNode} children - Child components that will have access to modals.
28
- **/
29
9
  function ModalProvider({ config, children }) {
30
- const [activeModal, setActiveModal] = (0, react_1.useState)();
31
- const [parameters, setParameters] = (0, react_1.useState)({});
32
- const openModal = async (modal, params) => {
33
- setActiveModal(modal);
34
- setParameters(params || {});
35
- };
36
- const closeModal = () => {
37
- setActiveModal(undefined);
38
- setParameters({});
39
- };
40
- return ((0, jsx_runtime_1.jsxs)(context_1.Context.Provider, { value: {
41
- activeId: activeModal,
42
- openModal,
43
- modal: activeModal ? config[activeModal] : null,
44
- parameters,
45
- closeModal
46
- }, children: [children, (0, jsx_runtime_1.jsx)(root_1.default, {})] }));
10
+ const [active, setActive] = (0, react_1.useState)(null);
11
+ const openModal = (id, props) => setActive({ id, props: props ?? {} });
12
+ const closeModal = () => setActive(null);
13
+ const ActiveComponent = active
14
+ ? config[active.id]
15
+ : null;
16
+ return ((0, jsx_runtime_1.jsxs)(context_1.Context.Provider, { value: { active, openModal, closeModal }, children: [children, (0, jsx_runtime_1.jsx)(animate_1.AnimatePresence, { mode: "wait", children: ActiveComponent && ((0, jsx_runtime_1.jsx)(animate_1.Animation, { style: s.backdrop, onClick: closeModal, children: (0, jsx_runtime_1.jsx)("div", { className: s.content, onClick: (e) => e.stopPropagation(), children: (0, jsx_runtime_1.jsx)(ActiveComponent, { ...active.props }) }) }, active.id)) })] }));
47
17
  }
18
+ const s = {
19
+ backdrop: "fixed inset-0 flex justify-center items-center bg-background-light/60 dark:bg-background-dark/60 z-[99]",
20
+ content: "max-w-[80%] max-h-[85%] bg-background border border-border rounded-lg shadow-soft"
21
+ };
@@ -6,6 +6,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const context_1 = require("../../state/context");
7
7
  const core_1 = require("@bouku/core");
8
8
  function ModalButton({ id, params, ...props }) {
9
- const { openModal } = (0, context_1.useModal)();
9
+ const { openModal } = (0, context_1.useRawModal)();
10
10
  return ((0, jsx_runtime_1.jsx)(core_1.Button, { ...props, action: () => openModal(id, params) }));
11
11
  }
@@ -2,6 +2,8 @@ import { ModalProps } from "./normal";
2
2
  import { FormBuilderField, FormData, FormSchema, PresetName } from "@bouku/form";
3
3
  type Props<T extends FormData = FormData, P extends PresetName | undefined = undefined> = {
4
4
  fields: FormBuilderField[][];
5
+ initialData?: Partial<T>;
6
+ submitLabel?: string;
5
7
  validator?: (data: FormSchema<T, P>) => {
6
8
  success: boolean;
7
9
  };
@@ -17,7 +19,7 @@ type Props<T extends FormData = FormData, P extends PresetName | undefined = und
17
19
  * Combines a standard modal layout with a form builder.
18
20
  * Wraps @bouko/form `FormBuilder` for form handling.
19
21
  **/
20
- export declare function FormModal({ style, fields, submit, ...props }: Props): import("react/jsx-runtime").JSX.Element;
22
+ export declare function FormModal({ style, fields, initialData, submitLabel, submit, ...props }: Props): import("react/jsx-runtime").JSX.Element;
21
23
  export default FormModal;
22
24
  /**
23
25
  * Problems:
@@ -10,7 +10,7 @@ const form_1 = require("@bouku/form");
10
10
  * Combines a standard modal layout with a form builder.
11
11
  * Wraps @bouko/form `FormBuilder` for form handling.
12
12
  **/
13
- function FormModal({ style, fields, submit, ...props }) {
14
- return ((0, jsx_runtime_1.jsx)(normal_1.Modal, { ...props, children: (0, jsx_runtime_1.jsx)(form_1.FormBuilder, { style: style, fields: fields, submit: submit }) }));
13
+ function FormModal({ style, fields, initialData, submitLabel, submit, ...props }) {
14
+ return ((0, jsx_runtime_1.jsx)(normal_1.Modal, { ...props, children: (0, jsx_runtime_1.jsx)(form_1.FormBuilder, { style: style, fields: fields, initialData: initialData, submitLabel: submitLabel, submit: submit }) }));
15
15
  }
16
16
  exports.default = FormModal;
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Modal = Modal;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const context_1 = require("../../state/context");
9
- const style_1 = require("@bouko/style");
9
+ const core_1 = require("@bouku/core");
10
10
  const x_svg_1 = __importDefault(require("../../assets/icons/x.svg"));
11
11
  function Modal({ style, title, subtitle, redirect, children }) {
12
- const { openModal, closeModal } = (0, context_1.useModal)();
13
- return ((0, jsx_runtime_1.jsxs)("div", { className: (0, style_1.cn)(styles.container, style), role: "dialog", "aria-modal": "true", children: [(0, jsx_runtime_1.jsxs)("div", { className: styles.header, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles.heading, children: [(0, jsx_runtime_1.jsx)("span", { className: styles.title, children: title }), (0, jsx_runtime_1.jsxs)("span", { className: styles.subtitle, children: [subtitle, redirect && ((0, jsx_runtime_1.jsx)("button", { className: "p-0 bg-transparent border-none outline-none text-sm text-accent duration-200 hover:text-accent-light cursor-pointer font-semibold", onClick: () => openModal(redirect.to), children: redirect.label }))] })] }), (0, jsx_runtime_1.jsx)(x_svg_1.default, { className: styles.close, onClick: closeModal })] }), children] }));
12
+ const { openModal, closeModal } = (0, context_1.useRawModal)();
13
+ return ((0, jsx_runtime_1.jsxs)("div", { className: (0, core_1.cn)(styles.container, style), role: "dialog", "aria-modal": "true", children: [(0, jsx_runtime_1.jsxs)("div", { className: styles.header, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles.heading, children: [(0, jsx_runtime_1.jsx)("span", { className: styles.title, children: title }), (0, jsx_runtime_1.jsxs)("span", { className: styles.subtitle, children: [subtitle, redirect && ((0, jsx_runtime_1.jsx)("button", { className: "p-0 bg-transparent border-none outline-none text-sm text-accent duration-200 hover:text-accent-light cursor-pointer font-semibold", onClick: () => openModal(redirect.to), children: redirect.label }))] })] }), (0, jsx_runtime_1.jsx)(x_svg_1.default, { className: styles.close, onClick: closeModal })] }), children] }));
14
14
  }
15
15
  const styles = {
16
16
  container: "relative flex flex-col gap-4 w-lg p-7 pt-6 select-none overflow-hidden",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bouku/modal",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -20,10 +20,9 @@
20
20
  "build": "tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@bouko/style": "^0.1.6",
24
- "@bouko/ts": "^0.2.0",
23
+ "@bouku/animate": "^0.0.1",
25
24
  "@bouku/core": "^0.2.4",
26
- "@bouku/form": "^0.1.4",
25
+ "@bouku/form": "^0.1.5",
27
26
  "clsx": "^2.1.1",
28
27
  "formeact": "^0.0.3",
29
28
  "framer-motion": "^12.16.0",