~james/core

core/web/src/lib/components/ui/selectField.ts -rw-r--r-- 1.7 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { Component } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";
import { tv, type VariantProps } from "tailwind-variants";

export interface SelectOption {
	value: string;
	label?: string;
	hint?: string;
	group?: string;
	disabled?: boolean;
	separator?: boolean;
	icon?: Component<SvelteHTMLElements["svg"]>;
}

export type SelectAlign = "left" | "right";

export const selectField = tv({
	slots: {
		box: "w-full rounded-md bg-background-default edge-ring-inset transition-colors focus-visible:outline-none disabled:cursor-not-allowed",
		chevron: "shrink-0 text-foreground-subtle"
	},
	variants: {
		error: {
			false: {
				box: "text-foreground-default focus-visible:ring-1 focus-visible:ring-border-focus focus-visible:inset-ring-border-focus aria-expanded:ring-1 aria-expanded:ring-border-focus aria-expanded:inset-ring-border-focus"
			},
			true: {
				box: "bg-background-danger-subtle text-foreground-danger inset-ring-border-danger focus-visible:ring-1 focus-visible:ring-border-focus-danger focus-visible:inset-ring-border-focus-danger aria-expanded:ring-1 aria-expanded:ring-border-focus-danger aria-expanded:inset-ring-border-focus-danger",
				chevron: "text-foreground-danger"
			}
		},
		disabled: {
			false: {},
			true: {
				box: "text-foreground-disabled",
				chevron: "text-foreground-disabled"
			}
		}
	},
	compoundVariants: [
		{
			error: true,
			disabled: true,
			class: {
				box: "bg-background-danger-subtle text-foreground-danger-subtle inset-ring-border-danger-subtle",
				chevron: "text-foreground-danger-subtle"
			}
		}
	],
	defaultVariants: {
		error: false,
		disabled: false
	}
});

export type SelectFieldVariants = VariantProps<typeof selectField>;