@cronocode/react-box 1.0.0 → 1.0.2

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,5 @@
1
1
  import Box from '../box';
2
- declare type BoxProps = React.ComponentProps<typeof Box>;
2
+ declare type BoxProps = React.ComponentProps<typeof Box<'button'>>;
3
3
  declare type BoxTagProps = Required<BoxProps>['props'];
4
4
  declare type ButtonTagProps = Omit<BoxTagProps, 'type' | 'onClick' | 'disabled'>;
5
5
  declare type ButtonType = Required<React.ComponentProps<'button'>>['type'];
@@ -1,5 +1,9 @@
1
- interface Props<T> {
2
- children: React.ReactNode;
1
+ import Box from '../box';
2
+ declare type BoxProps = React.ComponentProps<typeof Box<'form'>>;
3
+ declare type BoxTagProps = Required<BoxProps>['props'];
4
+ declare type FormAsyncTagProps = Omit<BoxTagProps, 'onSubmit' | 'ref'>;
5
+ interface Props<T> extends Omit<BoxProps, 'props' | 'tag'> {
6
+ props?: FormAsyncTagProps;
3
7
  onSubmit: (obj: T, e: React.FormEvent<HTMLFormElement>) => void;
4
8
  }
5
9
  export default function FormAsync<T>(props: Props<T>): JSX.Element;
@@ -1,33 +1,16 @@
1
1
  import { jsx as i } from "react/jsx-runtime";
2
- import { useRef as p, useCallback as s } from "react";
3
- import m from "../box.js";
2
+ import { useRef as p, useCallback as u } from "react";
3
+ import a from "../box.js";
4
+ import { F as c } from "../utils/utils.js";
4
5
  import "../box.module.css.js";
5
- import "../utils/utils.js";
6
- function d(u) {
7
- const n = Array.from(u.elements).reduce((r, o) => {
8
- const c = o.name;
9
- return c && (r[c] || (r[c] = []), r[c].push(o)), r;
10
- }, {});
11
- return Object.entries(n).reduce((r, [o, c]) => {
12
- if (c.length === 1) {
13
- const e = c[0];
14
- r[o] = e.type === "checkbox" || e.type === "radio" ? e.checked : e.value;
15
- } else
16
- r[o] = [], c.forEach((e) => {
17
- var t;
18
- e.type === "checkbox" ? e.checked && r[o].push(e.value) : e.type === "radio" ? r[o] = (t = c.find((f) => f.checked)) == null ? void 0 : t.value : r[o].push(e.value);
19
- });
20
- return r;
21
- }, {});
22
- }
23
- function v(u) {
24
- const { children: n, onSubmit: r } = u, o = p(null), c = s((e) => {
25
- e.preventDefault();
26
- const t = d(o.current);
27
- r(t, e);
28
- }, []);
29
- return /* @__PURE__ */ i(m, { tag: "form", props: { ref: o, onSubmit: c }, children: n });
6
+ function S(o) {
7
+ const { onSubmit: m, props: n } = o, r = p(null), s = u((t) => {
8
+ t.preventDefault();
9
+ const f = c.getFormEntries(r.current);
10
+ m(f, t);
11
+ }, []), e = { ...n, onSubmit: s, ref: r };
12
+ return /* @__PURE__ */ i(a, { tag: "form", ...o, props: e });
30
13
  }
31
14
  export {
32
- v as default
15
+ S as default
33
16
  };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import Box from '../box';
2
3
  declare type BoxProps = React.ComponentProps<typeof Box<'input'>>;
3
4
  declare type BoxTagProps = Required<BoxProps>['props'];
@@ -15,5 +16,5 @@ interface Props extends Omit<BoxProps, 'props'> {
15
16
  required?: boolean;
16
17
  defaultChecked?: boolean;
17
18
  }
18
- export default function UncontrolledCheckboxCore(props: Props): JSX.Element;
19
- export {};
19
+ declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLInputElement>>;
20
+ export default _default;
@@ -1,25 +1,27 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import f from "../box.js";
3
- import "react";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { forwardRef as h } from "react";
3
+ import x from "../box.js";
4
4
  import "../box.module.css.js";
5
5
  import "../utils/utils.js";
6
- function k(o) {
7
- const { props: e, name: r, disabled: t, placeholder: n, value: p, onInput: a, onChange: i, autoFocus: u, readOnly: c, required: l, defaultChecked: d } = o, s = {
8
- ...e,
6
+ function C(o, e) {
7
+ const { props: r, name: t, disabled: n, placeholder: a, value: p, onInput: c, onChange: l, autoFocus: u, readOnly: d, required: i, defaultChecked: s } = o, m = {
8
+ ...r,
9
9
  type: "checkbox",
10
- name: r,
11
- disabled: t,
12
- placeholder: n,
13
- onInput: a,
14
- onChange: i,
10
+ name: t,
11
+ disabled: n,
12
+ placeholder: a,
13
+ onInput: c,
14
+ onChange: l,
15
15
  value: p,
16
16
  autoFocus: u,
17
- readOnly: c,
18
- required: l,
19
- defaultChecked: d
17
+ readOnly: d,
18
+ required: i,
19
+ defaultChecked: s,
20
+ ref: e
20
21
  };
21
- return /* @__PURE__ */ m(f, { tag: "input", inline: !0, ...o, props: s });
22
+ return /* @__PURE__ */ f(x, { tag: "input", inline: !0, ...o, props: m });
22
23
  }
24
+ const P = h(C);
23
25
  export {
24
- k as default
26
+ P as default
25
27
  };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import Box from '../box';
2
3
  declare type BoxProps = React.ComponentProps<typeof Box<'input'>>;
3
4
  declare type BoxTagProps = Required<BoxProps>['props'];
@@ -15,5 +16,5 @@ interface Props extends Omit<BoxProps, 'props'> {
15
16
  required?: boolean;
16
17
  defaultChecked?: boolean;
17
18
  }
18
- export default function UncontrolledRadioButtonCore(props: Props): JSX.Element;
19
- export {};
19
+ declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLInputElement>>;
20
+ export default _default;
@@ -1,25 +1,27 @@
1
- import { jsx as c } from "react/jsx-runtime";
2
- import f from "../box.js";
3
- import "react";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { forwardRef as g } from "react";
3
+ import C from "../box.js";
4
4
  import "../box.module.css.js";
5
5
  import "../utils/utils.js";
6
- function B(o) {
7
- const { props: t, name: e, disabled: r, placeholder: n, value: a, onInput: p, onChange: i, autoFocus: u, readOnly: d, required: l, defaultChecked: s } = o, m = {
6
+ function h(o, r) {
7
+ const { props: t, name: e, disabled: n, placeholder: a, value: d, onInput: i, onChange: p, autoFocus: u, readOnly: l, required: s, defaultChecked: c } = o, m = {
8
8
  ...t,
9
9
  type: "radio",
10
10
  name: e,
11
- disabled: r,
12
- placeholder: n,
13
- onInput: p,
14
- onChange: i,
15
- value: a,
11
+ disabled: n,
12
+ placeholder: a,
13
+ onInput: i,
14
+ onChange: p,
15
+ value: d,
16
16
  autoFocus: u,
17
- readOnly: d,
18
- required: l,
19
- defaultChecked: s
17
+ readOnly: l,
18
+ required: s,
19
+ defaultChecked: c,
20
+ ref: r
20
21
  };
21
- return /* @__PURE__ */ c(f, { tag: "input", inline: !0, ...o, props: m });
22
+ return /* @__PURE__ */ f(C, { tag: "input", inline: !0, ...o, props: m });
22
23
  }
24
+ const P = g(h);
23
25
  export {
24
- B as default
26
+ P as default
25
27
  };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import Box from '../box';
2
3
  declare type BoxProps = React.ComponentProps<typeof Box<'textarea'>>;
3
4
  declare type BoxTagProps = Required<BoxProps>['props'];
@@ -5,8 +6,8 @@ declare type UncontrolledTextareaCoreTagProps = Omit<BoxTagProps, 'name' | 'onIn
5
6
  interface Props extends Omit<BoxProps, 'props'> {
6
7
  name: string;
7
8
  props?: UncontrolledTextareaCoreTagProps;
8
- onInput?: (e: React.FormEvent<HTMLInputElement>) => void;
9
- onChange?: (e: React.FormEvent<HTMLInputElement>) => void;
9
+ onInput?: (e: React.FormEvent<HTMLTextAreaElement>) => void;
10
+ onChange?: (e: React.FormEvent<HTMLTextAreaElement>) => void;
10
11
  placeholder?: string;
11
12
  disabled?: boolean;
12
13
  defaultValue?: string | number;
@@ -18,5 +19,5 @@ interface Props extends Omit<BoxProps, 'props'> {
18
19
  readOnly?: boolean;
19
20
  required?: boolean;
20
21
  }
21
- export default function UncontrolledTextareaCore(props: Props): JSX.Element;
22
- export {};
22
+ declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLTextAreaElement>>;
23
+ export default _default;
@@ -1,42 +1,44 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import h from "../box.js";
3
- import "react";
1
+ import { jsx as h } from "react/jsx-runtime";
2
+ import { forwardRef as w } from "react";
3
+ import C from "../box.js";
4
4
  import "../box.module.css.js";
5
5
  import "../utils/utils.js";
6
- function b(o) {
6
+ function T(o, e) {
7
7
  const {
8
- props: e,
9
- name: r,
10
- disabled: t,
11
- placeholder: n,
12
- defaultValue: a,
8
+ props: r,
9
+ name: t,
10
+ disabled: n,
11
+ placeholder: a,
12
+ defaultValue: l,
13
13
  onInput: p,
14
- onChange: i,
15
- rows: l,
16
- cols: s,
17
- autoFocus: m,
18
- maxLength: u,
19
- minLength: d,
20
- readOnly: c,
21
- required: g
22
- } = o, x = {
23
- ...e,
24
- name: r,
25
- disabled: t,
26
- placeholder: n,
14
+ onChange: s,
15
+ rows: i,
16
+ cols: m,
17
+ autoFocus: u,
18
+ maxLength: d,
19
+ minLength: c,
20
+ readOnly: f,
21
+ required: x
22
+ } = o, g = {
23
+ ...r,
24
+ name: t,
25
+ disabled: n,
26
+ placeholder: a,
27
27
  onInput: p,
28
- onChange: i,
29
- defaultValue: a,
30
- rows: l,
31
- cols: s,
32
- autoFocus: m,
33
- maxLength: u,
34
- minLength: d,
35
- readOnly: c,
36
- required: g
28
+ onChange: s,
29
+ defaultValue: l,
30
+ rows: i,
31
+ cols: m,
32
+ autoFocus: u,
33
+ maxLength: d,
34
+ minLength: c,
35
+ readOnly: f,
36
+ required: x,
37
+ ref: e
37
38
  };
38
- return /* @__PURE__ */ f(h, { tag: "textarea", inline: !0, ...o, props: x });
39
+ return /* @__PURE__ */ h(C, { tag: "textarea", inline: !0, ...o, props: g });
39
40
  }
41
+ const y = w(T);
40
42
  export {
41
- b as default
43
+ y as default
42
44
  };
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import Box from '../box';
2
3
  declare type BoxProps = React.ComponentProps<typeof Box<'input'>>;
3
4
  declare type BoxTagProps = Required<BoxProps>['props'];
@@ -17,5 +18,5 @@ interface Props extends Omit<BoxProps, 'props'> {
17
18
  required?: boolean;
18
19
  step?: number | string;
19
20
  }
20
- export default function UncontrolledTextboxCore(props: Props): JSX.Element;
21
- export {};
21
+ declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLInputElement>>;
22
+ export default _default;
@@ -1,38 +1,40 @@
1
1
  import { jsx as x } from "react/jsx-runtime";
2
- import f from "../box.js";
3
- import "react";
2
+ import { forwardRef as g } from "react";
3
+ import b from "../box.js";
4
4
  import "../box.module.css.js";
5
5
  import "../utils/utils.js";
6
- function P(t) {
6
+ function y(o, t) {
7
7
  const {
8
- props: o,
9
- name: e,
10
- type: r,
11
- disabled: n,
12
- placeholder: p,
13
- defaultValue: a,
14
- onInput: i,
15
- onChange: u,
16
- autoFocus: l,
17
- readOnly: s,
18
- required: d,
19
- step: m
20
- } = t, c = {
21
- ...o,
22
- type: r || "text",
23
- name: e,
24
- disabled: n,
25
- placeholder: p,
26
- onInput: i,
27
- onChange: u,
28
- defaultValue: a,
29
- autoFocus: l,
30
- readOnly: s,
31
- required: d,
32
- step: m
8
+ props: e,
9
+ name: r,
10
+ type: n,
11
+ disabled: p,
12
+ placeholder: a,
13
+ defaultValue: l,
14
+ onInput: u,
15
+ onChange: i,
16
+ autoFocus: s,
17
+ readOnly: d,
18
+ required: m,
19
+ step: c
20
+ } = o, f = {
21
+ ...e,
22
+ type: n || "text",
23
+ name: r,
24
+ disabled: p,
25
+ placeholder: a,
26
+ onInput: u,
27
+ onChange: i,
28
+ defaultValue: l,
29
+ autoFocus: s,
30
+ readOnly: d,
31
+ required: m,
32
+ step: c,
33
+ ref: t
33
34
  };
34
- return /* @__PURE__ */ x(f, { tag: "input", inline: !0, ...t, props: c });
35
+ return /* @__PURE__ */ x(b, { tag: "input", inline: !0, ...o, props: f });
35
36
  }
37
+ const j = g(y);
36
38
  export {
37
- P as default
39
+ j as default
38
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronocode/react-box",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "./box.js",
5
5
  "module": "./box.js",
6
6
  "types": "./box.d.ts",