mirror of
https://github.com/hanzoai/svelte.git
synced 2026-10-01 00:41:47 +00:00
Extracted from @hanzo/ui pkg/ui/src/backends/svelte with its history. It lived inside a React component library, which meant every consumer of @hanzo/ui resolved svelte whether they rendered a single Svelte component or not, and the package declared peer svelte>=5 against a dev svelte ^4.2.20 — two answers to one question. Three runtime dependencies, all load-bearing: class-variance-authority for the variants the components already used, and clsx + tailwind-merge behind cn. The cn helper is vendored (17 lines) rather than imported back from @hanzo/ui, because depending on the package this was extracted from would undo the split. No design-system runtime, no icon pack, no CSS-in-JS. svelte-check: 50 files, 0 errors. Co-authored-by: Hanzo Dev <[email protected]>
35 lines
1.2 KiB
Svelte
35 lines
1.2 KiB
Svelte
<!--
|
|
TabsTrigger — selects its `value`. role=tab with the shadcn backend's
|
|
data-state active styling; only the active tab is in the tab order (roving).
|
|
-->
|
|
<script lang="ts">
|
|
import { getSelection, TABS } from './internal/context'
|
|
import { cn } from './core/cn'
|
|
|
|
let className: string | undefined = undefined
|
|
export { className as class }
|
|
export let value: string
|
|
export let disabled = false
|
|
|
|
const { value: current, select } = getSelection(TABS, 'TabsTrigger')
|
|
$: active = $current === value
|
|
</script>
|
|
|
|
<button
|
|
type="button"
|
|
role="tab"
|
|
aria-selected={active}
|
|
tabindex={active ? 0 : -1}
|
|
{disabled}
|
|
data-slot="tabs-trigger"
|
|
data-state={active ? 'active' : 'inactive'}
|
|
class={cn(
|
|
'inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 whitespace-nowrap rounded-md border border-transparent px-2 py-1 text-sm font-medium transition-colors outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm',
|
|
className,
|
|
)}
|
|
on:click={() => !disabled && select(value)}
|
|
{...$$restProps}
|
|
>
|
|
<slot />
|
|
</button>
|