@pantoken/web-components
v0.1.1
Published
Framework-agnostic custom elements for Instructure UI: <instui-icon> plus token-styled primitives.
Downloads
384
Readme
@pantoken/web-components
Framework-agnostic custom elements for Instructure UI. One package gives Vue, Svelte, Angular, and
plain HTML the icon plus a set of token-styled components (from @pantoken/components), with no
per-framework port.
Install
npm i @pantoken/web-componentsAlso available as pantoken/webComponents.
Usage
import "@pantoken/web-components"; // auto-registers the elements in the browser
import "@pantoken/css"; // defines the --instui-* custom properties the elements read<instui-button><instui-icon name="arrow-left"></instui-icon> Save</instui-button>
<instui-button variant="secondary">Cancel</instui-button>
<instui-alert variant="success">Saved.</instui-alert>
<instui-badge variant="danger">3</instui-badge>
<instui-avatar variant="blue">AB</instui-avatar>
<instui-progress value="60"></instui-progress>The elements (each renders the matching @pantoken/components CSS into its shadow root; tokens are
inherited custom properties, so they pierce the shadow boundary — load @pantoken/css):
<instui-icon name="arrow-left" size="1.5rem" color="…">— glyphs from@pantoken/icons.<instui-button variant="secondary|danger">— withdisabled/aria-disabled.<instui-alert variant="info|success|warning|danger">.<instui-badge variant="success|danger">,<instui-pill variant="info|success|warning|danger">,<instui-tag>.<instui-avatar variant="blue|green|red|orange" size="sm|lg" shape="rectangle">.<instui-spinner>,<instui-progress value="0–100" variant="success|danger">.<instui-progress-circle value="0–100" label="…">— a ring driven byvalue.<instui-metric value="…" label="…">,<instui-rating value="3" max="5">.<instui-icon-button label="…">,<instui-toggle-button pressed="true|false">.<instui-truncate lines="2">— omitlinesfor a single-line ellipsis.<instui-img src="…" alt="…" constrain="cover|contain" display="block">.<instui-side-nav-bar minimized="true|false">,<instui-tree-browser>,<instui-calendar>— containers; slot the items / tree / day cells.<instui-tooltip tip="…" placement="bottom|start|end">— the slotted trigger plus a hover/focus bubble.<instui-modal open>— renders a real<dialog>; theopenattribute drivesshowModal()/close(), and native dismissal (Esc/backdrop) reflects back and fires acloseevent.<instui-context-view>,<instui-popover>,<instui-tray placement="start|end|top|bottom" size="…">— native popovers; toggle from a button withpopovertarget/command.<instui-in-place-edit value="…" readonly>— click-to-edit field; commits on Enter/blur (fires achangeevent), reverts on Escape.
The module is Node-safe: element classes are defined inside register(), which no-ops when there is
no DOM. Call register(customElements) manually if you need to control timing.
API
register(registry?, options?): void— define the custom elements into a registry (defaults toglobalThis.customElements). No-op when there is no DOM, so it's safe to import during SSR or a build.options.prefixsets the tag prefix, mirroring the CSS layer: pass a non-empty string likexfor<x-icon>. A prefix is always applied (a custom-element name must contain a hyphen), so an omitted, empty, or nullish prefix falls back to the defaultinstui(<instui-icon>).iconSvg(name, resolve?): string— resolve an icon name to inline SVG (empty string when unknown). Pure; the element renders the result.ELEMENTS— the tuple of base (unprefixed) element names this package registers (e.g.icon,date-input).DEFAULT_PREFIX— the default tag prefix,"instui".
Related
- Styles the elements with
@pantoken/componentsand reads glyphs from@pantoken/icons. - Pairs with
@pantoken/cssfor the base--instui-*custom properties. - Wrapped by the per-framework helpers:
@pantoken/angular,@pantoken/react,@pantoken/svelte, and@pantoken/vue.
License
MIT
