mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-22 01:29:05 +02:00
48 lines
1.6 KiB
Svelte
48 lines
1.6 KiB
Svelte
<script lang="ts" module>
|
|
import { tv, type VariantProps } from 'tailwind-variants';
|
|
|
|
export const fieldVariants = tv({
|
|
base: 'data-[invalid=true]:text-destructive gap-3 group/field flex w-full',
|
|
variants: {
|
|
orientation: {
|
|
vertical: 'cn-field-orientation-vertical flex-col [&>*]:w-full [&>.sr-only]:w-auto',
|
|
horizontal:
|
|
'cn-field-orientation-horizontal flex-row items-center has-[>[data-slot=field-content]]:items-start [&>[data-slot=field-label]]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
|
|
responsive:
|
|
'cn-field-orientation-responsive flex-col @md/field-group:flex-row @md/field-group:items-center @md/field-group:has-[>[data-slot=field-content]]:items-start [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto @md/field-group:[&>[data-slot=field-label]]:flex-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px'
|
|
}
|
|
},
|
|
defaultVariants: {
|
|
orientation: 'vertical'
|
|
}
|
|
});
|
|
|
|
export type FieldOrientation = VariantProps<typeof fieldVariants>['orientation'];
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
import { cn, type WithElementRef } from '$lib/utils/style.js';
|
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
|
|
let {
|
|
ref = $bindable(null),
|
|
class: className,
|
|
orientation = 'vertical',
|
|
children,
|
|
...restProps
|
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
orientation?: FieldOrientation;
|
|
} = $props();
|
|
</script>
|
|
|
|
<div
|
|
bind:this={ref}
|
|
role="group"
|
|
data-slot="field"
|
|
data-orientation={orientation}
|
|
class={cn(fieldVariants({ orientation }), className)}
|
|
{...restProps}
|
|
>
|
|
{@render children?.()}
|
|
</div>
|