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

218 lines (212 loc) 9.33 kB
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/Time Input', component: 'modus-wc-time-input', args: { disabled: false, label: 'Label', size: 'md', }, argTypes: { 'auto-complete': { control: { type: 'select' }, options: ['on', 'off'], }, feedback: { description: 'Feedback prop for input components', table: { type: { detail: ` Interface: IInputFeedbackProp Properties: - level ('error' | 'info' | 'success' | 'warning'): The feedback level - message (string, optional): The feedback message `, }, }, }, size: { control: { type: 'select' }, options: ['sm', 'md', 'lg'], }, }, decorators: [withActions], parameters: { actions: { handles: ['inputBlur', 'inputChange', 'inputFocus'], }, }, }; export default meta; const Template = { render: (args) => html ` <modus-wc-time-input aria-label="Time input" auto-complete=${ifDefined(args['auto-complete'])} bordered=${ifDefined(args.bordered)} custom-class=${ifDefined(args['custom-class'])} datalist-id=${ifDefined(args['datalist-id'])} ?disabled=${args.disabled} .feedback=${args.feedback} input-id=${ifDefined(args['input-id'])} input-tab-index=${ifDefined(args['input-tab-index'])} label=${ifDefined(args.label)} max=${ifDefined(args.max)} min=${ifDefined(args.min)} name=${ifDefined(args.name)} ?read-only=${args['read-only']} ?required=${args.required} show-seconds=${ifDefined(args['show-seconds'])} size=${ifDefined(args.size)} step=${ifDefined(args.step)} .datalistOptions=${args['datalist-options']} .value=${args.value} ></modus-wc-time-input> `, }; export const Default = Object.assign({}, Template); export const WithSeconds = Object.assign(Object.assign({}, Template), { args: { 'show-seconds': true, } }); export const WithDatalist = { render: () => { // prettier-ignore return html ` <modus-wc-time-input aria-label="Example time input" datalist-id="datalist-id-1" ></modus-wc-time-input> <datalist id="datalist-id-1"> <option value="06:00"></option> <option value="12:00"></option> <option value="17:00"></option> </datalist> `; }, }; export const WithDatalistOptions = { render: () => { // prettier-ignore return html ` <script> document.addEventListener('DOMContentLoaded', () => { // Example of programmatically adding 'datalistOptions' const preferredTimes = ['09:30', '12:00', '17:30']; document.querySelector('#time-input-with-options').datalistOptions = preferredTimes; }); </script> <modus-wc-time-input aria-label="Example time input" id="time-input-with-options" ></modus-wc-time-input> `; }, }; const errorFeedback = { level: 'error', message: 'Value is required.', }; export const WithErrorFeedback = Object.assign(Object.assign({}, Template), { args: { feedback: errorFeedback, required: true }, parameters: { docs: { source: { transform: (src) => `${src} <script> const timeInputElement = document.querySelector('modus-wc-time-input'); timeInputElement.feedback = { level: 'error', message: 'Value is required.' }; </script>`, }, }, } }); export const ShadowDomParent = { render: (args) => { // Create a unique shadow host for time-input component if (!customElements.get('time-input-shadow-host')) { const TimeInputShadowHost = createShadowHostClass({ componentTag: 'modus-wc-time-input', propsMapper: (v, el) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const timeInputEl = el; timeInputEl.autoComplete = (_a = v['auto-complete']) !== null && _a !== void 0 ? _a : ''; timeInputEl.bordered = (_b = v['bordered']) !== null && _b !== void 0 ? _b : true; timeInputEl.customClass = v['custom-class'] || ''; timeInputEl.datalistId = (_c = v['datalist-id']) !== null && _c !== void 0 ? _c : ''; if (v['datalist-options']) { timeInputEl.datalistOptions = v['datalist-options']; // Conditional assignment only if provided } timeInputEl.disabled = Boolean(v.disabled); timeInputEl.inputId = (_d = v['input-id']) !== null && _d !== void 0 ? _d : ''; timeInputEl.inputTabIndex = (_e = v['input-tab-index']) !== null && _e !== void 0 ? _e : 0; timeInputEl.label = (_f = v.label) !== null && _f !== void 0 ? _f : ''; timeInputEl.max = (_g = v.max) !== null && _g !== void 0 ? _g : ''; timeInputEl.min = (_h = v.min) !== null && _h !== void 0 ? _h : ''; timeInputEl.name = (_j = v.name) !== null && _j !== void 0 ? _j : ''; timeInputEl.readOnly = Boolean(v['read-only']); timeInputEl.required = Boolean(v.required); timeInputEl.showSeconds = Boolean(v['show-seconds']); timeInputEl.size = (_k = v.size) !== null && _k !== void 0 ? _k : 'md'; // Only set step if explicitly provided, otherwise let component calculate from showSeconds if (v.step !== undefined) { timeInputEl.step = v.step; } timeInputEl.value = (_l = v.value) !== null && _l !== void 0 ? _l : ''; }, }); customElements.define('time-input-shadow-host', TimeInputShadowHost); } return html `<time-input-shadow-host .props=${Object.assign({}, args)} ></time-input-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](/docs/documentation-form-inputs--docs) for additional info and examples. - Size values have changed from verbose names (\`medium\`, \`large\`) to abbreviations (\`sm\`, \`md\`, \`lg\`). #### Prop Mapping | 1.0 Prop | 2.0 Prop | Notes | |-------------------------|---------------------|-----------------------------------------| | allowed-chars-regex | | Not carried over | | ampm | | Not carried over | | aria-label | aria-label | | | auto-focus-input | autofocus | | | auto-format | | Not carried over | | disable-validation | | Not carried over | | disabled | disabled | | | error-text | feedback.message | Use \`feedback\` level | | helper-text | | Not carried over | | label | label | | | max | max | | | min | min | | | placeholder | | Not carried over | | read-only | read-only | | | required | required | | | size | size | \`medium\` → \`md\`, \`large\` → \`lg\` | | valid-text | feedback.message | Use \`feedback\` level | | value | value | | #### Event Mapping | 1.0 Event | 2.0 Event | Notes | |----------------|-------------|------------------------------------------------------| | timeInputBlur | inputBlur | | | valueChange | inputChange | | `, }, }, // To hide the actual story rendering and only show docs: controls: { disable: true }, canvas: { disable: true }, }, // Simple render function or leave it empty render: () => html `<div></div>`, };