UNPKG

@trimble-oss/moduswebcomponents

Version:

Modus Web Components is a modern, accessible UI library built with Stencil JS that provides reusable web components following Trimble's Modus design system. This updated version focuses on improved flexibility, enhanced theming options, comprehensive cust

146 lines (140 loc) 4.46 kB
import { html } from "lit"; import { ifDefined } from "lit/directives/if-defined.js"; import { createShadowHostClass } from "../../providers/shadow-dom/shadow-host-helper"; const meta = { title: 'Components/Icon', component: 'modus-wc-icon', args: { 'custom-class': '', decorative: false, name: 'alert', size: 'md', }, argTypes: { size: { control: { type: 'select' }, options: ['xs', 'sm', 'md', 'lg'], }, variant: { control: { type: 'select' }, options: ['outlined', 'solid'], }, }, }; export default meta; const Template = { render: (args) => { // prettier-ignore return html ` <modus-wc-icon aria-label="Alert icon" custom-class="${ifDefined(args['custom-class'])}" ?decorative="${args.decorative}" name="${args.name}" size="${args.size}" variant="${ifDefined(args.variant)}" > </modus-wc-icon> `; }, }; export const Default = Object.assign({}, Template); export const CustomColor = { render: (args) => { // prettier-ignore return html ` <style> .red-icon { color: red; } </style> <modus-wc-icon aria-label="Red alert icon" custom-class="red-icon" name="alert" size="${args.size}" > </modus-wc-icon> `; }, }; export const CustomIcons = { args: { 'custom-class': 'icon-font tc-icon-cloud-queue', decorative: false, name: '', size: 'lg', }, decorators: [ (story) => html ` <link rel="stylesheet" href="https://resources.connect.trimble.com/1.12.0/fonts/icon-font.min.css" /> ${story()} `, ], render: (args) => { // prettier-ignore return html ` <modus-wc-icon aria-label="Cloud Queue icon" custom-class="${ifDefined(args['custom-class'])}" ?decorative="${args.decorative}" name="${args.name}" size="${args.size}" > </modus-wc-icon> `; }, }; export const ShadowDomParent = { render: (args) => { // Create a unique shadow host for icon component if (!customElements.get('icon-shadow-host')) { const IconShadowHost = createShadowHostClass({ componentTag: 'modus-wc-icon', propsMapper: (v, el) => { var _a; const iconEl = el; iconEl.customClass = v['custom-class'] || ''; iconEl.decorative = Boolean(v.decorative); iconEl.name = v.name; iconEl.size = v.size; iconEl.variant = (_a = v.variant) !== null && _a !== void 0 ? _a : 'outlined'; }, }); customElements.define('icon-shadow-host', IconShadowHost); } return html `<icon-shadow-host .props=${Object.assign({}, args)}></icon-shadow-host>`; }, }; export const Migration = { parameters: { docs: { description: { story: ` #### Breaking Changes - Requires <b>Modus Icons</b> to be installed in the host application see [Modus Icon Usage](/docs/documentation-modus-icon-usage--docs). - The \`color\` property has been removed in favor of using CSS for styling. - The \`iconClick\` event has been removed. Use the \`click\` event on the host element instead. - In 1.0 the \`size\` prop accepted any numeric string (e.g., \`'16'\`, \`'24'\`, \`'32'\`) to set the icon's width and height. 2.0 uses preset sizes: \`sm\`, \`md\`, \`lg\`, and can use CSS for custom sizes. #### Prop Mapping | 1.0 Prop | 2.0 Prop | Notes | |----------|----------|------------------------------------------------------| | color | | Not carried over, use CSS instead | | name | name | | | size | size | Numeric values changed to \`sm\`, \`md\`, \`lg\`, use CSS for custom sizes | #### Event Mapping | 1.0 Event | 2.0 Event | Notes | |-----------|-----------|---------------------------------------------------------------| | iconClick | | Not carried over, use \`click\` event on host element instead | `, }, }, controls: { disable: true }, canvas: { disable: true }, }, render: () => html `<div></div>`, };