@geckou/ui-react 0.6.0 → 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.
@@ -1,70 +1,83 @@
1
1
  "use client";
2
- import { jsxs as f, jsx as u } from "react/jsx-runtime";
3
- import { useState as N, useRef as G, useEffect as R, useId as z } from "react";
4
- import { isEmptyValue as M, MESSAGES as V, COLOR as o } from "@geckou/ui-core";
5
- import { ErrorMessage as j } from "./ErrorMessage.js";
6
- function A({
7
- value: p,
8
- onChange: s,
9
- options: m,
10
- name: _,
2
+ import { jsxs as _, jsx as d } from "react/jsx-runtime";
3
+ import { useState as M, useRef as R, useEffect as V, useId as g } from "react";
4
+ import { isEmptyValue as j, MESSAGES as q, COLOR as o } from "@geckou/ui-core";
5
+ import { ErrorMessage as I } from "./ErrorMessage.js";
6
+ function $({
7
+ value: v,
8
+ onChange: n,
9
+ options: x,
10
+ name: h,
11
11
  isDisabled: a,
12
- isRequired: n,
12
+ isRequired: u,
13
13
  cssStyle: e,
14
- isDisableAnimation: v
14
+ isDisableAnimation: k,
15
+ ariaLabel: w,
16
+ ariaLabelledBy: i
15
17
  }) {
16
- var i, d;
17
- const r = p ?? "", [g, x] = N(!1), c = G(r);
18
- R(() => {
19
- c.current !== r && (c.current = r, x(!0));
18
+ var f, p;
19
+ const r = v ?? "", [C, E] = M(!1), s = R(r);
20
+ V(() => {
21
+ s.current !== r && (s.current = r, E(!0));
20
22
  }, [r]);
21
- const h = g && n && M(r) ? [V.required] : void 0, k = z(), w = _ ?? k, C = a ? e == null ? void 0 : e.disabled : e == null ? void 0 : e.default, l = {
23
+ const c = C && u && j(r) ? [q.required] : void 0, N = g(), G = h ?? N, b = g(), y = a ? e == null ? void 0 : e.disabled : e == null ? void 0 : e.default, l = {
22
24
  textColor: a ? o.darkGray : o.black,
23
25
  backgroundColor: a ? o.lightGray : o.white,
24
26
  border: {
25
27
  color: a ? o.darkGray : o.blue,
26
28
  size: "1px"
27
29
  },
28
- ...C ?? {}
29
- }, E = {
30
+ ...y ?? {}
31
+ }, z = {
30
32
  "--text-color": l.textColor,
31
- "--border-color": (i = l.border) == null ? void 0 : i.color,
32
- "--border-size": (d = l.border) == null ? void 0 : d.size,
33
+ "--border-color": (f = l.border) == null ? void 0 : f.color,
34
+ "--border-size": (p = l.border) == null ? void 0 : p.size,
33
35
  "--background-color": l.backgroundColor,
34
- "--duration": v ? "0s" : ".3s"
36
+ "--duration": k ? "0s" : ".3s"
35
37
  };
36
- return /* @__PURE__ */ f("div", { className: "relative flex flex-wrap items-center gap-4", children: [
37
- /* @__PURE__ */ u("style", { children: "@keyframes uiRadioPop{0%{scale:1}10%{scale:.8}50%{scale:1.2}100%{scale:1}}" }),
38
- m.map((t) => {
39
- const b = t.value === r;
40
- return /* @__PURE__ */ f(
41
- "label",
42
- {
43
- style: E,
44
- className: `relative grid cursor-pointer grid-cols-[auto_1fr] items-center gap-2 before:inline-block before:aspect-square before:w-4 before:rounded-full before:transition-all before:duration-(--duration) before:ease-linear before:content-[''] has-[input:disabled]:cursor-not-allowed has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-(--border-color) ${b ? "text-(--text-color) before:animate-[uiRadioPop_var(--duration)_ease-out] before:bg-(--border-color) before:shadow-[0_0_0_2px_var(--background-color)_inset,0_0_0_1px_var(--border-color)]" : "text-(--border-color) before:bg-(--background-color) before:shadow-[0_0_0_1px_var(--border-color)_inset]"}`,
45
- children: [
46
- /* @__PURE__ */ u(
47
- "input",
48
- {
49
- type: "radio",
50
- name: w,
51
- value: t.value,
52
- disabled: a,
53
- required: n,
54
- checked: b,
55
- onChange: () => s == null ? void 0 : s(t.value),
56
- className: "sr-only"
57
- }
58
- ),
59
- /* @__PURE__ */ u("span", { children: t.label })
60
- ]
61
- },
62
- t.value
63
- );
64
- }),
65
- /* @__PURE__ */ u(j, { errorMessages: h })
66
- ] });
38
+ return /* @__PURE__ */ _(
39
+ "div",
40
+ {
41
+ role: "radiogroup",
42
+ "aria-label": i ? void 0 : w,
43
+ "aria-labelledby": i,
44
+ "aria-required": u || void 0,
45
+ "aria-describedby": c ? b : void 0,
46
+ className: "relative flex flex-wrap items-center gap-4",
47
+ children: [
48
+ /* @__PURE__ */ d("style", { children: "@keyframes uiRadioPop{0%{scale:1}10%{scale:.8}50%{scale:1.2}100%{scale:1}}" }),
49
+ x.map((t) => {
50
+ const m = t.value === r;
51
+ return /* @__PURE__ */ _(
52
+ "label",
53
+ {
54
+ style: z,
55
+ className: `relative grid cursor-pointer grid-cols-[auto_1fr] items-center gap-2 before:inline-block before:aspect-square before:w-4 before:rounded-full before:transition-all before:duration-(--duration) before:ease-linear before:content-[''] has-[input:disabled]:cursor-not-allowed has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-(--border-color) ${m ? "text-(--text-color) before:animate-[uiRadioPop_var(--duration)_ease-out] before:bg-(--border-color) before:shadow-[0_0_0_2px_var(--background-color)_inset,0_0_0_1px_var(--border-color)]" : "text-(--border-color) before:bg-(--background-color) before:shadow-[0_0_0_1px_var(--border-color)_inset]"}`,
56
+ children: [
57
+ /* @__PURE__ */ d(
58
+ "input",
59
+ {
60
+ type: "radio",
61
+ name: G,
62
+ value: t.value,
63
+ disabled: a,
64
+ required: u,
65
+ checked: m,
66
+ onChange: () => n == null ? void 0 : n(t.value),
67
+ className: "sr-only"
68
+ }
69
+ ),
70
+ /* @__PURE__ */ d("span", { children: t.label })
71
+ ]
72
+ },
73
+ t.value
74
+ );
75
+ }),
76
+ /* @__PURE__ */ d(I, { id: b, errorMessages: c })
77
+ ]
78
+ }
79
+ );
67
80
  }
68
81
  export {
69
- A as RadioButtons
82
+ $ as RadioButtons
70
83
  };
@@ -11,6 +11,7 @@ type Props = {
11
11
  cssStyle?: InputBoxStyleForEachStatus;
12
12
  /** combobox のアクセシブル名。可視ラベルがあるならそちらを ariaLabelledBy で指すこと */
13
13
  ariaLabel?: string;
14
+ ariaLabelledBy?: string;
14
15
  };
15
- export declare function SearchableSelectBox({ options, value, onChange, onSelect, name, placeholder, isDisabled, searchTarget, cssStyle, ariaLabel, }: Props): import("react").JSX.Element;
16
+ export declare function SearchableSelectBox({ options, value, onChange, onSelect, name, placeholder, isDisabled, searchTarget, cssStyle, ariaLabel, ariaLabelledBy, }: Props): import("react").JSX.Element;
16
17
  export {};
@@ -1,77 +1,84 @@
1
1
  "use client";
2
- import { jsxs as N, jsx as m } from "react/jsx-runtime";
3
- import { useState as w, useRef as k, useId as _, useEffect as y } from "react";
4
- import { TextBox as $ } from "./TextBox.js";
5
- function R({
6
- options: v,
2
+ import { jsxs as $, jsx as m } from "react/jsx-runtime";
3
+ import { useState as v, useRef as A, useId as j, useEffect as I } from "react";
4
+ import { TextBox as K } from "./TextBox.js";
5
+ function z({
6
+ options: w,
7
7
  value: o,
8
8
  onChange: s,
9
9
  onSelect: d,
10
- name: A,
11
- placeholder: I = "入力してください",
12
- isDisabled: g,
13
- searchTarget: B = "label",
14
- cssStyle: L,
15
- ariaLabel: O
10
+ name: g,
11
+ placeholder: O = "入力してください",
12
+ isDisabled: B,
13
+ searchTarget: L = "label",
14
+ cssStyle: S,
15
+ ariaLabel: F,
16
+ ariaLabelledBy: N
16
17
  }) {
17
- const [u, f] = w(o), [h, a] = w(!1), [i, n] = w(-1), x = k(null), p = _(), b = (e) => `${p}-option-${e}`, E = k(o);
18
- y(() => {
19
- E.current !== o && (E.current = o, f(o));
20
- }, [o]), y(() => {
18
+ const b = (e) => {
19
+ var r;
20
+ return ((r = w.find((t) => String(t.value) === e)) == null ? void 0 : r.label) ?? e;
21
+ }, [u, f] = v(() => b(o)), [h, a] = v(!1), [i, l] = v(-1), x = A(null), p = j(), D = (e) => `${p}-option-${e}`, E = A(o);
22
+ I(() => {
23
+ E.current !== o && (E.current = o, f(b(o)));
24
+ }, [o]), I(() => {
21
25
  const e = (r) => {
22
26
  const t = x.current;
23
27
  t && !t.contains(r.target) && a(!1);
24
28
  };
25
29
  return document.addEventListener("pointerdown", e), () => document.removeEventListener("pointerdown", e);
26
30
  }, []);
27
- const l = u ? v.filter(
28
- (e) => String(e[B]).toLowerCase().includes(u.toLowerCase())
29
- ) : v, F = (e) => {
31
+ const y = w.filter((e) => !e.isDisabled), n = u ? y.filter(
32
+ (e) => String(e[L]).toLowerCase().includes(u.toLowerCase())
33
+ ) : y, V = (e) => {
30
34
  const r = String(e);
31
- f(r), a(!!r), n(-1), s == null || s(r);
32
- }, D = (e) => {
35
+ f(r), a(!!r), l(-1), s == null || s(r);
36
+ }, k = (e) => {
37
+ if (e.isDisabled)
38
+ return;
33
39
  const r = e.value.toString();
34
- f(r), a(!1), n(-1), s == null || s(r), d == null || d(r);
35
- }, c = h && l.length > 0, S = (e) => {
40
+ f(e.label), a(!1), l(-1), s == null || s(r), d == null || d(r);
41
+ }, c = h && n.length > 0, _ = (e) => {
36
42
  if (e.key === "ArrowDown" || e.key === "ArrowUp") {
37
43
  if (e.preventDefault(), !h) {
38
- a(!0), n(
39
- e.key === "ArrowDown" ? 0 : l.length - 1
44
+ a(!0), l(
45
+ e.key === "ArrowDown" ? 0 : n.length - 1
40
46
  );
41
47
  return;
42
48
  }
43
- if (l.length === 0)
49
+ if (n.length === 0)
44
50
  return;
45
- n((r) => {
46
- const t = l.length - 1;
51
+ l((r) => {
52
+ const t = n.length - 1;
47
53
  return e.key === "ArrowDown" ? r >= t ? 0 : r + 1 : r <= 0 ? t : r - 1;
48
54
  });
49
55
  return;
50
56
  }
51
57
  if (e.key === "Enter") {
52
- const r = c ? l[i] : void 0;
53
- r && (e.preventDefault(), D(r));
58
+ const r = c ? n[i] : void 0;
59
+ r && (e.preventDefault(), k(r));
54
60
  return;
55
61
  }
56
- e.key === "Escape" && c && (e.preventDefault(), a(!1), n(-1));
62
+ e.key === "Escape" && c && (e.preventDefault(), a(!1), l(-1));
57
63
  };
58
- return /* @__PURE__ */ N("div", { ref: x, className: "relative", children: [
64
+ return /* @__PURE__ */ $("div", { ref: x, className: "relative", children: [
59
65
  /* @__PURE__ */ m(
60
- $,
66
+ K,
61
67
  {
62
- name: A,
68
+ name: g,
63
69
  value: u,
64
- onChange: F,
65
- isDisabled: g,
66
- placeholder: I,
67
- cssStyle: L,
70
+ onChange: V,
71
+ isDisabled: B,
72
+ placeholder: O,
73
+ cssStyle: S,
68
74
  role: "combobox",
69
- ariaLabel: O,
75
+ ariaLabel: F,
76
+ ariaLabelledBy: N,
70
77
  ariaAutocomplete: "list",
71
78
  ariaExpanded: c,
72
79
  ariaControls: p,
73
- ariaActivedescendant: c && i >= 0 ? b(i) : void 0,
74
- onKeyDown: S
80
+ ariaActivedescendant: c && i >= 0 ? D(i) : void 0,
81
+ onKeyDown: _
75
82
  }
76
83
  ),
77
84
  c && /* @__PURE__ */ m(
@@ -80,17 +87,17 @@ function R({
80
87
  id: p,
81
88
  role: "listbox",
82
89
  className: "absolute top-[calc(100%-var(--sp-min,0.1875rem))] left-0 z-[2] max-h-[calc(var(--bv,0.375rem)*56)] min-w-full overflow-auto rounded-[var(--radius-small,0.1875rem)] bg-white py-[var(--sp-small,0.375rem)] shadow-[0_0_6px_#33333333]",
83
- children: l.map((e, r) => /* @__PURE__ */ m(
90
+ children: n.map((e, r) => /* @__PURE__ */ m(
84
91
  "div",
85
92
  {
86
- id: b(r),
93
+ id: D(r),
87
94
  role: "option",
88
95
  "aria-selected": r === i,
89
96
  className: `block w-full cursor-pointer p-[var(--sp-medium,0.75rem)] text-left text-[length:var(--fs-small,0.6875rem)] text-[var(--link-color,#1c4ac9)] hover:bg-[var(--hover-color,#EEF7FB)] hover:transition-all hover:duration-100 ${r === i ? "bg-[var(--hover-color,#EEF7FB)]" : ""}`,
90
97
  onPointerDown: (t) => {
91
- t.preventDefault(), D(e);
98
+ t.preventDefault(), k(e);
92
99
  },
93
- onMouseEnter: () => n(r),
100
+ onMouseEnter: () => l(r),
94
101
  children: e.label
95
102
  },
96
103
  e.value
@@ -100,5 +107,5 @@ function R({
100
107
  ] });
101
108
  }
102
109
  export {
103
- R as SearchableSelectBox
110
+ z as SearchableSelectBox
104
111
  };
@@ -1,69 +1,70 @@
1
1
  "use client";
2
- import { jsxs as f, jsx as r } from "react/jsx-runtime";
2
+ import { jsxs as d, jsx as r } from "react/jsx-runtime";
3
3
  import { MESSAGES as I } from "@geckou/ui-core";
4
- import { useState as O, useRef as x, useEffect as V, Fragment as q } from "react";
5
- import { InputBox as w } from "./InputBox.js";
6
- import { ErrorMessage as D } from "./ErrorMessage.js";
4
+ import { useState as N, useRef as p, useEffect as O, Fragment as V } from "react";
5
+ import { InputBox as q } from "./InputBox.js";
6
+ import { ErrorMessage as w } from "./ErrorMessage.js";
7
7
  import { KeyboardArrowDownIcon as F } from "./icons/KeyboardArrowDownIcon.js";
8
- function p(t) {
9
- return typeof t == "object" && t !== null && "label" in t && typeof t.label == "string" && "value" in t;
8
+ function g(l) {
9
+ return typeof l == "object" && l !== null && "label" in l && typeof l.label == "string" && "value" in l;
10
10
  }
11
11
  function P({
12
- options: t,
13
- name: g,
14
- value: E,
12
+ options: l,
13
+ name: E,
14
+ value: M,
15
15
  onChange: u,
16
- cssStyle: a,
17
- placeholder: o = "選択してください",
18
- canOmitSelect: M,
19
- isDisabled: s,
20
- isRequired: m,
21
- arrow: A
16
+ cssStyle: t,
17
+ placeholder: f = "選択してください",
18
+ canOmitSelect: B,
19
+ isDisabled: m,
20
+ isRequired: v,
21
+ arrow: C
22
22
  }) {
23
- var b, h;
24
- const [B, C] = O([]), l = E ?? "", c = () => {
23
+ var b, x;
24
+ const [s, j] = N([]), a = M ?? "", o = () => {
25
25
  const e = [];
26
- l === "" && m && e.push(I.required), C(e);
27
- }, N = x(l), v = x(!1);
28
- V(() => {
29
- if (!v.current) {
30
- if (l === N.current) {
31
- l !== "" && c();
26
+ a === "" && v && e.push(I.required), j(e);
27
+ }, k = p(a), h = p(!1);
28
+ O(() => {
29
+ if (!h.current) {
30
+ if (a === k.current) {
31
+ a !== "" && o();
32
32
  return;
33
33
  }
34
- v.current = !0;
34
+ h.current = !0;
35
35
  }
36
- c();
37
- }, [l]);
38
- const j = t.flatMap(
39
- (e) => p(e) ? [e] : Object.values(e).flat()
40
- ), k = (e) => {
41
- const n = j.find(
42
- (d) => String(d.value) === e
36
+ o();
37
+ }, [a]);
38
+ const A = l.flatMap(
39
+ (e) => g(e) ? [e] : Object.values(e).flat()
40
+ ), D = (e) => {
41
+ const n = A.find(
42
+ (c) => String(c.value) === e
43
43
  );
44
44
  u == null || u(n ? n.value : e);
45
45
  };
46
- return /* @__PURE__ */ f(
47
- w,
46
+ return /* @__PURE__ */ d(
47
+ q,
48
48
  {
49
- cssStyle: a,
49
+ cssStyle: t,
50
50
  className: "inline-flex [&>select]:flex-auto [&>select]:cursor-pointer [&>select]:pe-8",
51
- isDisabled: s,
51
+ isDisabled: m,
52
+ isErrored: !!s.length,
52
53
  children: [
53
- /* @__PURE__ */ f(
54
+ /* @__PURE__ */ d(
54
55
  "select",
55
56
  {
56
- name: g,
57
- value: l,
58
- disabled: s,
59
- required: m,
60
- onChange: (e) => k(e.target.value),
61
- onBlur: () => c(),
57
+ name: E,
58
+ value: a,
59
+ disabled: m,
60
+ required: v,
61
+ "aria-invalid": s.length > 0 || void 0,
62
+ onChange: (e) => D(e.target.value),
63
+ onBlur: () => o(),
62
64
  children: [
63
- M ? /* @__PURE__ */ r("option", { value: "", children: o || "選択しない" }) : /* @__PURE__ */ r("option", { disabled: !0, value: "", children: o || "選択してください" }),
64
- ["0", "NA"].includes(l.toString()) && s && /* @__PURE__ */ r("option", { disabled: !0, value: l, children: o || "選択してください" }),
65
- t.map(
66
- (e) => p(e) ? /* @__PURE__ */ r(
65
+ B ? /* @__PURE__ */ r("option", { value: "", children: f || "選択しない" }) : /* @__PURE__ */ r("option", { disabled: !0, value: "", children: f || "選択してください" }),
66
+ l.map(
67
+ (e) => g(e) ? /* @__PURE__ */ r(
67
68
  "option",
68
69
  {
69
70
  value: e.value,
@@ -71,8 +72,8 @@ function P({
71
72
  children: e.label
72
73
  },
73
74
  e.value
74
- ) : /* @__PURE__ */ f(q, { children: [
75
- Object.entries(e).map(([n, d]) => /* @__PURE__ */ r("optgroup", { label: n, children: d.map((i) => /* @__PURE__ */ r(
75
+ ) : /* @__PURE__ */ d(V, { children: [
76
+ Object.entries(e).map(([n, c]) => /* @__PURE__ */ r("optgroup", { label: n, children: c.map((i) => /* @__PURE__ */ r(
76
77
  "option",
77
78
  {
78
79
  value: i.value,
@@ -87,14 +88,14 @@ function P({
87
88
  ]
88
89
  }
89
90
  ),
90
- /* @__PURE__ */ r("div", { className: "pointer-events-none absolute inset-y-0 end-2 flex items-center [&>*]:h-4 [&>*]:fill-current [&>*]:text-current", children: A ?? /* @__PURE__ */ r(F, {}) }),
91
+ /* @__PURE__ */ r("div", { className: "pointer-events-none absolute inset-y-0 end-2 flex items-center [&>*]:h-4 [&>*]:fill-current [&>*]:text-current", children: C ?? /* @__PURE__ */ r(F, {}) }),
91
92
  /* @__PURE__ */ r(
92
- D,
93
+ w,
93
94
  {
94
- errorMessages: B,
95
+ errorMessages: s,
95
96
  cssStyle: {
96
- textColor: (b = a == null ? void 0 : a.error) == null ? void 0 : b.backgroundColor,
97
- backgroundColor: (h = a == null ? void 0 : a.error) == null ? void 0 : h.textColor
97
+ textColor: (b = t == null ? void 0 : t.error) == null ? void 0 : b.backgroundColor,
98
+ backgroundColor: (x = t == null ? void 0 : t.error) == null ? void 0 : x.textColor
98
99
  }
99
100
  }
100
101
  )
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsxs as v, jsx as i } from "react/jsx-runtime";
3
- import { useState as a, useRef as h, useImperativeHandle as E, useEffect as l } from "react";
3
+ import { useState as a, useRef as p, useImperativeHandle as E, useEffect as l } from "react";
4
4
  import { KeyboardArrowDownIcon as I } from "./icons/KeyboardArrowDownIcon.js";
5
5
  import { COLOR as N } from "@geckou/ui-core";
6
6
  function $({
7
7
  isOpened: n = null,
8
- isHiddenArrow: p = !1,
8
+ isHiddenArrow: h = !1,
9
9
  isDisabled: b = !1,
10
10
  isDisableClickOutside: f = !1,
11
11
  duration: c = 0.3,
@@ -13,7 +13,7 @@ function $({
13
13
  children: w,
14
14
  ref: x
15
15
  }) {
16
- const [t, r] = a(n || !1), [C, u] = a(n || !1), [y, H] = a(0), d = h(null), m = h(null), R = () => r((e) => !e);
16
+ const [t, r] = a(n || !1), [C, u] = a(n || !1), [y, k] = a(0), d = p(null), m = p(null), H = () => r((e) => !e);
17
17
  E(x, () => ({
18
18
  isOpenedContents: () => t,
19
19
  close: () => r(!1)
@@ -31,7 +31,7 @@ function $({
31
31
  const e = m.current;
32
32
  if (!e)
33
33
  return;
34
- const s = () => H(e.clientHeight);
34
+ const s = () => k(e.clientHeight);
35
35
  s();
36
36
  const o = new ResizeObserver(s);
37
37
  return o.observe(e), () => o.disconnect();
@@ -43,8 +43,8 @@ function $({
43
43
  const e = setTimeout(() => u(!0), c * 1e3);
44
44
  return () => clearTimeout(e);
45
45
  }, [t, c]);
46
- const k = { "--link-color": N.blue };
47
- return /* @__PURE__ */ v("div", { ref: d, style: k, children: [
46
+ const R = { "--link-color": N.blue };
47
+ return /* @__PURE__ */ v("div", { ref: d, style: R, children: [
48
48
  /* @__PURE__ */ v(
49
49
  "button",
50
50
  {
@@ -53,11 +53,11 @@ function $({
53
53
  "aria-expanded": t,
54
54
  className: "relative grid w-full cursor-pointer grid-cols-[1fr_auto] items-center justify-items-start text-(--link-color)",
55
55
  onClick: (e) => {
56
- e.preventDefault(), R();
56
+ e.preventDefault(), H();
57
57
  },
58
58
  children: [
59
- /* @__PURE__ */ i("div", { className: "w-full text-left", children: g }),
60
- !p && /* @__PURE__ */ i(
59
+ /* @__PURE__ */ i("span", { className: "block w-full text-left", children: g }),
60
+ !h && /* @__PURE__ */ i(
61
61
  I,
62
62
  {
63
63
  className: `size-[var(--icon-medium,1.125rem)] flex-none text-(--link-color) transition-all duration-100 ${t ? "rotate-180" : ""}`
@@ -1,68 +1,76 @@
1
1
  "use client";
2
- import { jsxs as j, jsx as p } from "react/jsx-runtime";
3
- import { isEmptyValue as k, validateInputValue as B } from "@geckou/ui-core";
4
- import { useState as I, useRef as n, useEffect as A } from "react";
5
- import { InputBox as H } from "./InputBox.js";
6
- import { ErrorMessage as N } from "./ErrorMessage.js";
7
- function z({
8
- name: d,
9
- value: s,
10
- onChange: o,
2
+ import { jsxs as H, jsx as h } from "react/jsx-runtime";
3
+ import { isEmptyValue as M, validateInputValue as T } from "@geckou/ui-core";
4
+ import { useState as j, useRef as m, useEffect as k } from "react";
5
+ import { InputBox as I } from "./InputBox.js";
6
+ import { ErrorMessage as W } from "./ErrorMessage.js";
7
+ function z(n) {
8
+ const e = getComputedStyle(n), t = (...r) => r.reduce((a, i) => a + (parseFloat(i) || 0), 0);
9
+ return e.boxSizing === "border-box" ? n.scrollHeight + t(e.borderTopWidth, e.borderBottomWidth) : n.scrollHeight - t(e.paddingTop, e.paddingBottom);
10
+ }
11
+ function q({
12
+ name: n,
13
+ value: e,
14
+ onChange: t,
11
15
  cssStyle: r,
12
- placeholder: x = "入力してください",
16
+ placeholder: a = "入力してください",
13
17
  isDisabled: i,
14
- isRequired: l,
15
- rows: g,
16
- maxLength: h = 100,
18
+ isRequired: p,
19
+ rows: x,
20
+ maxLength: b = 100,
17
21
  autocomplete: v = "off",
18
22
  validates: E = [],
19
23
  autoAdjustHeight: V
20
24
  }) {
21
- var m, c;
22
- const [u, C] = I([]), t = n(null), e = s ?? "", a = () => {
23
- C(B(e, { isRequired: l, validates: E }));
24
- }, M = n(e), f = n(!1);
25
- return A(() => {
26
- if (V && t.current && (t.current.style.height = "auto", t.current.style.height = `calc(${t.current.scrollHeight}px - 2rem)`), !f.current) {
27
- if (e === M.current) {
28
- k(e) || a();
25
+ var c, g;
26
+ const [l, B] = j([]), d = m(null), o = e ?? "", f = () => {
27
+ B(T(o, { isRequired: p, validates: E }));
28
+ }, C = m(o), s = m(!1);
29
+ return k(() => {
30
+ if (V && d.current) {
31
+ const u = d.current;
32
+ u.style.height = "auto", u.style.height = `${z(u)}px`;
33
+ }
34
+ if (!s.current) {
35
+ if (o === C.current) {
36
+ M(o) || f();
29
37
  return;
30
38
  }
31
- f.current = !0;
39
+ s.current = !0;
32
40
  }
33
- a();
34
- }, [e]), /* @__PURE__ */ j(
35
- H,
41
+ f();
42
+ }, [o]), /* @__PURE__ */ H(
43
+ I,
36
44
  {
37
45
  cssStyle: r,
38
46
  className: "min-h-[4em]",
39
- isErrored: !!u.length,
47
+ isErrored: !!l.length,
40
48
  isDisabled: i,
41
49
  children: [
42
- /* @__PURE__ */ p(
50
+ /* @__PURE__ */ h(
43
51
  "textarea",
44
52
  {
45
- ref: t,
46
- name: d,
47
- value: e,
48
- required: l,
49
- placeholder: x,
53
+ ref: d,
54
+ name: n,
55
+ value: o,
56
+ required: p,
57
+ placeholder: a,
50
58
  disabled: i,
51
59
  autoComplete: v,
52
- rows: g,
53
- maxLength: h,
54
- "aria-invalid": u.length ? "true" : void 0,
55
- onChange: (b) => o == null ? void 0 : o(b.target.value),
56
- onBlur: () => a()
60
+ rows: x,
61
+ maxLength: b,
62
+ "aria-invalid": l.length ? "true" : void 0,
63
+ onChange: (u) => t == null ? void 0 : t(u.target.value),
64
+ onBlur: () => f()
57
65
  }
58
66
  ),
59
- /* @__PURE__ */ p(
60
- N,
67
+ /* @__PURE__ */ h(
68
+ W,
61
69
  {
62
- errorMessages: u,
70
+ errorMessages: l,
63
71
  cssStyle: {
64
- textColor: (m = r == null ? void 0 : r.error) == null ? void 0 : m.backgroundColor,
65
- backgroundColor: (c = r == null ? void 0 : r.error) == null ? void 0 : c.textColor
72
+ textColor: (c = r == null ? void 0 : r.error) == null ? void 0 : c.backgroundColor,
73
+ backgroundColor: (g = r == null ? void 0 : r.error) == null ? void 0 : g.textColor
66
74
  }
67
75
  }
68
76
  )
@@ -71,5 +79,5 @@ function z({
71
79
  );
72
80
  }
73
81
  export {
74
- z as TextArea
82
+ q as TextArea
75
83
  };
@@ -23,11 +23,13 @@ type Props = {
23
23
  */
24
24
  role?: string;
25
25
  ariaLabel?: string;
26
+ /** 可視ラベルがあるなら、その要素の id をここで指す(ariaLabel より優先) */
27
+ ariaLabelledBy?: string;
26
28
  ariaExpanded?: boolean;
27
29
  ariaControls?: string;
28
30
  ariaActivedescendant?: string;
29
31
  ariaAutocomplete?: 'none' | 'inline' | 'list' | 'both';
30
32
  onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
31
33
  };
32
- export declare function TextBox({ name, value, onChange, cssStyle, inputType, placeholder, isDisabled, isRequired, maxLength, autocomplete, validates, before, after, id, role, ariaLabel, ariaExpanded, ariaControls, ariaActivedescendant, ariaAutocomplete, onKeyDown, }: Props): import("react").JSX.Element;
34
+ export declare function TextBox({ name, value, onChange, cssStyle, inputType, placeholder, isDisabled, isRequired, maxLength, autocomplete, validates, before, after, id, role, ariaLabel, ariaLabelledBy, ariaExpanded, ariaControls, ariaActivedescendant, ariaAutocomplete, onKeyDown, }: Props): import("react").JSX.Element;
33
35
  export {};