@bouku/modal 0.0.4 → 0.0.6

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.
@@ -1,5 +1,6 @@
1
1
  import { type ModalConfig } from "./context";
2
- import type { ComponentProps } from "react";
2
+ import type { ReactNode, ComponentProps } from "react";
3
+ import { type ButtonProps } from "../ui/components/button";
3
4
  type ArgsFor<P> = {} extends P ? [props?: P] : [props: P];
4
5
  type ActiveModal<T extends ModalConfig> = {
5
6
  [K in keyof T]: {
@@ -9,12 +10,13 @@ type ActiveModal<T extends ModalConfig> = {
9
10
  }[keyof T];
10
11
  export declare const createModalSystem: <T extends ModalConfig>(config: T) => {
11
12
  ModalProvider: (props: {
12
- children: React.ReactNode;
13
+ children: ReactNode;
13
14
  }) => import("react/jsx-runtime").JSX.Element;
14
15
  useModal: () => {
15
16
  active: ActiveModal<T> | null;
16
17
  openModal: <K extends keyof T>(id: K, ...args: ArgsFor<ComponentProps<T[K]>>) => void;
17
18
  closeModal: () => void;
18
19
  };
20
+ ModalButton: (props: ButtonProps<T>) => import("react/jsx-runtime").JSX.Element;
19
21
  };
20
22
  export { useRawModal } from "./context";
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useRawModal = exports.createModalSystem = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const provider_1 = require("./provider");
6
5
  const context_1 = require("./context");
6
+ const provider_1 = require("./provider");
7
+ const button_1 = require("../ui/components/button");
7
8
  const createModalSystem = (config) => ({
8
9
  ModalProvider: (props) => ((0, jsx_runtime_1.jsx)(provider_1.ModalProvider, { config: config, ...props })),
9
10
  useModal: () => {
@@ -12,11 +13,12 @@ const createModalSystem = (config) => ({
12
13
  openModal(id, args[0]);
13
14
  }
14
15
  return {
15
- active: active, // cast happens only here, at the typed edge
16
+ active: active,
16
17
  openModal: open,
17
18
  closeModal
18
19
  };
19
- }
20
+ },
21
+ ModalButton: (props) => ((0, jsx_runtime_1.jsx)(button_1.ModalButton, { ...props }))
20
22
  });
21
23
  exports.createModalSystem = createModalSystem;
22
24
  var context_2 = require("./context");
@@ -1,5 +1,5 @@
1
- import type { ReactNode } from "react";
2
- import type { ModalConfig } from "./context";
1
+ import { type ReactNode } from "react";
2
+ import { type ModalConfig } from "./context";
3
3
  export declare function ModalProvider<T extends ModalConfig>({ config, children }: {
4
4
  config: T;
5
5
  children: ReactNode;
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ModalProvider = ModalProvider;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_1 = require("react");
7
- const animate_1 = require("@bouku/animate");
8
7
  const context_1 = require("./context");
8
+ const animate_1 = require("@bouku/animate");
9
9
  function ModalProvider({ config, children }) {
10
10
  const [active, setActive] = (0, react_1.useState)(null);
11
11
  const openModal = (id, props) => setActive({ id, props: props ?? {} });
@@ -1 +1 @@
1
- export { default as ModalButton } from "./button";
1
+ export * from "./button";
@@ -1,8 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ModalButton = void 0;
7
- var button_1 = require("./button");
8
- Object.defineProperty(exports, "ModalButton", { enumerable: true, get: function () { return __importDefault(button_1).default; } });
17
+ __exportStar(require("./button"), exports);
@@ -1,11 +1,12 @@
1
+ import { type ModalConfig } from "../../state/context";
1
2
  import type { ReactNode } from "react";
2
3
  import type { JsonMap } from "ts-helper-kit";
3
- type ButtonProps = {
4
- id: string;
4
+ export type ButtonProps<T extends ModalConfig> = {
5
+ id: keyof T;
5
6
  params?: JsonMap;
6
7
  variant?: "surface" | "accent";
7
8
  icon?: ReactNode;
8
9
  children?: ReactNode;
10
+ disabled?: boolean;
9
11
  };
10
- export default function ModalButton({ id, params, ...props }: ButtonProps): import("react/jsx-runtime").JSX.Element;
11
- export {};
12
+ export declare function ModalButton<T extends ModalConfig>({ id, params, ...props }: ButtonProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.default = ModalButton;
4
+ exports.ModalButton = ModalButton;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
- const context_1 = require("../../state/context");
7
6
  const core_1 = require("@bouku/core");
7
+ const context_1 = require("../../state/context");
8
8
  function ModalButton({ id, params, ...props }) {
9
9
  const { openModal } = (0, context_1.useRawModal)();
10
- return ((0, jsx_runtime_1.jsx)(core_1.Button, { ...props, action: () => openModal(id, params) }));
10
+ return ((0, jsx_runtime_1.jsx)(core_1.Button, { ...props, action: () => openModal(id.toString(), params) }));
11
11
  }
@@ -1,5 +1,14 @@
1
- import { ModalProps } from "./normal";
2
1
  import { FormBuilderField, FormData, FormSchema, PresetName } from "@bouku/form";
2
+ import type { ReactNode } from "react";
3
+ import type { Component } from "@bouku/core";
4
+ type ModalProps = Component & {
5
+ title: string;
6
+ subtitle?: ReactNode;
7
+ redirect?: {
8
+ label: string;
9
+ to: string;
10
+ };
11
+ };
3
12
  type Props<T extends FormData = FormData, P extends PresetName | undefined = undefined> = {
4
13
  fields: FormBuilderField[][];
5
14
  initialData?: Partial<T>;
@@ -12,6 +21,7 @@ type Props<T extends FormData = FormData, P extends PresetName | undefined = und
12
21
  code?: string;
13
22
  message?: string;
14
23
  }>;
24
+ oops?: (message: string) => void;
15
25
  } & Omit<ModalProps, "children">;
16
26
  /**
17
27
  * Form Modal component.
@@ -19,7 +29,7 @@ type Props<T extends FormData = FormData, P extends PresetName | undefined = und
19
29
  * Combines a standard modal layout with a form builder.
20
30
  * Wraps @bouko/form `FormBuilder` for form handling.
21
31
  **/
22
- export declare function FormModal({ style, fields, initialData, submitLabel, submit, ...props }: Props): import("react/jsx-runtime").JSX.Element;
32
+ export declare function FormModal({ style, fields, initialData, submitLabel, submit, oops, ...props }: Props): import("react/jsx-runtime").JSX.Element;
23
33
  export default FormModal;
24
34
  /**
25
35
  * Problems:
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FormModal = FormModal;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const normal_1 = require("./normal");
6
+ const notify_1 = require("@bouku/notify");
6
7
  const form_1 = require("@bouku/form");
7
8
  /**
8
9
  * Form Modal component.
@@ -10,7 +11,7 @@ const form_1 = require("@bouku/form");
10
11
  * Combines a standard modal layout with a form builder.
11
12
  * Wraps @bouko/form `FormBuilder` for form handling.
12
13
  **/
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 }) }));
14
+ function FormModal({ style, fields, initialData, submitLabel, submit, oops, ...props }) {
15
+ 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, oops: oops ?? ((msg) => (0, notify_1.isToasterMounted)() ? notify_1.toast.error(msg) : console.log(msg)) }) }));
15
16
  }
