tailwind-to-style 3.1.2 → 3.2.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.
@@ -0,0 +1,85 @@
1
+ // Type definitions for tailwind-to-style/twsx-variants
2
+ // Tree-shakeable import: import { twsxVariants } from 'tailwind-to-style/twsx-variants'
3
+
4
+ /**
5
+ * Variant option values - string Tailwind classes
6
+ */
7
+ export type VariantValue = string;
8
+
9
+ /**
10
+ * Variant options definition
11
+ */
12
+ export interface VariantOptions {
13
+ [optionKey: string]: VariantValue;
14
+ }
15
+
16
+ /**
17
+ * Variants definition object
18
+ */
19
+ export interface VariantsDefinition {
20
+ [variantName: string]: VariantOptions;
21
+ }
22
+
23
+ /**
24
+ * Compound variant with class targeting
25
+ */
26
+ export interface CompoundVariantWithClass<V extends VariantsDefinition = VariantsDefinition> {
27
+ [K: string]: any;
28
+ class?: string;
29
+ className?: string;
30
+ }
31
+
32
+ /**
33
+ * Default variants - ensures only valid variant keys and values
34
+ */
35
+ export type DefaultVariants<V extends VariantsDefinition> = {
36
+ [K in keyof V]?: keyof V[K];
37
+ };
38
+
39
+ /**
40
+ * Variant props - infers types from variants definition
41
+ */
42
+ export type VariantProps<V extends VariantsDefinition> = {
43
+ [K in keyof V]?: keyof V[K] | (keyof V[K])[];
44
+ };
45
+
46
+ /**
47
+ * Configuration for twsxVariants with strict typing
48
+ */
49
+ export interface TwsxVariantsConfig<V extends VariantsDefinition = VariantsDefinition> {
50
+ /** Base Tailwind classes applied to all variants */
51
+ base?: string;
52
+ /** Variant definitions with their options */
53
+ variants?: V;
54
+ /** Compound variant rules for multi-variant combinations */
55
+ compoundVariants?: CompoundVariantWithClass<V>[];
56
+ /** Default variant values */
57
+ defaultVariants?: DefaultVariants<V>;
58
+ /** Nested selectors for child elements */
59
+ nested?: Record<string, string>;
60
+ }
61
+
62
+ /**
63
+ * Variant function returned by twsxVariants
64
+ */
65
+ export type VariantFunction<V extends VariantsDefinition = VariantsDefinition> =
66
+ (props?: Partial<VariantProps<V>>) => string;
67
+
68
+ /**
69
+ * Create a variant-based style generator with full type safety
70
+ */
71
+ export function twsxVariants<V extends VariantsDefinition>(
72
+ className: string,
73
+ config?: TwsxVariantsConfig<V>
74
+ ): VariantFunction<V>;
75
+
76
+ /**
77
+ * Extract variant props type from a twsxVariants return value
78
+ *
79
+ * @example
80
+ * const button = twsxVariants('.btn', { variants: { size: { sm: '...', lg: '...' } } })
81
+ * type ButtonProps = InferVariantProps<typeof button>
82
+ * // → { size?: 'sm' | 'lg' }
83
+ */
84
+ export type InferVariantProps<T extends VariantFunction<any>> =
85
+ T extends VariantFunction<infer V> ? Partial<VariantProps<V>> : never;