@hashicorp/design-system-components
Version:
Helios Design System Components
66 lines (56 loc) • 2.25 kB
JavaScript
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { HdsFormTextInputTypeValues } from './types.js';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';
var TEMPLATE = precompileTemplate("{{!\n Copyright (c) HashiCorp, Inc.\n SPDX-License-Identifier: MPL-2.0\n}}\n<input\n class={{this.classNames}}\n {{style width=@width}}\n id={{@id}}\n aria-describedby={{@ariaDescribedBy}}\n ...attributes\n value={{@value}}\n type={{this.type}}\n/>");
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
// notice: we don't support all the possible HTML types, only a subset
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
const DEFAULT_TYPE = HdsFormTextInputTypeValues.Text;
const TYPES = Object.values(HdsFormTextInputTypeValues);
class HdsFormTextInputBase extends Component {
/**
* Sets the type of input
*
* @param type
* @type {string}
* @default 'text'
*/
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 the class names to apply to the component.
* @method classNames
* @return {string} The "class" attribute to apply to the component.
*/
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(' ');
}
}
setComponentTemplate(TEMPLATE, HdsFormTextInputBase);
export { DEFAULT_TYPE, TYPES, HdsFormTextInputBase as default };
//# sourceMappingURL=base.js.map