
Enter a search term above to see results...
Enter a search term above to see results...
@semantic-ui/component
includes a few additional helpers in its exports which are used internally and may prove useful for some advanced use cases.
import { adoptStylesheet, scopeStyles, extractCSS } from '@semantic-ui/component';
adoptStylesheet(css, adoptedElement, options)
Adopts a stylesheet into an element’s adoptedStyleSheets. Each stylesheet is only added once, tracked by a hash of its content.
Name | Type | Required | Description |
---|---|---|---|
css | string | Yes | CSS to be adopted |
adoptedElement | Element | No | Element to adopt styles into. Defaults to document |
options | Object | No | Configuration options |
Name | Type | Default | Description |
---|---|---|---|
scopeSelector | string | undefined | Selector to scope styles to |
// Add to documentadoptStylesheet(` .ui.button { padding: 0.5em 1em; }`);
// Add to specific element with scopingadoptStylesheet( '.button { color: blue; }', myElement, { scopeSelector: '.my-component' });
scopeStyles(css, scopeSelector)
Scopes CSS rules to a specific selector, handling various CSS rule types including media queries, supports rules, and layer statements.
Name | Type | Required | Description |
---|---|---|---|
css | string | Yes | CSS content to be scoped |
scopeSelector | string | Yes | Selector to scope styles to |
The scoped CSS string.
const css = ` .button { color: blue; } @media (max-width: 768px) { .button { padding: 0.5em; } } @layer theme { .button { background: var(--primary); } }`;
const scopedCSS = scopeStyles(css, '.ui-button');
extractCSS(tagName)
Extracts all CSS rules that match a specific tag name from document stylesheets. Creates a new stylesheet containing only matching rules.
Name | Type | Required | Description |
---|---|---|---|
tagName | string | Yes | Tag name to extract CSS for |
A new CSSStyleSheet containing matching rules.
// Extract all styles for ui-buttonconst buttonStyles = extractCSS('ui-button');
adjustPropertyFromAttribute({ el, attribute, attributeValue, properties, componentSpec })
Synchronizes component properties when attributes change, handling Semantic UI’s attribute dialects and spec-based property mapping.
Name | Type | Required | Description |
---|---|---|---|
el | Element | Yes | Web component element instance |
attribute | string | Yes | Attribute name that changed |
attributeValue | any | Yes | New value of the attribute |
properties | Object | No | Component property definitions |
componentSpec | Object | No | Component specification object |
// With component specadjustPropertyFromAttribute({ el: buttonElement, attribute: 'size', attributeValue: 'large', componentSpec: ButtonComponentSpec});
// With property definitionsadjustPropertyFromAttribute({ el: customElement, attribute: 'icon-after', attributeValue: true, properties: { iconAfter: { type: Boolean }, 'icon-after': { type: Boolean, alias: true } }});