@geckou/ui-react 0.8.0 → 0.9.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.
- package/README.md +7 -0
- package/dist/components/DropdownUi.js +90 -73
- package/dist/components/SlideDownUi.js +22 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,6 +108,13 @@ props は Vue 版(`@geckou/ui-vue`)と揃えている。`v-model` にあた
|
|
|
108
108
|
yarn workspace @geckou/ui-react test
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
## 0.9.0 の変更
|
|
112
|
+
|
|
113
|
+
- `DropdownUi` が Escape で閉じ、トリガーへフォーカスを戻す。処理したときは
|
|
114
|
+
`preventDefault()` するので、`ModalBox` の中に置いてもダイアログまで閉じない
|
|
115
|
+
- `DropdownUi` / `SlideDownUi` のトリガーに `aria-controls` が付き、
|
|
116
|
+
`DropdownUi` には `aria-haspopup="true"` も付く
|
|
117
|
+
|
|
111
118
|
## 0.8.0 の変更
|
|
112
119
|
|
|
113
120
|
- `BasicButton` はローディング中に `disabled` にしない(押した瞬間にフォーカスが
|
|
@@ -1,88 +1,105 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { KeyboardArrowDownIcon as
|
|
5
|
-
import { COLOR as
|
|
6
|
-
function
|
|
7
|
-
isHiddenArrow:
|
|
8
|
-
contentAlignment:
|
|
9
|
-
isDisabled:
|
|
10
|
-
contentsWidth:
|
|
11
|
-
trigger:
|
|
12
|
-
contents:
|
|
13
|
-
ref:
|
|
2
|
+
import { jsxs as b, jsx as l } from "react/jsx-runtime";
|
|
3
|
+
import { useState as g, useRef as i, useId as H, useImperativeHandle as N, useEffect as h } from "react";
|
|
4
|
+
import { KeyboardArrowDownIcon as S } from "./icons/KeyboardArrowDownIcon.js";
|
|
5
|
+
import { COLOR as w } from "@geckou/ui-core";
|
|
6
|
+
function K({
|
|
7
|
+
isHiddenArrow: x = !1,
|
|
8
|
+
contentAlignment: c = "left",
|
|
9
|
+
isDisabled: a = !1,
|
|
10
|
+
contentsWidth: C = "auto",
|
|
11
|
+
trigger: y,
|
|
12
|
+
contents: t,
|
|
13
|
+
ref: k
|
|
14
14
|
}) {
|
|
15
|
-
const [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const [n, u] = g(!1), [z, I] = g(0), d = i(null), f = i(null), m = i(null), p = `${H()}-panel`, O = () => u((e) => !e), r = () => u(!1), R = () => {
|
|
16
|
+
var e;
|
|
17
|
+
r(), (e = m.current) == null || e.focus();
|
|
18
|
+
};
|
|
19
|
+
N(k, () => ({
|
|
20
|
+
isContentsOpened: () => n,
|
|
21
|
+
close: r
|
|
22
|
+
})), h(() => {
|
|
23
|
+
const e = (s) => {
|
|
24
|
+
const o = d.current;
|
|
25
|
+
o && !o.contains(s.target) && r();
|
|
23
26
|
};
|
|
24
27
|
return document.addEventListener("pointerdown", e), () => document.removeEventListener("pointerdown", e);
|
|
25
|
-
}, []),
|
|
26
|
-
const e =
|
|
28
|
+
}, []), h(() => {
|
|
29
|
+
const e = f.current;
|
|
27
30
|
if (!e)
|
|
28
31
|
return;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
}, [!!
|
|
34
|
-
const
|
|
35
|
-
"--trigger-color":
|
|
36
|
-
},
|
|
37
|
-
boxShadow:
|
|
38
|
-
blockSize:
|
|
39
|
-
inlineSize:
|
|
40
|
-
right:
|
|
41
|
-
left:
|
|
32
|
+
const s = () => I(e.clientHeight);
|
|
33
|
+
s();
|
|
34
|
+
const o = new ResizeObserver(s);
|
|
35
|
+
return o.observe(e), () => o.disconnect();
|
|
36
|
+
}, [!!t]);
|
|
37
|
+
const v = a || !t, D = {
|
|
38
|
+
"--trigger-color": v ? w.black : w.blue
|
|
39
|
+
}, E = {
|
|
40
|
+
boxShadow: n ? "0 0 6px #33333333" : "none",
|
|
41
|
+
blockSize: n ? `${z}px` : 0,
|
|
42
|
+
inlineSize: C,
|
|
43
|
+
right: c === "right" ? "calc(var(--bv, 0.375rem) * -0.5)" : "auto",
|
|
44
|
+
left: c === "left" ? "calc(var(--bv, 0.375rem) * -0.5)" : "auto",
|
|
42
45
|
zIndex: 2
|
|
43
46
|
};
|
|
44
|
-
return /* @__PURE__ */
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
return /* @__PURE__ */ b(
|
|
48
|
+
"div",
|
|
49
|
+
{
|
|
50
|
+
ref: d,
|
|
51
|
+
className: "relative",
|
|
52
|
+
onKeyDown: (e) => {
|
|
53
|
+
e.key !== "Escape" || !n || (e.preventDefault(), R());
|
|
54
|
+
},
|
|
55
|
+
children: [
|
|
56
|
+
/* @__PURE__ */ b(
|
|
57
|
+
"button",
|
|
58
|
+
{
|
|
59
|
+
ref: m,
|
|
60
|
+
type: "button",
|
|
61
|
+
disabled: a,
|
|
62
|
+
"aria-expanded": n,
|
|
63
|
+
"aria-haspopup": t ? !0 : void 0,
|
|
64
|
+
"aria-controls": t ? p : void 0,
|
|
65
|
+
style: { ...D, cursor: v ? "auto" : "pointer" },
|
|
66
|
+
className: "flex size-full items-center gap-[var(--sp-small,0.375rem)] text-(--trigger-color)",
|
|
67
|
+
onClick: (e) => {
|
|
68
|
+
e.preventDefault(), O();
|
|
69
|
+
},
|
|
70
|
+
children: [
|
|
71
|
+
y,
|
|
72
|
+
!(x || !t || a) && /* @__PURE__ */ l(
|
|
73
|
+
S,
|
|
74
|
+
{
|
|
75
|
+
className: `size-[var(--icon-small,0.9375rem)] flex-none transition-all duration-100 ${n ? "rotate-180" : ""}`
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
t && /* @__PURE__ */ l(
|
|
74
82
|
"div",
|
|
75
83
|
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
id: p,
|
|
85
|
+
style: E,
|
|
86
|
+
inert: !n,
|
|
87
|
+
className: "absolute top-[calc(100%-var(--sp-min,0.1875rem))] cursor-pointer overflow-hidden rounded-[var(--radius-small,0.1875rem)] transition-[block-size] duration-100",
|
|
88
|
+
children: /* @__PURE__ */ l(
|
|
89
|
+
"div",
|
|
90
|
+
{
|
|
91
|
+
ref: f,
|
|
92
|
+
className: "max-h-[calc(var(--bv,0.375rem)*56)] min-w-[calc(var(--bv,0.375rem)*20)] overflow-auto bg-white",
|
|
93
|
+
onClick: r,
|
|
94
|
+
children: t
|
|
95
|
+
}
|
|
96
|
+
)
|
|
80
97
|
}
|
|
81
98
|
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
);
|
|
85
102
|
}
|
|
86
103
|
export {
|
|
87
|
-
|
|
104
|
+
K as DropdownUi
|
|
88
105
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs as v, jsx as i } from "react/jsx-runtime";
|
|
3
|
-
import { useState as a, useRef as
|
|
4
|
-
import { KeyboardArrowDownIcon as
|
|
5
|
-
import { COLOR as
|
|
6
|
-
function
|
|
3
|
+
import { useState as a, useRef as h, useId as E, useImperativeHandle as N, useEffect as l } from "react";
|
|
4
|
+
import { KeyboardArrowDownIcon as O } from "./icons/KeyboardArrowDownIcon.js";
|
|
5
|
+
import { COLOR as $ } from "@geckou/ui-core";
|
|
6
|
+
function S({
|
|
7
7
|
isOpened: n = null,
|
|
8
|
-
isHiddenArrow:
|
|
9
|
-
isDisabled:
|
|
8
|
+
isHiddenArrow: b = !1,
|
|
9
|
+
isDisabled: g = !1,
|
|
10
10
|
isDisableClickOutside: f = !1,
|
|
11
11
|
duration: c = 0.3,
|
|
12
|
-
trigger:
|
|
13
|
-
children:
|
|
14
|
-
ref:
|
|
12
|
+
trigger: w,
|
|
13
|
+
children: x,
|
|
14
|
+
ref: C
|
|
15
15
|
}) {
|
|
16
|
-
const [t, r] = a(n || !1), [
|
|
17
|
-
|
|
16
|
+
const [t, r] = a(n || !1), [y, u] = a(n || !1), [I, k] = a(0), d = h(null), m = h(null), p = `${E()}-panel`, H = () => r((e) => !e);
|
|
17
|
+
N(C, () => ({
|
|
18
18
|
isOpenedContents: () => t,
|
|
19
19
|
close: () => r(!1)
|
|
20
20
|
})), l(() => {
|
|
@@ -43,22 +43,23 @@ function $({
|
|
|
43
43
|
const e = setTimeout(() => u(!0), c * 1e3);
|
|
44
44
|
return () => clearTimeout(e);
|
|
45
45
|
}, [t, c]);
|
|
46
|
-
const R = { "--link-color":
|
|
46
|
+
const R = { "--link-color": $.blue };
|
|
47
47
|
return /* @__PURE__ */ v("div", { ref: d, style: R, children: [
|
|
48
48
|
/* @__PURE__ */ v(
|
|
49
49
|
"button",
|
|
50
50
|
{
|
|
51
51
|
type: "button",
|
|
52
|
-
disabled:
|
|
52
|
+
disabled: g,
|
|
53
53
|
"aria-expanded": t,
|
|
54
|
+
"aria-controls": p,
|
|
54
55
|
className: "relative grid w-full cursor-pointer grid-cols-[1fr_auto] items-center justify-items-start text-(--link-color)",
|
|
55
56
|
onClick: (e) => {
|
|
56
57
|
e.preventDefault(), H();
|
|
57
58
|
},
|
|
58
59
|
children: [
|
|
59
|
-
/* @__PURE__ */ i("span", { className: "block w-full text-left", children:
|
|
60
|
-
!
|
|
61
|
-
|
|
60
|
+
/* @__PURE__ */ i("span", { className: "block w-full text-left", children: w }),
|
|
61
|
+
!b && /* @__PURE__ */ i(
|
|
62
|
+
O,
|
|
62
63
|
{
|
|
63
64
|
className: `size-[var(--icon-medium,1.125rem)] flex-none text-(--link-color) transition-all duration-100 ${t ? "rotate-180" : ""}`
|
|
64
65
|
}
|
|
@@ -69,18 +70,19 @@ function $({
|
|
|
69
70
|
/* @__PURE__ */ i(
|
|
70
71
|
"div",
|
|
71
72
|
{
|
|
73
|
+
id: p,
|
|
72
74
|
style: {
|
|
73
|
-
height: t ? `${
|
|
75
|
+
height: t ? `${I}px` : 0,
|
|
74
76
|
transitionDuration: `${c}s`,
|
|
75
|
-
overflow:
|
|
77
|
+
overflow: y ? "visible" : "hidden"
|
|
76
78
|
},
|
|
77
79
|
inert: !t,
|
|
78
80
|
className: "transition-[height]",
|
|
79
|
-
children: /* @__PURE__ */ i("div", { ref: m, children:
|
|
81
|
+
children: /* @__PURE__ */ i("div", { ref: m, children: x })
|
|
80
82
|
}
|
|
81
83
|
)
|
|
82
84
|
] });
|
|
83
85
|
}
|
|
84
86
|
export {
|
|
85
|
-
|
|
87
|
+
S as SlideDownUi
|
|
86
88
|
};
|