@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
118 lines (112 loc) • 4.71 kB
JavaScript
import { withActions } from "@storybook/addon-actions/decorator";
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/Forms/Checkbox',
component: 'modus-wc-checkbox',
args: {
'custom-class': '',
disabled: false,
indeterminate: false,
label: 'Label',
name: '',
required: false,
size: 'md',
value: true,
},
argTypes: {
size: {
control: { type: 'select' },
options: ['sm', 'md', 'lg'],
},
},
decorators: [withActions],
parameters: {
actions: {
handles: ['inputBlur', 'inputChange', 'inputFocus'],
},
},
};
export default meta;
export const Default = {
render: (args) => {
return html `
<modus-wc-checkbox
aria-label="Checkbox"
custom-class=${ifDefined(args['custom-class'])}
?disabled=${args.disabled}
.indeterminate=${args.indeterminate}
input-id=${ifDefined(args['input-id'])}
input-tab-index=${ifDefined(args['input-tab-index'])}
label=${ifDefined(args.label)}
name=${ifDefined(args.name)}
?required=${args.required}
size=${ifDefined(args.size)}
.value=${args.value}
></modus-wc-checkbox>
`;
},
};
export const ShadowDomParent = {
render: (args) => {
// Create a unique shadow host for checkbox component
if (!customElements.get('checkbox-shadow-host')) {
const CheckboxShadowHost = createShadowHostClass({
componentTag: 'modus-wc-checkbox',
propsMapper: (v, el) => {
var _a, _b, _c, _d, _e;
const checkboxEl = el;
checkboxEl.customClass = v['custom-class'] || '';
checkboxEl.disabled = Boolean(v.disabled);
checkboxEl.indeterminate = Boolean(v.indeterminate);
checkboxEl.inputId = (_a = v['input-id']) !== null && _a !== void 0 ? _a : '';
checkboxEl.inputTabIndex = (_b = v['input-tab-index']) !== null && _b !== void 0 ? _b : 0;
checkboxEl.label = (_c = v.label) !== null && _c !== void 0 ? _c : '';
checkboxEl.name = (_d = v.name) !== null && _d !== void 0 ? _d : '';
checkboxEl.required = Boolean(v.required);
checkboxEl.size = (_e = v.size) !== null && _e !== void 0 ? _e : '';
checkboxEl.value = Boolean(v.value);
},
});
customElements.define('checkbox-shadow-host', CheckboxShadowHost);
}
return html `<checkbox-shadow-host
.props=${Object.assign({}, args)}
></checkbox-shadow-host>`;
},
};
export const Migration = {
parameters: {
docs: {
description: {
story: `
#### Breaking Changes
- In 1.0 input state was maintained by the component. 2.0 components encourage users to follow a controlled
input model. See the Form Inputs [documentation]([Angular](?path=/docs/documentation-form-inputs--docs) for
additional info and examples.
- The \`checked\` prop is now \`value\` in 2.0.
- The \`checkboxClick\` event is now \`inputChange\` in 2.0.
- Size values have changed from verbose names (\`small\`, \`medium\`) to abbreviations (\`sm\`, \`md\`, \`lg\`).
#### Prop Mapping
| 1.0 Prop | 2.0 Prop | Notes |
|------------------|---------------|-----------------------------------------|
| aria-label | aria-label | |
| checked | value | |
| disabled | disabled | |
| indeterminate | indeterminate | |
| label | label | |
| size | size | \`small\` → \`sm\`, \`medium\` → \`md\` |
| stop-propagation | | Not carried over |
#### Event Mapping
| 1.0 Event | 2.0 Event | Notes |
|---------------|-------------|-------------------------------------------------------|
| checkboxClick | inputChange | Event now emits \`InputEvent\` instead of \`boolean\` |
`,
},
},
controls: { disable: true },
canvas: { disable: true },
},
render: () => html `<div></div>`,
};