16
17
  exports.default = FormModal;
@@ -1,5 +1,5 @@
1
+ import { type Component } from "@bouku/core";
1
2
  import type { ReactNode } from "react";
2
- import type { Component } from "@bouko/react";
3
3
  export type ModalProps = Component & {
4
4
  title: string;
5
5
  subtitle?: ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bouku/modal",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -21,8 +21,9 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@bouku/animate": "^0.0.1",
24
- "@bouku/core": "^0.2.4",
25
- "@bouku/form": "^0.1.5",
24
+ "@bouku/core": "^0.4.1",
25
+ "@bouku/form": "^0.1.9",
26
+ "@bouku/notify": "^0.0.1",
26
27
  "clsx": "^2.1.1",
27
28
  "formeact": "^0.0.3",
28
29
  "framer-motion": "^12.16.0",
@@ -1,14 +0,0 @@
1
- /**
2
- * Root Modal component
3
- *
4
- * Injected into the root layout in a hidden state,
5
- * then when a modal is opened this is displayed and wraps
6
- * the new modal with a backdrop.
7
- **/
8
- export default function RootModal(): import("react/jsx-runtime").JSX.Element;
9
- /**
10
- * Problems:
11
- *
12
- * - Perfect `useModal`
13
- * - Perfect `Animation`
14
- **/
@@ -1,22 +0,0 @@
1
- "use client";
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.default = RootModal;
5
- const jsx_runtime_1 = require("react/jsx-runtime");
6
- const context_1 = require("./context");
7
- const react_1 = require("@bouko/react");
8
- /**
9
- * Root Modal component
10
- *
11
- * Injected into the root layout in a hidden state,
12
- * then when a modal is opened this is displayed and wraps
13
- * the new modal with a backdrop.
14
- **/
15
- function RootModal() {
16
- const { activeId, modal } = (0, context_1.useModal)();
17
- return ((0, jsx_runtime_1.jsx)(react_1.AnimatePresence, { mode: "wait", children: modal && ((0, jsx_runtime_1.jsx)(react_1.Animation, { style: styles.backdrop, children: (0, jsx_runtime_1.jsx)("div", { className: styles.content, children: modal }) }, activeId)) }));
18
- }
19
- const styles = {
20
- backdrop: "fixed inset-0 flex justify-center items-center bg-background-light/60 dark:bg-background-dark/60 z-[99]",
21
- content: "max-w-[80%] max-h-[85%] bg-background border border-border rounded-lg shadow-soft"
22
- };