UNPKG

@hashicorp/design-system-components

Version:
48 lines (45 loc) 2.12 kB
import Component from '@glimmer/component'; import { guidFor } from '@ember/object/internals'; import { assert } from '@ember/debug'; import { or } from 'ember-truth-helpers'; import style from 'ember-style-modifier'; import { HdsTableHorizontalAlignmentValues } from './types.js'; import HdsTableThButtonTooltip from './th-button-tooltip.js'; import { precompileTemplate } from '@ember/template-compilation'; import { setComponentTemplate } from '@ember/component'; /** * Copyright IBM Corp. 2021, 2025 * SPDX-License-Identifier: MPL-2.0 */ const ALIGNMENTS = Object.values(HdsTableHorizontalAlignmentValues); const DEFAULT_ALIGN = HdsTableHorizontalAlignmentValues.Left; class HdsTableTh extends Component { _labelId = guidFor(this); get align() { const { align = DEFAULT_ALIGN } = this.args; assert(`@align for "Hds::Table::Th" must be one of the following: ${ALIGNMENTS.join(', ')}; received: ${align}`, ALIGNMENTS.includes(align)); return align; } get classNames() { const classes = ['hds-table__th']; // add a class based on the @align argument if (this.align) { classes.push(`hds-table__th--align-${this.align}`); } return classes.join(' '); } static { setComponentTemplate(precompileTemplate("<th class={{this.classNames}} {{style width=@width minWidth=@width}} ...attributes scope={{(or @scope \"col\")}}>\n {{#if @isVisuallyHidden}}\n <span class=\"sr-only\">{{yield}}</span>\n {{else}}\n {{#if @tooltip}}\n <div class=\"hds-table__th-content\">\n <span id={{this._labelId}} class=\"hds-typography-body-200 hds-font-weight-semibold\">{{yield}}</span>\n <HdsTableThButtonTooltip @tooltip={{@tooltip}} @labelId={{this._labelId}} />\n </div>\n {{else}}\n <span class=\"hds-typography-body-200 hds-font-weight-semibold\">{{yield}}</span>\n {{/if}}\n {{/if}}\n</th>", { strictMode: true, scope: () => ({ or, style, HdsTableThButtonTooltip }) }), this); } } export { ALIGNMENTS, DEFAULT_ALIGN, HdsTableTh as default }; //# sourceMappingURL=th.js.map