@passui/react 0.1.14 → 0.1.15
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/package.json
CHANGED
|
@@ -10,12 +10,18 @@ import { cn } from "../../lib/class-names"
|
|
|
10
10
|
export function TabView<Value extends string>({
|
|
11
11
|
options,
|
|
12
12
|
defaultValue,
|
|
13
|
+
value: controlledValue,
|
|
14
|
+
onValueChange,
|
|
15
|
+
align = "center",
|
|
13
16
|
label,
|
|
14
17
|
children,
|
|
15
18
|
className,
|
|
16
19
|
}: {
|
|
17
20
|
options: readonly { value: Value; label: string }[]
|
|
18
21
|
defaultValue: Value
|
|
22
|
+
value?: Value
|
|
23
|
+
onValueChange?: (value: Value) => void
|
|
24
|
+
align?: "start" | "center"
|
|
19
25
|
label: string
|
|
20
26
|
children: (value: Value) => ReactNode
|
|
21
27
|
className?: string
|
|
@@ -23,10 +29,15 @@ export function TabView<Value extends string>({
|
|
|
23
29
|
const id = useId()
|
|
24
30
|
const buttons = useRef<(HTMLButtonElement | null)[]>([])
|
|
25
31
|
const [selected, setSelected] = useState(defaultValue)
|
|
32
|
+
const current = controlledValue ?? selected
|
|
33
|
+
function select(next: Value) {
|
|
34
|
+
if (controlledValue === undefined) setSelected(next)
|
|
35
|
+
onValueChange?.(next)
|
|
36
|
+
}
|
|
26
37
|
const value = options.some(
|
|
27
|
-
(option) => option.value ===
|
|
38
|
+
(option) => option.value === current
|
|
28
39
|
)
|
|
29
|
-
?
|
|
40
|
+
? current
|
|
30
41
|
: options[0]?.value
|
|
31
42
|
if (value === undefined) return null
|
|
32
43
|
|
|
@@ -40,7 +51,12 @@ export function TabView<Value extends string>({
|
|
|
40
51
|
<div
|
|
41
52
|
role="tablist"
|
|
42
53
|
aria-label={label}
|
|
43
|
-
className=
|
|
54
|
+
className={cn(
|
|
55
|
+
"inline-flex h-8 w-fit max-w-full items-center gap-5 p-[3px]",
|
|
56
|
+
align === "start"
|
|
57
|
+
? "self-start"
|
|
58
|
+
: "mx-auto justify-center"
|
|
59
|
+
)}
|
|
44
60
|
>
|
|
45
61
|
{options.map((option, index) => (
|
|
46
62
|
<button
|
|
@@ -56,9 +72,7 @@ export function TabView<Value extends string>({
|
|
|
56
72
|
ref={(element) => {
|
|
57
73
|
buttons.current[index] = element
|
|
58
74
|
}}
|
|
59
|
-
onClick={() =>
|
|
60
|
-
setSelected(option.value)
|
|
61
|
-
}
|
|
75
|
+
onClick={() => select(option.value)}
|
|
62
76
|
onKeyDown={(event) => {
|
|
63
77
|
const rtl =
|
|
64
78
|
getComputedStyle(
|
|
@@ -82,8 +96,7 @@ export function TabView<Value extends string>({
|
|
|
82
96
|
(next + options.length) %
|
|
83
97
|
options.length
|
|
84
98
|
const option = options[next]
|
|
85
|
-
if (option)
|
|
86
|
-
setSelected(option.value)
|
|
99
|
+
if (option) select(option.value)
|
|
87
100
|
buttons.current[next]?.focus()
|
|
88
101
|
}}
|
|
89
102
|
className={cn(
|