All files / packages/fds-uif/schema/src/types shared.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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                                                                                                                                                                                                                                                                                                                                   
/**
 * @fds-uif/schema - Shared Type Definitions
 *
 * These types are used by both Foundation and System schemas.
 */
 
/**
 * Namespaced metadata for third-party tooling.
 * Keys should use reverse domain notation (e.g., 'com.salesforce-ux').
 * Each namespace value is an arbitrary object owned by that namespace.
 */
export type Extensions = Record<string, Record<string, unknown>>;
 
/**
 * Slot definition for content injection points.
 */
export interface Slot {
  /** Slot identifier ('default' for primary content) */
  name: string;
  /** Allowed component types (e.g., ['Tab'] for TabList slots) */
  restrict?: string[];
  /** If true, at least one child must be provided */
  required?: boolean;
  /** Namespaced metadata for third-party tooling */
  extensions?: Extensions;
}
 
/**
 * Attribute bound to a component prop.
 */
export interface BoundAttribute {
  /** Name of the prop this attribute is bound to */
  prop: string;
  /** Whether this prop is required */
  required?: boolean;
}
 
/**
 * Attribute rendered conditionally based on state.
 */
export interface ConditionalAttribute {
  /** Condition expression (e.g., state reference) */
  when: string;
  /** Value to render when condition is true */
  value: string;
}
 
/**
 * HTML attributes for a structural element.
 */
export interface Attributes {
  /** Hardcoded attribute values. The `class` key accepts `string | string[]`. */
  static?: Record<string, string | string[]>;
  /** Attributes bound to component props */
  bound?: Record<string, BoundAttribute>;
  /** Conditionally rendered attributes */
  conditional?: Record<string, ConditionalAttribute | ConditionalAttribute[]>;
}
 
/**
 * Accessibility requirement definition.
 */
export interface AccessibilityRequirement {
  /** Unique identifier for the requirement */
  id: string;
  /** Description of the requirement */
  description: string;
}
 
/**
 * Accessibility configuration for a component.
 */
export interface Accessibility {
  /** List of accessibility requirements */
  requirements?: AccessibilityRequirement[];
  /** Namespaced metadata for third-party tooling */
  extensions?: Extensions;
}
 
/**
 * Prop-value equality condition for conditional rendering.
 *
 * The child renders only when the named prop equals the given value.
 * Used to tie composed children to a specific prop setting
 * (e.g. iconRight renders when iconPosition === 'right').
 */
export interface RenderWhenPropMatch {
  /** Prop name to test */
  prop: string;
  /** Value the prop must equal for this child to render */
  eq: string;
}
 
/**
 * Conditional rendering expression.
 *
 * - `'slotFilled'` — render when the child's slot has content
 * - `'propFilled'` — render when the child's bound prop is provided
 * - `{ prop, eq }` — render when a parent prop equals a specific value
 */
export type RenderWhen = 'slotFilled' | 'propFilled' | RenderWhenPropMatch;
 
/**
 * Base child element definition shared between foundation and system.
 */
export interface BaseChild {
  /** Unique identifier for the child element */
  name: string;
  /** Allowed HTML elements */
  restrict?: string[];
  /** Description of this child */
  description?: string;
  /** Conditional rendering mode */
  renderWhen?: RenderWhen;
  /** Whether this child repeats (maps over array) */
  repeats?: boolean;
  /** Slot for injecting content */
  slot?: Slot;
}
 
/**
 * Option within a grouped modifier.
 *
 * @example
 * ```json
 * { "propValue": "small", "value": "slds-button_small" }
 * ```
 */
export interface ModifierOption {
  /** The consumer-facing option value (used as prop value) */
  propValue: string;
  /** The attribute value to apply (e.g., CSS class) */
  value: string;
}
 
/**
 * Configuration for how a composed component's props are wired.
 *
 * Mirrors {@link ResolvedComponentProps} — keys group props by binding style:
 *   - `static`    — hardcoded values always applied
 *   - `bound`     — props bound to parent props
 *   - `forwarded` — props passed through unchanged
 *   - `byVariant` — props determined by a parent variant
 *   - `restrict`  — whitelist that narrows the child's interface
 */
export interface ComponentProps {
  /** Hardcoded prop values, always applied */
  static?: Record<string, unknown>;
 
  /** Props bound to parent component props (child prop → parent prop) */
  bound?: Record<string, string>;
 
  /** Props passed through from parent unchanged */
  forwarded?: string[];
 
  /** Props determined by parent's variant value (variant → option → props) */
  byVariant?: Record<string, Record<string, Record<string, unknown>>>;
 
  /** Whitelist of allowed props (narrows the child's interface) */
  restrict?: string[];
}