On This Page
Installation
Basic Usage
API Sections
Specs
@semantic-ui/specs provides tools for defining and interpreting component APIs. It enables semantic HTML parsing, documentation generation, and bidirectional transformation between HTML and component metadata.
Installation
Specs can be used as a standalone package or alongside Semantic UI components.
npm install @semantic-ui/specsBasic Usage
import { SpecReader } from '@semantic-ui/specs';import buttonSpec from './button.spec.js';
const reader = new SpecReader(buttonSpec);
// Generate runtime metadataconst componentSpec = reader.getWebComponentSpec();
// Parse semantic HTMLconst parts = reader.getComponentPartsFromHTML( '<ui-button primary large>Save</ui-button>');
// Generate HTML from modifiersconst html = reader.getCodeFromModifiers('primary large', { html: 'Save',});API Sections
Core
-
SpecReader - Create spec readers and generate runtime metadata
-
Spec Helpers - Reusable constants and helpers for common patterns
- getVariations() - Get multiple variations
- getStates() - Get multiple states
- modifyVariation() - Customize variations
- Variation constants (SIZE_VARIATION, COLORED_VARIATION, etc.)
- State constants (HOVER_STATE, ACTIVE_STATE, etc.)
- Options arrays (SIZE_OPTIONS, COLOR_OPTIONS, etc.)
Documentation Generation
- Documentation - Generate structured documentation from specs
Semantic Interpretation
-
Parsing HTML - Extract semantic meaning from HTML
-
Generating HTML - Create HTML from semantic attributes
Utilities
- Utilities - Helper methods for component metadata