@hashicorp/design-system-components
Version:
Helios Design System Components
58 lines (55 loc) • 1.82 kB
JavaScript
import Component from '@glimmer/component';
import didInsert from '@ember/render-modifiers/modifiers/did-insert';
import HdsTextBody from '../../text/body.js';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';
/**
* Copyright IBM Corp. 2021, 2025
* SPDX-License-Identifier: MPL-2.0
*/
const ID_PREFIX = 'helper-text-';
const NOOP = () => {};
class HdsFormHelperText extends Component {
get id() {
const {
controlId
} = this.args;
if (controlId) {
return `${ID_PREFIX}${controlId}`;
}
return null;
}
// 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 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(' ');
}
static {
setComponentTemplate(precompileTemplate("<HdsTextBody class={{this.classNames}} @tag=\"div\" @size=\"100\" @weight=\"regular\" id={{this.id}} {{didInsert this.onInsert}} ...attributes>\n {{yield}}\n</HdsTextBody>", {
strictMode: true,
scope: () => ({
HdsTextBody,
didInsert
})
}), this);
}
}
export { ID_PREFIX, HdsFormHelperText as default };
//# sourceMappingURL=index.js.map