UNPKG

@hashicorp/design-system-components

Version:
78 lines (75 loc) 2.63 kB
import Component from '@glimmer/component'; import { hash } from '@ember/helper'; import didInsert from '@ember/render-modifiers/modifiers/did-insert'; import willDestroy from '@ember/render-modifiers/modifiers/will-destroy'; import HdsIcon from '../../icon/index.js'; import HdsTextBody from '../../text/body.js'; import HdsFormErrorMessage from './message.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 = 'error-'; const NOOP = () => {}; class HdsFormError 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; } } // eslint-disable-next-line @typescript-eslint/no-explicit-any get onRemove() { const { onRemove } = this.args; // notice: this is a guard used to prevent triggering an error when the component is used as standalone element if (typeof onRemove === 'function') { return onRemove; } else { return NOOP; } } get classNames() { const classes = ['hds-form-error']; // 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("<div class={{this.classNames}} id={{this.id}} {{didInsert this.onInsert}} {{willDestroy this.onRemove}} ...attributes>\n <HdsIcon class=\"hds-form-error__icon\" @name=\"alert-diamond-fill\" />\n <HdsTextBody class=\"hds-form-error__content\" @tag=\"div\" @size=\"100\" @weight=\"medium\">\n {{yield (hash Message=HdsFormErrorMessage)}}\n </HdsTextBody>\n</div>", { strictMode: true, scope: () => ({ didInsert, willDestroy, HdsIcon, HdsTextBody, hash, HdsFormErrorMessage }) }), this); } } export { ID_PREFIX, HdsFormError as default }; //# sourceMappingURL=index.js.map