UNPKG

@hashicorp/design-system-components

Version:
52 lines (49 loc) 1.85 kB
import Component from '@glimmer/component'; import { assert } from '@ember/debug'; import style from 'ember-style-modifier'; import { HdsFormTextInputTypeValues } from './types.js'; import { precompileTemplate } from '@ember/template-compilation'; import { setComponentTemplate } from '@ember/component'; /** * Copyright IBM Corp. 2021, 2025 * SPDX-License-Identifier: MPL-2.0 */ const DEFAULT_TYPE = HdsFormTextInputTypeValues.Text; const TYPES = Object.values(HdsFormTextInputTypeValues); class HdsFormTextInputBase extends Component { get type() { const { type = DEFAULT_TYPE } = this.args; assert(`@type for "Hds::Form::TextInput" must be one of the following: ${TYPES.join(', ')}; received: ${type}`, TYPES.includes(type)); return type; } get classNames() { const classes = ['hds-form-text-input']; // add typographic classes classes.push('hds-typography-body-200', 'hds-font-weight-regular'); // add a class based on the @isInvalid argument if (this.args.isInvalid) { classes.push(`hds-form-text-input--is-invalid`); } // add a class based on the @hasVisibilityToggle argument if (this.args.hasVisibilityToggle) { classes.push(`hds-form-text-input--has-visibility-toggle`); } // add a class based on the @isLoading argument if (this.args.isLoading) { classes.push(`hds-form-text-input--is-loading`); } return classes.join(' '); } static { setComponentTemplate(precompileTemplate("<input class={{this.classNames}} {{style width=@width}} id={{@id}} aria-describedby={{@ariaDescribedBy}} ...attributes value={{@value}} type={{this.type}} />", { strictMode: true, scope: () => ({ style }) }), this); } } export { DEFAULT_TYPE, TYPES, HdsFormTextInputBase as default }; //# sourceMappingURL=base.js.map