@nikala-ui/core 0.9.10 → 0.9.11-nightly.78f0a94
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 +1 -1
- package/package.json +2 -2
- package/registry/aspect-ratio.json +17 -0
- package/registry/collapsible.json +18 -0
- package/registry/combobox.json +18 -0
- package/registry/command.json +1 -1
- package/registry/hover-card.json +18 -0
- package/registry/index.json +64 -0
- package/registry/pin-input.json +17 -0
- package/registry/slider.json +18 -0
- package/src/registry/components/ui/aspect-ratio.tsx +31 -0
- package/src/registry/components/ui/collapsible.tsx +73 -0
- package/src/registry/components/ui/combobox.tsx +295 -0
- package/src/registry/components/ui/command.tsx +90 -7
- package/src/registry/components/ui/hover-card.tsx +105 -0
- package/src/registry/components/ui/pin-input.tsx +198 -0
- package/src/registry/components/ui/slider.tsx +153 -0
- package/src/registry/metadata.ts +30 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSignal,
|
|
3
|
+
createMemo,
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
type JSX,
|
|
7
|
+
} from "solid-js";
|
|
8
|
+
import { cn } from "@/lib/cn";
|
|
9
|
+
|
|
10
|
+
export type PinInputType = "numeric" | "alphanumeric";
|
|
11
|
+
|
|
12
|
+
export interface PinInputContextValue {
|
|
13
|
+
value: () => string;
|
|
14
|
+
setValue: (val: string) => void;
|
|
15
|
+
mask: () => boolean;
|
|
16
|
+
disabled: () => boolean;
|
|
17
|
+
length: () => number;
|
|
18
|
+
type: () => PinInputType;
|
|
19
|
+
containerRef: HTMLDivElement | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const PinInputContext = createContext<PinInputContextValue>();
|
|
23
|
+
|
|
24
|
+
export interface PinInputProps {
|
|
25
|
+
value?: string;
|
|
26
|
+
onValueChange?: (value: string) => void;
|
|
27
|
+
length?: number;
|
|
28
|
+
type?: PinInputType;
|
|
29
|
+
mask?: boolean;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
class?: string;
|
|
32
|
+
children?: JSX.Element;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Root PinInput component for 4 or 6-digit OTP / verification PIN codes.
|
|
37
|
+
*/
|
|
38
|
+
export const PinInput = (props: PinInputProps) => {
|
|
39
|
+
let containerRef: HTMLDivElement | undefined;
|
|
40
|
+
const [internalValue, setInternalValue] = createSignal(props.value ?? "");
|
|
41
|
+
|
|
42
|
+
const value = () => props.value ?? internalValue();
|
|
43
|
+
const mask = () => props.mask ?? false;
|
|
44
|
+
const disabled = () => props.disabled ?? false;
|
|
45
|
+
const length = () => props.length ?? 6;
|
|
46
|
+
|
|
47
|
+
const inputType = (): PinInputType => {
|
|
48
|
+
const t = props.type ?? "numeric";
|
|
49
|
+
if (t !== "numeric" && t !== "alphanumeric") {
|
|
50
|
+
return "numeric";
|
|
51
|
+
}
|
|
52
|
+
return t;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleValueChange = (val: string) => {
|
|
56
|
+
setInternalValue(val);
|
|
57
|
+
props.onValueChange?.(val);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const contextValue: PinInputContextValue = {
|
|
61
|
+
value,
|
|
62
|
+
setValue: handleValueChange,
|
|
63
|
+
mask,
|
|
64
|
+
disabled,
|
|
65
|
+
length,
|
|
66
|
+
type: inputType,
|
|
67
|
+
get containerRef() {
|
|
68
|
+
return containerRef;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<PinInputContext.Provider value={contextValue}>
|
|
74
|
+
<div ref={containerRef} class={cn("flex items-center gap-2", props.class)}>
|
|
75
|
+
{props.children}
|
|
76
|
+
</div>
|
|
77
|
+
</PinInputContext.Provider>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export interface PinInputLabelProps {
|
|
82
|
+
class?: string;
|
|
83
|
+
children?: JSX.Element;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Accessible label for PinInput.
|
|
88
|
+
*/
|
|
89
|
+
export const PinInputLabel = (props: PinInputLabelProps) => {
|
|
90
|
+
return (
|
|
91
|
+
<label class={cn("text-sm font-medium leading-none text-foreground", props.class)}>
|
|
92
|
+
{props.children}
|
|
93
|
+
</label>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const focusIndex = (containerRef: HTMLDivElement | undefined, index: number) => {
|
|
98
|
+
const el = containerRef?.querySelector<HTMLInputElement>(
|
|
99
|
+
`[data-pin-input-index="${index}"]`
|
|
100
|
+
);
|
|
101
|
+
el?.focus();
|
|
102
|
+
el?.select();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export interface PinInputInputProps {
|
|
106
|
+
index: number;
|
|
107
|
+
class?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Individual input slot for a single OTP digit/character.
|
|
112
|
+
*/
|
|
113
|
+
export const PinInputInput = (props: PinInputInputProps) => {
|
|
114
|
+
const ctx = useContext(PinInputContext);
|
|
115
|
+
const digit = createMemo(() => ctx?.value()[props.index] ?? "");
|
|
116
|
+
|
|
117
|
+
const isCharAllowed = (char: string) => {
|
|
118
|
+
if (!ctx || char === "") return false;
|
|
119
|
+
return ctx.type() === "numeric"
|
|
120
|
+
? /^[0-9]$/.test(char)
|
|
121
|
+
: /^[a-zA-Z0-9]$/.test(char);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const commitChar = (char: string) => {
|
|
125
|
+
if (!ctx) return;
|
|
126
|
+
const currentArray = ctx.value().split("");
|
|
127
|
+
while (currentArray.length < props.index) currentArray.push("");
|
|
128
|
+
currentArray[props.index] = char;
|
|
129
|
+
ctx.setValue(currentArray.join(""));
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleInput = (e: InputEvent & { currentTarget: HTMLInputElement }) => {
|
|
133
|
+
if (!ctx || ctx.disabled()) return;
|
|
134
|
+
const val = e.currentTarget.value;
|
|
135
|
+
const rawChar = val ? val[val.length - 1] : "";
|
|
136
|
+
|
|
137
|
+
// Clear digit if input is empty
|
|
138
|
+
if (rawChar === "") {
|
|
139
|
+
commitChar("");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!isCharAllowed(rawChar)) {
|
|
144
|
+
e.currentTarget.value = digit();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
commitChar(rawChar);
|
|
149
|
+
|
|
150
|
+
if (props.index < ctx.length() - 1) {
|
|
151
|
+
focusIndex(ctx.containerRef, props.index + 1);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
156
|
+
if (!ctx || ctx.disabled()) return;
|
|
157
|
+
if (e.key === "Backspace" && digit() === "" && props.index > 0) {
|
|
158
|
+
focusIndex(ctx.containerRef, props.index - 1);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const handlePaste = (e: ClipboardEvent & { currentTarget: HTMLInputElement }) => {
|
|
163
|
+
if (!ctx || ctx.disabled()) return;
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
const pasted = e.clipboardData?.getData("text") ?? "";
|
|
166
|
+
const chars = pasted.split("").filter(isCharAllowed);
|
|
167
|
+
if (chars.length === 0) return;
|
|
168
|
+
|
|
169
|
+
const currentArray = ctx.value().split("");
|
|
170
|
+
let lastFilled = props.index;
|
|
171
|
+
for (let i = 0; i < chars.length && props.index + i < ctx.length(); i++) {
|
|
172
|
+
while (currentArray.length < props.index + i) currentArray.push("");
|
|
173
|
+
currentArray[props.index + i] = chars[i];
|
|
174
|
+
lastFilled = props.index + i;
|
|
175
|
+
}
|
|
176
|
+
ctx.setValue(currentArray.join(""));
|
|
177
|
+
focusIndex(ctx.containerRef, Math.min(lastFilled + 1, ctx.length() - 1));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<input
|
|
182
|
+
type={ctx?.mask() ? "password" : "text"}
|
|
183
|
+
inputMode={ctx?.type() === "numeric" ? "numeric" : "text"}
|
|
184
|
+
autocomplete="one-time-code"
|
|
185
|
+
maxLength={1}
|
|
186
|
+
disabled={ctx?.disabled()}
|
|
187
|
+
data-pin-input-index={props.index}
|
|
188
|
+
value={digit()}
|
|
189
|
+
onInput={handleInput}
|
|
190
|
+
onKeyDown={handleKeyDown}
|
|
191
|
+
onPaste={handlePaste}
|
|
192
|
+
class={cn(
|
|
193
|
+
"relative flex h-10 w-10 text-center text-sm font-semibold rounded-md border border-input bg-background shadow-xs transition-all focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50",
|
|
194
|
+
props.class
|
|
195
|
+
)}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { splitProps, type JSX, type ValidComponent } from "solid-js";
|
|
2
|
+
import * as SliderPrimitive from "@kobalte/core/slider";
|
|
3
|
+
import { cn } from "@/lib/cn";
|
|
4
|
+
|
|
5
|
+
export type SliderRootProps<T extends ValidComponent = "div"> =
|
|
6
|
+
SliderPrimitive.SliderRootProps<T> & {
|
|
7
|
+
class?: string;
|
|
8
|
+
children?: JSX.Element;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Root Slider component built on Kobalte primitives.
|
|
13
|
+
*/
|
|
14
|
+
export const Slider = <T extends ValidComponent = "div">(
|
|
15
|
+
props: SliderRootProps<T>
|
|
16
|
+
) => {
|
|
17
|
+
const [local, rest] = splitProps(props as SliderRootProps, ["class", "children"]);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<SliderPrimitive.Root
|
|
21
|
+
class={cn(
|
|
22
|
+
"relative flex w-full touch-none select-none flex-col gap-2 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-auto data-[orientation=vertical]:items-center",
|
|
23
|
+
local.class
|
|
24
|
+
)}
|
|
25
|
+
{...(rest as any)}
|
|
26
|
+
>
|
|
27
|
+
{local.children}
|
|
28
|
+
</SliderPrimitive.Root>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SliderTrackProps<T extends ValidComponent = "div"> =
|
|
33
|
+
SliderPrimitive.SliderTrackProps<T> & {
|
|
34
|
+
class?: string;
|
|
35
|
+
children?: JSX.Element;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Slider track containing the active range fill and thumbs.
|
|
40
|
+
*/
|
|
41
|
+
export const SliderTrack = <T extends ValidComponent = "div">(
|
|
42
|
+
props: SliderTrackProps<T>
|
|
43
|
+
) => {
|
|
44
|
+
const [local, rest] = splitProps(props as SliderTrackProps, ["class", "children"]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<SliderPrimitive.Track
|
|
48
|
+
class={cn(
|
|
49
|
+
"relative h-2 w-full flex items-center rounded-lg bg-secondary cursor-pointer data-[orientation=vertical]:w-2 data-[orientation=vertical]:h-full data-[orientation=vertical]:flex-col data-[orientation=vertical]:justify-center",
|
|
50
|
+
local.class
|
|
51
|
+
)}
|
|
52
|
+
{...(rest as any)}
|
|
53
|
+
>
|
|
54
|
+
<SliderFill />
|
|
55
|
+
{local.children}
|
|
56
|
+
</SliderPrimitive.Track>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type SliderFillProps<T extends ValidComponent = "div"> =
|
|
61
|
+
SliderPrimitive.SliderFillProps<T> & {
|
|
62
|
+
class?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Active range indicator fill inside SliderTrack.
|
|
67
|
+
*/
|
|
68
|
+
export const SliderFill = <T extends ValidComponent = "div">(
|
|
69
|
+
props: SliderFillProps<T>
|
|
70
|
+
) => {
|
|
71
|
+
const [local, rest] = splitProps(props as SliderFillProps, ["class"]);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<SliderPrimitive.Fill
|
|
75
|
+
class={cn(
|
|
76
|
+
"absolute rounded-lg bg-primary data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full",
|
|
77
|
+
local.class
|
|
78
|
+
)}
|
|
79
|
+
{...(rest as any)}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type SliderThumbProps<T extends ValidComponent = "span"> =
|
|
85
|
+
SliderPrimitive.SliderThumbProps<T> & {
|
|
86
|
+
class?: string;
|
|
87
|
+
children?: JSX.Element;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Draggable thumb handle for selecting slider values.
|
|
92
|
+
* Positioned centered on Kobalte offset coordinates using -translate-x-1/2 -translate-y-1/2.
|
|
93
|
+
*/
|
|
94
|
+
export const SliderThumb = <T extends ValidComponent = "span">(
|
|
95
|
+
props: SliderThumbProps<T>
|
|
96
|
+
) => {
|
|
97
|
+
const [local, rest] = splitProps(props as SliderThumbProps, ["class", "children"]);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<SliderPrimitive.Thumb
|
|
101
|
+
class={cn(
|
|
102
|
+
"block h-5 w-5 rounded-lg border-2 border-primary bg-background shadow-md transition-transform hover:scale-110 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 cursor-grab active:cursor-grabbing z-10 data-[orientation=horizontal]:translate-x-0 data-[orientation=horizontal]:translate-y-0 data-[orientation=vertical]:translate-x-0 data-[orientation=vertical]:translate-y-0",
|
|
103
|
+
local.class
|
|
104
|
+
)}
|
|
105
|
+
{...(rest as any)}
|
|
106
|
+
>
|
|
107
|
+
<SliderPrimitive.Input />
|
|
108
|
+
{local.children}
|
|
109
|
+
</SliderPrimitive.Thumb>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type SliderLabelProps<T extends ValidComponent = "label"> =
|
|
114
|
+
SliderPrimitive.SliderLabelProps<T> & {
|
|
115
|
+
class?: string;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Accessible label for the Slider component.
|
|
120
|
+
*/
|
|
121
|
+
export const SliderLabel = <T extends ValidComponent = "label">(
|
|
122
|
+
props: SliderLabelProps<T>
|
|
123
|
+
) => {
|
|
124
|
+
const [local, rest] = splitProps(props as SliderLabelProps, ["class"]);
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<SliderPrimitive.Label
|
|
128
|
+
class={cn("text-sm font-medium leading-none text-foreground", local.class)}
|
|
129
|
+
{...(rest as any)}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type SliderValueLabelProps<T extends ValidComponent = "output"> =
|
|
135
|
+
SliderPrimitive.SliderValueLabelProps<T> & {
|
|
136
|
+
class?: string;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Displays current formatted value label for single or dual thumbs.
|
|
141
|
+
*/
|
|
142
|
+
export const SliderValueLabel = <T extends ValidComponent = "output">(
|
|
143
|
+
props: SliderValueLabelProps<T>
|
|
144
|
+
) => {
|
|
145
|
+
const [local, rest] = splitProps(props as SliderValueLabelProps, ["class"]);
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<SliderPrimitive.ValueLabel
|
|
149
|
+
class={cn("text-sm font-medium text-muted-foreground", local.class)}
|
|
150
|
+
{...(rest as any)}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
};
|
package/src/registry/metadata.ts
CHANGED
|
@@ -75,6 +75,11 @@ export const COMPONENT_METADATA: Record<string, ComponentMeta> = {
|
|
|
75
75
|
description: "Displays a list of options for the user to pick from, built on Kobalte primitives.",
|
|
76
76
|
dependencies: ["clsx", "tailwind-merge", "@kobalte/core"],
|
|
77
77
|
},
|
|
78
|
+
combobox: {
|
|
79
|
+
title: "Combobox",
|
|
80
|
+
description: "Searchable autocomplete dropdown with single/multi-selection tags, avatars, group headers, and customizable clear controls.",
|
|
81
|
+
dependencies: ["clsx", "tailwind-merge", "@kobalte/core"],
|
|
82
|
+
},
|
|
78
83
|
tabs: {
|
|
79
84
|
title: "Tabs",
|
|
80
85
|
description: "A set of layered sections of content displayed one at a time.",
|
|
@@ -169,6 +174,31 @@ export const COMPONENT_METADATA: Record<string, ComponentMeta> = {
|
|
|
169
174
|
description: "Displays an indicator showing the completion progress of a task or media playback, built on Kobalte primitives.",
|
|
170
175
|
dependencies: ["clsx", "tailwind-merge", "@kobalte/core"],
|
|
171
176
|
},
|
|
177
|
+
slider: {
|
|
178
|
+
title: "Slider",
|
|
179
|
+
description: "Numeric range selection slider supporting single/dual thumbs, custom steps, vertical orientation, and formatted value labels, built on Kobalte primitives.",
|
|
180
|
+
dependencies: ["clsx", "tailwind-merge", "@kobalte/core"],
|
|
181
|
+
},
|
|
182
|
+
collapsible: {
|
|
183
|
+
title: "Collapsible",
|
|
184
|
+
description: "An interactive component that expands and collapses content panels with smooth height animations, built on Kobalte primitives.",
|
|
185
|
+
dependencies: ["clsx", "tailwind-merge", "@kobalte/core"],
|
|
186
|
+
},
|
|
187
|
+
"aspect-ratio": {
|
|
188
|
+
title: "Aspect Ratio",
|
|
189
|
+
description: "Displays content within a specific aspect ratio using CSS aspect-ratio while preventing layout shifts.",
|
|
190
|
+
dependencies: ["clsx", "tailwind-merge"],
|
|
191
|
+
},
|
|
192
|
+
"pin-input": {
|
|
193
|
+
title: "Pin Input",
|
|
194
|
+
description: "Interactive multi-slot PIN/OTP input component for SMS and 2FA authentication verification codes.",
|
|
195
|
+
dependencies: ["clsx", "tailwind-merge"],
|
|
196
|
+
},
|
|
197
|
+
"hover-card": {
|
|
198
|
+
title: "Hover Card",
|
|
199
|
+
description: "Profile and link preview popover triggered on hover, built on Kobalte primitives.",
|
|
200
|
+
dependencies: ["clsx", "tailwind-merge", "@kobalte/core"],
|
|
201
|
+
},
|
|
172
202
|
};
|
|
173
203
|
|
|
174
204
|
/**
|