@surreal-ui/svelte 0.5.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/CHANGELOG.md +66 -0
- package/package.json +33 -0
- package/src/components/GlassmorphismAlert.svelte +37 -0
- package/src/components/GlassmorphismButton.svelte +16 -0
- package/src/components/GlassmorphismCard.svelte +37 -0
- package/src/components/GlassmorphismEmptyState.svelte +19 -0
- package/src/components/GlassmorphismInputGroup.svelte +124 -0
- package/src/components/GlassmorphismMenubar.svelte +98 -0
- package/src/components/GlassmorphismScrollArea.svelte +61 -0
- package/src/components/GlassmorphismTable.svelte +54 -0
- package/src/components/GlassmorphismTypography.svelte +31 -0
- package/src/components/MinimalistAccordion.svelte +189 -0
- package/src/components/MinimalistAlert.svelte +35 -0
- package/src/components/MinimalistAlertDialog.svelte +247 -0
- package/src/components/MinimalistAspectRatio.svelte +31 -0
- package/src/components/MinimalistAvatar.svelte +127 -0
- package/src/components/MinimalistBadge.svelte +60 -0
- package/src/components/MinimalistBreadcrumb.svelte +141 -0
- package/src/components/MinimalistButton.svelte +94 -0
- package/src/components/MinimalistButtonGroup.svelte +93 -0
- package/src/components/MinimalistCalendar.svelte +307 -0
- package/src/components/MinimalistCard.svelte +87 -0
- package/src/components/MinimalistCarousel.svelte +258 -0
- package/src/components/MinimalistChart.svelte +225 -0
- package/src/components/MinimalistCheckbox.svelte +95 -0
- package/src/components/MinimalistCodeBlock.svelte +189 -0
- package/src/components/MinimalistCollapsible.svelte +88 -0
- package/src/components/MinimalistCommand.svelte +299 -0
- package/src/components/MinimalistContextMenu.svelte +236 -0
- package/src/components/MinimalistDialog.svelte +218 -0
- package/src/components/MinimalistDrawer.svelte +209 -0
- package/src/components/MinimalistDropdownMenu.svelte +349 -0
- package/src/components/MinimalistEmpty.svelte +136 -0
- package/src/components/MinimalistEmptyState.svelte +27 -0
- package/src/components/MinimalistField.svelte +239 -0
- package/src/components/MinimalistForm.svelte +157 -0
- package/src/components/MinimalistHoverCard.svelte +71 -0
- package/src/components/MinimalistInput.svelte +53 -0
- package/src/components/MinimalistInputGroup.svelte +165 -0
- package/src/components/MinimalistInputOtp.svelte +171 -0
- package/src/components/MinimalistItem.svelte +225 -0
- package/src/components/MinimalistKbd.svelte +39 -0
- package/src/components/MinimalistLabel.svelte +26 -0
- package/src/components/MinimalistMenubar.svelte +373 -0
- package/src/components/MinimalistNativeSelect.svelte +81 -0
- package/src/components/MinimalistNavigationMenu.svelte +188 -0
- package/src/components/MinimalistPagination.svelte +189 -0
- package/src/components/MinimalistPopover.svelte +160 -0
- package/src/components/MinimalistProgress.svelte +42 -0
- package/src/components/MinimalistRadioGroup.svelte +90 -0
- package/src/components/MinimalistRangeCalendar.svelte +273 -0
- package/src/components/MinimalistResizable.svelte +45 -0
- package/src/components/MinimalistScrollArea.svelte +24 -0
- package/src/components/MinimalistSelect.svelte +237 -0
- package/src/components/MinimalistSeparator.svelte +35 -0
- package/src/components/MinimalistSheet.svelte +189 -0
- package/src/components/MinimalistSidebar.svelte +601 -0
- package/src/components/MinimalistSkeleton.svelte +19 -0
- package/src/components/MinimalistSlider.svelte +192 -0
- package/src/components/MinimalistSonner.svelte +30 -0
- package/src/components/MinimalistSpinner.svelte +35 -0
- package/src/components/MinimalistSwitch.svelte +67 -0
- package/src/components/MinimalistTable.svelte +53 -0
- package/src/components/MinimalistTabs.svelte +169 -0
- package/src/components/MinimalistTextarea.svelte +31 -0
- package/src/components/MinimalistToggle.svelte +74 -0
- package/src/components/MinimalistToggleGroup.svelte +184 -0
- package/src/components/MinimalistTooltip.svelte +121 -0
- package/src/components/MinimalistTypography.svelte +25 -0
- package/src/components/NeubrutalismCard.svelte +85 -0
- package/src/components/NeubrutalismItem.svelte +53 -0
- package/src/components/ShadcnAccordion.svelte +189 -0
- package/src/components/ShadcnAlertDialog.svelte +247 -0
- package/src/components/ShadcnAspectRatio.svelte +31 -0
- package/src/components/ShadcnAvatar.svelte +127 -0
- package/src/components/ShadcnBadge.svelte +60 -0
- package/src/components/ShadcnBreadcrumb.svelte +141 -0
- package/src/components/ShadcnButton.svelte +94 -0
- package/src/components/ShadcnButtonGroup.svelte +93 -0
- package/src/components/ShadcnCalendar.svelte +307 -0
- package/src/components/ShadcnCarousel.svelte +258 -0
- package/src/components/ShadcnChart.svelte +225 -0
- package/src/components/ShadcnCheckbox.svelte +95 -0
- package/src/components/ShadcnCodeBlock.svelte +189 -0
- package/src/components/ShadcnCollapsible.svelte +88 -0
- package/src/components/ShadcnCommand.svelte +299 -0
- package/src/components/ShadcnContextMenu.svelte +236 -0
- package/src/components/ShadcnDialog.svelte +218 -0
- package/src/components/ShadcnDrawer.svelte +209 -0
- package/src/components/ShadcnDropdownMenu.svelte +349 -0
- package/src/components/ShadcnEmpty.svelte +136 -0
- package/src/components/ShadcnField.svelte +239 -0
- package/src/components/ShadcnForm.svelte +157 -0
- package/src/components/ShadcnHoverCard.svelte +71 -0
- package/src/components/ShadcnInput.svelte +53 -0
- package/src/components/ShadcnInputGroup.svelte +165 -0
- package/src/components/ShadcnInputOtp.svelte +171 -0
- package/src/components/ShadcnItem.svelte +225 -0
- package/src/components/ShadcnKbd.svelte +39 -0
- package/src/components/ShadcnLabel.svelte +26 -0
- package/src/components/ShadcnMenubar.svelte +373 -0
- package/src/components/ShadcnNativeSelect.svelte +81 -0
- package/src/components/ShadcnNavigationMenu.svelte +188 -0
- package/src/components/ShadcnPagination.svelte +189 -0
- package/src/components/ShadcnPopover.svelte +160 -0
- package/src/components/ShadcnProgress.svelte +42 -0
- package/src/components/ShadcnRadioGroup.svelte +90 -0
- package/src/components/ShadcnRangeCalendar.svelte +273 -0
- package/src/components/ShadcnSelect.svelte +237 -0
- package/src/components/ShadcnSeparator.svelte +35 -0
- package/src/components/ShadcnSheet.svelte +189 -0
- package/src/components/ShadcnSidebar.svelte +601 -0
- package/src/components/ShadcnSkeleton.svelte +19 -0
- package/src/components/ShadcnSlider.svelte +192 -0
- package/src/components/ShadcnSonner.svelte +30 -0
- package/src/components/ShadcnSpinner.svelte +35 -0
- package/src/components/ShadcnSwitch.svelte +67 -0
- package/src/components/ShadcnTabs.svelte +169 -0
- package/src/components/ShadcnTextarea.svelte +31 -0
- package/src/components/ShadcnToggle.svelte +74 -0
- package/src/components/ShadcnToggleGroup.svelte +184 -0
- package/src/components/ShadcnTooltip.svelte +121 -0
- package/src/index.d.ts +123 -0
- package/src/index.js +123 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
export interface ShadcnSliderProps {
|
|
5
|
+
value?: number[];
|
|
6
|
+
defaultValue?: number[];
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
step?: number;
|
|
10
|
+
orientation?: 'horizontal' | 'vertical';
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
name?: string;
|
|
13
|
+
class?: string;
|
|
14
|
+
onValueChange?: (val: number[]) => void;
|
|
15
|
+
onValueCommit?: (val: number[]) => void;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
value = $bindable(),
|
|
21
|
+
defaultValue = [0],
|
|
22
|
+
min = 0,
|
|
23
|
+
max = 100,
|
|
24
|
+
step = 1,
|
|
25
|
+
orientation = 'horizontal',
|
|
26
|
+
disabled = false,
|
|
27
|
+
name = undefined,
|
|
28
|
+
class: className = '',
|
|
29
|
+
onValueChange,
|
|
30
|
+
onValueCommit,
|
|
31
|
+
...restProps
|
|
32
|
+
}: ShadcnSliderProps = $props();
|
|
33
|
+
|
|
34
|
+
let internalValues = $state<number[]>(value ?? defaultValue);
|
|
35
|
+
|
|
36
|
+
$effect(() => {
|
|
37
|
+
if (value !== undefined) {
|
|
38
|
+
internalValues = [...value];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let activeIndex = $state<number | null>(null);
|
|
43
|
+
let trackEl = $state<HTMLElement | null>(null);
|
|
44
|
+
|
|
45
|
+
function getPercentage(val: number): number {
|
|
46
|
+
return Math.max(0, Math.min(100, ((val - min) / (max - min)) * 100));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getValueFromPointer(e: PointerEvent): number {
|
|
50
|
+
if (!trackEl) return min;
|
|
51
|
+
const rect = trackEl.getBoundingClientRect();
|
|
52
|
+
let percent = 0;
|
|
53
|
+
if (orientation === 'horizontal') {
|
|
54
|
+
percent = (e.clientX - rect.left) / rect.width;
|
|
55
|
+
} else {
|
|
56
|
+
percent = (rect.bottom - e.clientY) / rect.height;
|
|
57
|
+
}
|
|
58
|
+
percent = Math.max(0, Math.min(1, percent));
|
|
59
|
+
const rawVal = min + percent * (max - min);
|
|
60
|
+
const steppedVal = Math.round(rawVal / step) * step;
|
|
61
|
+
return Math.max(min, Math.min(max, steppedVal));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handlePointerDown(e: PointerEvent) {
|
|
65
|
+
if (disabled) return;
|
|
66
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
67
|
+
const pointerVal = getValueFromPointer(e);
|
|
68
|
+
let closestIdx = 0;
|
|
69
|
+
let minDiff = Infinity;
|
|
70
|
+
internalValues.forEach((val, idx) => {
|
|
71
|
+
const diff = Math.abs(val - pointerVal);
|
|
72
|
+
if (diff < minDiff) {
|
|
73
|
+
minDiff = diff;
|
|
74
|
+
closestIdx = idx;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
activeIndex = closestIdx;
|
|
78
|
+
updateValue(closestIdx, pointerVal);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function handlePointerMove(e: PointerEvent) {
|
|
82
|
+
if (disabled || activeIndex === null) return;
|
|
83
|
+
const pointerVal = getValueFromPointer(e);
|
|
84
|
+
updateValue(activeIndex, pointerVal);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function handlePointerUp(e: PointerEvent) {
|
|
88
|
+
if (disabled || activeIndex === null) return;
|
|
89
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
90
|
+
activeIndex = null;
|
|
91
|
+
if (onValueCommit) onValueCommit(internalValues);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function updateValue(index: number, newVal: number) {
|
|
95
|
+
const next = [...internalValues];
|
|
96
|
+
next[index] = newVal;
|
|
97
|
+
if (next.length === 2) {
|
|
98
|
+
if (index === 0 && next[0] > next[1]) next[0] = next[1];
|
|
99
|
+
if (index === 1 && next[1] < next[0]) next[1] = next[0];
|
|
100
|
+
}
|
|
101
|
+
internalValues = next;
|
|
102
|
+
value = next;
|
|
103
|
+
if (onValueChange) onValueChange(next);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function handleKeyDown(e: KeyboardEvent, index: number) {
|
|
107
|
+
if (disabled) return;
|
|
108
|
+
let delta = 0;
|
|
109
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') delta = step;
|
|
110
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') delta = -step;
|
|
111
|
+
else if (e.key === 'PageUp') delta = step * 10;
|
|
112
|
+
else if (e.key === 'PageDown') delta = -step * 10;
|
|
113
|
+
else if (e.key === 'Home') delta = min - internalValues[index];
|
|
114
|
+
else if (e.key === 'End') delta = max - internalValues[index];
|
|
115
|
+
else return;
|
|
116
|
+
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
const newVal = Math.max(min, Math.min(max, internalValues[index] + delta));
|
|
119
|
+
updateValue(index, newVal);
|
|
120
|
+
if (onValueCommit) onValueCommit(internalValues);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let rangeStyle = $derived.by(() => {
|
|
124
|
+
if (internalValues.length === 1) {
|
|
125
|
+
const pct = getPercentage(internalValues[0]);
|
|
126
|
+
return orientation === 'horizontal'
|
|
127
|
+
? `left: 0%; width: ${pct}%;`
|
|
128
|
+
: `bottom: 0%; height: ${pct}%;`;
|
|
129
|
+
} else {
|
|
130
|
+
const p1 = getPercentage(internalValues[0]);
|
|
131
|
+
const p2 = getPercentage(internalValues[1]);
|
|
132
|
+
const left = Math.min(p1, p2);
|
|
133
|
+
const size = Math.abs(p2 - p1);
|
|
134
|
+
return orientation === 'horizontal'
|
|
135
|
+
? `left: ${left}%; width: ${size}%;`
|
|
136
|
+
: `bottom: ${left}%; height: ${size}%;`;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
<div
|
|
142
|
+
role="group"
|
|
143
|
+
data-slot="slider"
|
|
144
|
+
data-orientation={orientation}
|
|
145
|
+
data-disabled={disabled ? '' : undefined}
|
|
146
|
+
class={cn(
|
|
147
|
+
'relative flex w-full touch-none select-none items-center',
|
|
148
|
+
orientation === 'vertical' ? 'h-full min-h-40 w-auto flex-col' : 'h-auto w-full flex-row',
|
|
149
|
+
disabled && 'opacity-50 pointer-events-none',
|
|
150
|
+
className,
|
|
151
|
+
)}
|
|
152
|
+
onpointerdown={handlePointerDown}
|
|
153
|
+
onpointermove={handlePointerMove}
|
|
154
|
+
onpointerup={handlePointerUp}
|
|
155
|
+
{...restProps}
|
|
156
|
+
>
|
|
157
|
+
<span
|
|
158
|
+
bind:this={trackEl}
|
|
159
|
+
data-slot="slider-track"
|
|
160
|
+
data-orientation={orientation}
|
|
161
|
+
class={cn(
|
|
162
|
+
'relative grow overflow-hidden rounded-full bg-muted',
|
|
163
|
+
orientation === 'horizontal' ? 'h-1.5 w-full' : 'h-full w-1.5',
|
|
164
|
+
)}
|
|
165
|
+
>
|
|
166
|
+
<span
|
|
167
|
+
data-slot="slider-range"
|
|
168
|
+
data-orientation={orientation}
|
|
169
|
+
class="absolute bg-primary"
|
|
170
|
+
style={rangeStyle}
|
|
171
|
+
></span>
|
|
172
|
+
</span>
|
|
173
|
+
|
|
174
|
+
{#each internalValues as val, idx (idx)}
|
|
175
|
+
{@const pct = getPercentage(val)}
|
|
176
|
+
<span
|
|
177
|
+
role="slider"
|
|
178
|
+
tabindex={disabled ? -1 : 0}
|
|
179
|
+
aria-valuemin={min}
|
|
180
|
+
aria-valuemax={max}
|
|
181
|
+
aria-valuenow={val}
|
|
182
|
+
aria-orientation={orientation}
|
|
183
|
+
aria-disabled={disabled}
|
|
184
|
+
data-slot="slider-thumb"
|
|
185
|
+
class="absolute block size-4 shrink-0 rounded-full border border-primary bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
|
|
186
|
+
style={orientation === 'horizontal'
|
|
187
|
+
? `left: calc(${pct}% - 8px); top: 50%; transform: translateY(-50%);`
|
|
188
|
+
: `bottom: calc(${pct}% - 8px); left: 50%; transform: translateX(-50%);`}
|
|
189
|
+
onkeydown={(e) => handleKeyDown(e, idx)}
|
|
190
|
+
></span>
|
|
191
|
+
{/each}
|
|
192
|
+
</div>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { mode } from 'mode-watcher';
|
|
3
|
+
import { Toaster as Sonner, type ToasterProps as SonnerProps } from 'svelte-sonner';
|
|
4
|
+
import { Loader2, CircleCheck, OctagonX, Info, TriangleAlert } from '@lucide/svelte';
|
|
5
|
+
|
|
6
|
+
let { ...restProps }: ShadcnSonnerProps = $props();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<Sonner
|
|
10
|
+
theme={mode?.current ?? 'light'}
|
|
11
|
+
class="toaster group"
|
|
12
|
+
style="--normal-bg: var(--color-popover); --normal-text: var(--color-popover-foreground); --normal-border: var(--color-border);"
|
|
13
|
+
{...restProps}
|
|
14
|
+
>
|
|
15
|
+
{#snippet loadingIcon()}
|
|
16
|
+
<Loader2 class="size-4 animate-spin" />
|
|
17
|
+
{/snippet}
|
|
18
|
+
{#snippet successIcon()}
|
|
19
|
+
<CircleCheck class="size-4" />
|
|
20
|
+
{/snippet}
|
|
21
|
+
{#snippet errorIcon()}
|
|
22
|
+
<OctagonX class="size-4" />
|
|
23
|
+
{/snippet}
|
|
24
|
+
{#snippet infoIcon()}
|
|
25
|
+
<Info class="size-4" />
|
|
26
|
+
{/snippet}
|
|
27
|
+
{#snippet warningIcon()}
|
|
28
|
+
<TriangleAlert class="size-4" />
|
|
29
|
+
{/snippet}
|
|
30
|
+
</Sonner>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import { Loader2 } from '@lucide/svelte';
|
|
5
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
6
|
+
|
|
7
|
+
interface ShadcnSpinnerProps extends SVGAttributes<SVGSVGElement> {
|
|
8
|
+
class?: string;
|
|
9
|
+
role?: string;
|
|
10
|
+
name?: string | null;
|
|
11
|
+
color?: string | null;
|
|
12
|
+
stroke?: string | number | null;
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
class: className,
|
|
18
|
+
role = 'status',
|
|
19
|
+
name,
|
|
20
|
+
color,
|
|
21
|
+
stroke,
|
|
22
|
+
'aria-label': ariaLabel = 'Loading',
|
|
23
|
+
...restProps
|
|
24
|
+
}: ShadcnSpinnerProps = $props();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<Loader2
|
|
28
|
+
{role}
|
|
29
|
+
name={name === null ? undefined : name}
|
|
30
|
+
color={color === null ? undefined : color}
|
|
31
|
+
stroke={stroke === null ? undefined : stroke}
|
|
32
|
+
aria-label={ariaLabel}
|
|
33
|
+
class={cn('size-4 animate-spin', className)}
|
|
34
|
+
{...restProps}
|
|
35
|
+
/>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
interface ShadcnSwitchProps extends HTMLButtonAttributes {
|
|
7
|
+
ref?: HTMLButtonElement | null;
|
|
8
|
+
class?: string;
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
size?: 'sm' | 'default';
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
ref = $bindable(null),
|
|
17
|
+
class: className = '',
|
|
18
|
+
checked = $bindable(false),
|
|
19
|
+
size = 'default',
|
|
20
|
+
disabled = false,
|
|
21
|
+
onCheckedChange,
|
|
22
|
+
...restProps
|
|
23
|
+
}: ShadcnSwitchProps = $props();
|
|
24
|
+
|
|
25
|
+
function toggle() {
|
|
26
|
+
if (disabled) return;
|
|
27
|
+
checked = !checked;
|
|
28
|
+
onCheckedChange?.(checked);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
32
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
toggle();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
role="switch"
|
|
42
|
+
aria-checked={checked}
|
|
43
|
+
aria-disabled={disabled}
|
|
44
|
+
{disabled}
|
|
45
|
+
data-slot="switch"
|
|
46
|
+
data-state={checked ? 'checked' : 'unchecked'}
|
|
47
|
+
data-size={size}
|
|
48
|
+
bind:this={ref}
|
|
49
|
+
onclick={toggle}
|
|
50
|
+
onkeydown={handleKeyDown}
|
|
51
|
+
class={cn(
|
|
52
|
+
'peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-colors outline-none cursor-pointer select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80',
|
|
53
|
+
className,
|
|
54
|
+
)}
|
|
55
|
+
{...restProps}
|
|
56
|
+
>
|
|
57
|
+
<span
|
|
58
|
+
data-slot="switch-thumb"
|
|
59
|
+
data-state={checked ? 'checked' : 'unchecked'}
|
|
60
|
+
class={cn(
|
|
61
|
+
'pointer-events-none block rounded-full bg-background ring-0 transition-transform dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground',
|
|
62
|
+
size === 'sm'
|
|
63
|
+
? 'size-3 data-[state=checked]:translate-x-[10px] data-[state=unchecked]:translate-x-0'
|
|
64
|
+
: 'size-4 data-[state=checked]:translate-x-[14px] data-[state=unchecked]:translate-x-0',
|
|
65
|
+
)}
|
|
66
|
+
></span>
|
|
67
|
+
</button>
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn, cva, type VariantProps } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
import { setContext, getContext } from 'svelte';
|
|
6
|
+
|
|
7
|
+
export const tabsListVariants = cva(
|
|
8
|
+
'rounded-lg p-[3px] group-data-horizontal/tabs:h-8 data-[variant=line]:rounded-none group/tabs-list inline-flex w-fit items-center justify-center text-muted-foreground group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col',
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: 'cn-tabs-list-variant-default bg-muted',
|
|
13
|
+
line: 'cn-tabs-list-variant-line gap-1 bg-transparent',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
variant: 'default',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type TabsListVariant = VariantProps<typeof tabsListVariants>['variant'];
|
|
23
|
+
|
|
24
|
+
interface TabsContextValue {
|
|
25
|
+
currentValue: string;
|
|
26
|
+
setValue: (val: string) => void;
|
|
27
|
+
orientation: 'horizontal' | 'vertical';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const TABS_CTX_KEY = Symbol('TABS_CONTEXT');
|
|
31
|
+
|
|
32
|
+
export interface ShadcnTabsProps {
|
|
33
|
+
value?: string;
|
|
34
|
+
defaultValue?: string;
|
|
35
|
+
orientation?: 'horizontal' | 'vertical';
|
|
36
|
+
class?: string;
|
|
37
|
+
onValueChange?: (value: string) => void;
|
|
38
|
+
children?: Snippet;
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ShadcnTabsListProps {
|
|
43
|
+
variant?: TabsListVariant;
|
|
44
|
+
class?: string;
|
|
45
|
+
children?: Snippet;
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ShadcnTabsTriggerProps {
|
|
50
|
+
value: string;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
class?: string;
|
|
53
|
+
children?: Snippet;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ShadcnTabsContentProps {
|
|
58
|
+
value: string;
|
|
59
|
+
class?: string;
|
|
60
|
+
children?: Snippet;
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<script lang="ts">
|
|
66
|
+
let {
|
|
67
|
+
value = $bindable(''),
|
|
68
|
+
defaultValue = '',
|
|
69
|
+
orientation = 'horizontal',
|
|
70
|
+
class: className = '',
|
|
71
|
+
onValueChange,
|
|
72
|
+
children,
|
|
73
|
+
...restProps
|
|
74
|
+
}: ShadcnTabsProps = $props();
|
|
75
|
+
|
|
76
|
+
let internalValue = $state(value || defaultValue);
|
|
77
|
+
|
|
78
|
+
$effect(() => {
|
|
79
|
+
if (value !== undefined && value !== '') {
|
|
80
|
+
internalValue = value;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
function handleSetValue(val: string) {
|
|
85
|
+
internalValue = val;
|
|
86
|
+
value = val;
|
|
87
|
+
onValueChange?.(val);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setContext<TabsContextValue>(TABS_CTX_KEY, {
|
|
91
|
+
get currentValue() {
|
|
92
|
+
return internalValue;
|
|
93
|
+
},
|
|
94
|
+
setValue: handleSetValue,
|
|
95
|
+
get orientation() {
|
|
96
|
+
return orientation;
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
{#snippet TabsList({ variant = 'default', class: className = '', children, ...props })}
|
|
102
|
+
<div
|
|
103
|
+
role="tablist"
|
|
104
|
+
aria-orientation={orientation}
|
|
105
|
+
data-slot="tabs-list"
|
|
106
|
+
data-variant={variant}
|
|
107
|
+
class={cn(tabsListVariants({ variant }), className)}
|
|
108
|
+
{...props}
|
|
109
|
+
>
|
|
110
|
+
{@render children?.()}
|
|
111
|
+
</div>
|
|
112
|
+
{/snippet}
|
|
113
|
+
|
|
114
|
+
{#snippet TabsTrigger({
|
|
115
|
+
value: triggerValue,
|
|
116
|
+
disabled = false,
|
|
117
|
+
class: className = '',
|
|
118
|
+
children,
|
|
119
|
+
...props
|
|
120
|
+
})}
|
|
121
|
+
{@const ctx = getContext<TabsContextValue>(TABS_CTX_KEY)}
|
|
122
|
+
{@const isActive = ctx?.currentValue === triggerValue}
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
role="tab"
|
|
126
|
+
aria-selected={isActive}
|
|
127
|
+
data-state={isActive ? 'active' : 'inactive'}
|
|
128
|
+
data-slot="tabs-trigger"
|
|
129
|
+
{disabled}
|
|
130
|
+
tabindex={isActive ? 0 : -1}
|
|
131
|
+
onclick={() => ctx?.setValue(triggerValue)}
|
|
132
|
+
class={cn(
|
|
133
|
+
"gap-1.5 rounded-md border border-transparent px-2.5 py-1 text-xs font-medium has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none [&_svg:not([class*='size-'])]:size-3.5 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-muted-foreground transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
134
|
+
'group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent',
|
|
135
|
+
'data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-xs dark:data-[state=active]:border-border/50 dark:data-[state=active]:bg-background dark:data-[state=active]:text-foreground',
|
|
136
|
+
'after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100',
|
|
137
|
+
className,
|
|
138
|
+
)}
|
|
139
|
+
{...props}
|
|
140
|
+
>
|
|
141
|
+
{@render children?.()}
|
|
142
|
+
</button>
|
|
143
|
+
{/snippet}
|
|
144
|
+
|
|
145
|
+
{#snippet TabsContent({ value: contentValue, class: className = '', children, ...props })}
|
|
146
|
+
{@const ctx = getContext<TabsContextValue>(TABS_CTX_KEY)}
|
|
147
|
+
{@const isActive = ctx?.currentValue === contentValue}
|
|
148
|
+
{#if isActive}
|
|
149
|
+
<div
|
|
150
|
+
role="tabpanel"
|
|
151
|
+
tabindex="0"
|
|
152
|
+
data-state={isActive ? 'active' : 'inactive'}
|
|
153
|
+
data-slot="tabs-content"
|
|
154
|
+
class={cn('text-sm flex-1 outline-none', className)}
|
|
155
|
+
{...props}
|
|
156
|
+
>
|
|
157
|
+
{@render children?.()}
|
|
158
|
+
</div>
|
|
159
|
+
{/if}
|
|
160
|
+
{/snippet}
|
|
161
|
+
|
|
162
|
+
<div
|
|
163
|
+
data-slot="tabs"
|
|
164
|
+
data-orientation={orientation}
|
|
165
|
+
class={cn('gap-2 group/tabs flex data-[orientation=horizontal]:flex-col', className)}
|
|
166
|
+
{...restProps}
|
|
167
|
+
>
|
|
168
|
+
{@render children?.()}
|
|
169
|
+
</div>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
interface Props extends HTMLTextareaAttributes {
|
|
7
|
+
ref?: HTMLTextAreaElement | null;
|
|
8
|
+
value?: string;
|
|
9
|
+
class?: string;
|
|
10
|
+
'data-slot'?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
ref = $bindable(null),
|
|
15
|
+
value = $bindable(),
|
|
16
|
+
class: className,
|
|
17
|
+
'data-slot': dataSlot = 'textarea',
|
|
18
|
+
...restProps
|
|
19
|
+
}: Props = $props();
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<textarea
|
|
23
|
+
bind:this={ref}
|
|
24
|
+
data-slot={dataSlot}
|
|
25
|
+
class={cn(
|
|
26
|
+
'rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex field-sizing-content min-h-16 w-full outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
|
|
27
|
+
className,
|
|
28
|
+
)}
|
|
29
|
+
bind:value
|
|
30
|
+
{...restProps}
|
|
31
|
+
></textarea>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { cn, cva, type VariantProps } from '@surreal-ui/core';
|
|
3
|
+
|
|
4
|
+
export const shadcnToggleVariants = cva(
|
|
5
|
+
"gap-1 rounded-lg text-sm font-medium transition-all hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 group/toggle inline-flex items-center justify-center whitespace-nowrap outline-none hover:bg-muted focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
6
|
+
{
|
|
7
|
+
variants: {
|
|
8
|
+
variant: {
|
|
9
|
+
default: 'bg-transparent',
|
|
10
|
+
outline: 'border border-input bg-transparent hover:bg-muted',
|
|
11
|
+
},
|
|
12
|
+
size: {
|
|
13
|
+
default:
|
|
14
|
+
'h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
15
|
+
sm: "h-7 min-w-7 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
16
|
+
lg: 'h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
variant: 'default',
|
|
21
|
+
size: 'default',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export type ShadcnToggleVariant = VariantProps<typeof shadcnToggleVariants>['variant'];
|
|
27
|
+
export type ShadcnToggleSize = VariantProps<typeof shadcnToggleVariants>['size'];
|
|
28
|
+
export type ToggleVariants = VariantProps<typeof shadcnToggleVariants>;
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script lang="ts">
|
|
32
|
+
import type { Snippet } from 'svelte';
|
|
33
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
34
|
+
|
|
35
|
+
interface Props extends Omit<HTMLButtonAttributes, 'children'> {
|
|
36
|
+
ref?: HTMLButtonElement | null;
|
|
37
|
+
pressed?: boolean;
|
|
38
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
39
|
+
variant?: ShadcnToggleVariant;
|
|
40
|
+
size?: ToggleSize;
|
|
41
|
+
children?: Snippet;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let {
|
|
45
|
+
ref = $bindable(null),
|
|
46
|
+
pressed = $bindable(false),
|
|
47
|
+
onPressedChange,
|
|
48
|
+
class: className = '',
|
|
49
|
+
size = 'default',
|
|
50
|
+
variant = 'default',
|
|
51
|
+
children,
|
|
52
|
+
onclick,
|
|
53
|
+
...restProps
|
|
54
|
+
}: Props = $props();
|
|
55
|
+
|
|
56
|
+
function handleClick(e: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
|
|
57
|
+
pressed = !pressed;
|
|
58
|
+
onPressedChange?.(pressed);
|
|
59
|
+
onclick?.(e);
|
|
60
|
+
}
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<button
|
|
64
|
+
bind:this={ref}
|
|
65
|
+
type="button"
|
|
66
|
+
aria-pressed={pressed}
|
|
67
|
+
data-state={pressed ? 'on' : 'off'}
|
|
68
|
+
data-slot="toggle"
|
|
69
|
+
class={cn(shadcnToggleVariants({ variant, size }), className)}
|
|
70
|
+
onclick={handleClick}
|
|
71
|
+
{...restProps}
|
|
72
|
+
>
|
|
73
|
+
{@render children?.()}
|
|
74
|
+
</button>
|