Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | /**
* @fds-uif/schema - System Type Definitions
*
* Systems define design-system specific components that either
* extend foundations or define standalone components.
*/
import type { Attributes, BaseChild, ComponentProps, ModifierOption, Slot } from './shared.js';
// =============================================================================
// Style API Types
// =============================================================================
/**
* Styling API status.
*/
export interface StyleApi {
/** Current status of the styling API */
status?: 'stable' | 'in-development' | 'deprecated';
/** Whether the styling API is ready for use */
ready?: boolean;
}
// =============================================================================
// State Class Types
// =============================================================================
/**
* CSS class mapping for a foundation state.
*
* Maps foundation-defined states to design-system CSS classes.
*
* @example
* ```json
* { "state": "disabled", "class": "slds-button_disabled" }
* ```
*/
export interface StateClass {
/** Name of the state from the foundation */
state: string;
/** CSS class to apply when state is active */
class: string;
}
// =============================================================================
// Modifier Types
// =============================================================================
/**
* Base properties shared by all modifier types.
*/
interface ModifierBase {
/** Unique identifier for the modifier (becomes a prop) */
name: string;
/** The HTML attribute to target (e.g., 'class', 'data-size') */
attribute: string;
/** Description of the modifier's effect */
description?: string;
}
/**
* Boolean modifier - produces a boolean prop.
*
* @example
* ```json
* { "name": "inverse", "attribute": "class", "value": "slds-badge_inverse" }
* ```
* Usage: `<Badge inverse />` → `class="... slds-badge_inverse"`
*/
export interface BooleanModifier extends ModifierBase {
/** Value to add when modifier is active */
value: string;
/** Grouped modifiers use options, not value */
options?: never;
default?: never;
}
/**
* Grouped modifier - produces a prop with enumerated options.
*
* @example
* ```json
* {
* "name": "size",
* "attribute": "class",
* "default": "medium",
* "options": [
* { "propValue": "small", "value": "slds-button_small" },
* { "propValue": "medium", "value": "slds-button_medium" },
* { "propValue": "large", "value": "slds-button_large" }
* ]
* }
* ```
* Usage: `<Button size="small" />` → `class="... slds-button_small"`
*/
export interface GroupedModifier extends ModifierBase {
/** Available options for this modifier */
options: ModifierOption[];
/** Default option value */
default?: string;
/** Boolean modifiers use value, not options */
value?: never;
}
/**
* CSS interface modifier.
*
* Modifiers adjust a property of the component without changing its
* fundamental nature. They tweak presentation or state.
*
* Two forms:
* - **Boolean**: `{ name, attribute, value }` → boolean prop
* - **Grouped**: `{ name, attribute, options, default? }` → enum prop
*
* Modifiers are **combinable** — a component can have multiple
* modifiers active simultaneously.
*/
export type Modifier = BooleanModifier | GroupedModifier;
// Re-export ModifierOption for convenience
export type { ModifierOption } from './shared.js';
// =============================================================================
// Variant Types
// =============================================================================
/**
* Variant option within a structural variant.
*
* Variant options can optionally modify DOM structure.
*/
export interface VariantOption {
/** The option value (used as prop value) */
value: string;
/** CSS class to apply for this variant */
class?: string;
/** Override element restriction for this variant */
restrict?: string[];
/** Override or extend children for this variant */
children?: SystemChild[];
/** Enable/disable slots (false hides, true shows) */
slots?: Record<string, boolean>;
}
/**
* Structural variant definition.
*
* Variants represent fundamentally different versions of a component
* that serve distinct semantic purposes. Variants are **mutually exclusive**
* within a group.
*
* @example
* ```json
* {
* "name": "variant",
* "default": "neutral",
* "options": [
* { "value": "neutral", "class": "slds-button_neutral" },
* { "value": "brand", "class": "slds-button_brand" },
* { "value": "destructive", "class": "slds-button_destructive" }
* ]
* }
* ```
*/
export interface Variant {
/** Unique identifier for the variant (becomes a prop) */
name: string;
/** Description of the variant */
description?: string;
/** The available options for this variant */
options: VariantOption[];
/** Default option value (first option if not specified) */
default?: string;
}
// =============================================================================
// System Structure
// =============================================================================
/**
* Child element in system structure.
*/
export interface SystemChild extends Omit<BaseChild, 'slot'> {
/** HTML attributes (including class) */
attributes?: Attributes;
/** Nested children */
children?: SystemChild[];
/** Slot for injecting content */
slot?: Slot;
/** CSS interface modifiers */
modifiers?: Modifier[];
/** Structural variants */
variants?: Variant[];
/**
* Reference to another UIF component.
* Inherited from foundation; can be overridden.
*/
component?: string;
/**
* Configuration for how the composed component's props are wired.
* Only valid when `component` is set.
*/
componentProps?: ComponentProps;
}
/**
* Root structural node for systems.
*/
export interface SystemStructure {
/** Unique identifier for this structural node */
name?: string;
/** Allowed HTML elements (first is used for generation) */
restrict?: string[];
/** Description of this structural element */
description?: string;
/** HTML attributes (including class) */
attributes?: Attributes;
/** Child elements and slots */
children?: SystemChild[];
/** Slot definition */
slot?: Slot;
/** CSS interface modifiers */
modifiers?: Modifier[];
/** Structural variants */
variants?: Variant[];
}
// =============================================================================
// UIF System
// =============================================================================
/**
* UIF System definition.
*
* Systems are design-system specific and either:
* - Extend a foundation with CSS classes, modifiers, and variants
* - Define a standalone component (when extends is omitted)
*
* Systems OWN the CSS interface:
* - Base styling identifiers (attributes.static.class)
* - Modifiers and variants
* - State-to-class mappings
*/
export interface UifSystem {
/** UIF schema version (e.g., '1.0.0') */
apiVersion: string;
/** Path to base foundation UIF file (if extending) */
extends?: string;
/** Component name in PascalCase (required for standalone) */
name?: string;
/** Brief description of the component (required for standalone) */
description?: string;
/** Status of the component's styling API */
styleApi?: StyleApi;
/** CSS class mappings for foundation states */
stateClasses?: StateClass[];
/** Root structural node (required for standalone) */
structure?: SystemStructure;
/**
* Path to component's CSS file.
* Used by the styling layer for CSS association.
*/
cssSource?: string;
}
// =============================================================================
// Type Guards
// =============================================================================
/**
* Type guard for standalone system (no extends).
* Standalone systems require name, description, and structure.
*/
export interface StandaloneUifSystem extends UifSystem {
extends?: never;
name: string;
description: string;
structure: SystemStructure;
}
/**
* Type guard for extending system (has extends).
*/
export interface ExtendingUifSystem extends UifSystem {
extends: string;
}
/**
* Check if a modifier is a boolean modifier.
*/
export function isBooleanModifier(modifier: Modifier): modifier is BooleanModifier {
return 'value' in modifier && typeof modifier.value === 'string';
}
/**
* Check if a modifier is a grouped modifier.
*/
export function isGroupedModifier(modifier: Modifier): modifier is GroupedModifier {
return 'options' in modifier && Array.isArray(modifier.options);
}
|