@hashicorp/design-system-components
Version:
Helios Design System Components
70 lines (61 loc) • 2.17 kB
JavaScript
import Component from '@glimmer/component';
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<Hds::Text::Body\n class={{this.classNames}}\n @tag=\"div\"\n @size=\"100\"\n @weight=\"regular\"\n id={{this.id}}\n {{did-insert this.onInsert}}\n ...attributes\n>\n {{yield}}\n</Hds::Text::Body>");
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const ID_PREFIX = 'helper-text-';
const NOOP = () => {};
class HdsFormHelperText extends Component {
/**
* Determines the unique ID to assign to the element
* @method id
* @return {(string|null)} The "id" attribute to apply to the element or null, if no controlId is provided
*/
get id() {
const {
controlId
} = this.args;
if (controlId) {
return `${ID_PREFIX}${controlId}`;
}
return null;
}
/**
* @param onInsert
* @type {function}
* @default () => {}
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get onInsert() {
const {
onInsert
} = this.args;
// notice: this is a guard used to prevent triggering an error when the component is used as standalone element
if (typeof onInsert === 'function') {
return onInsert;
} else {
return NOOP;
}
}
/**
* 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-helper-text'];
// add a class based on the @contextualClass argument
// notice: this will *not* be documented for public use
// the reason for this is that the contextual component declarations don't pass attributes to the component
if (this.args.contextualClass) {
classes.push(this.args.contextualClass);
}
return classes.join(' ');
}
}
setComponentTemplate(TEMPLATE, HdsFormHelperText);
export { ID_PREFIX, HdsFormHelperText as default };
//# sourceMappingURL=index.js.map