@hashicorp/design-system-components
Version:
Helios Design System Components
54 lines (51 loc) • 2.11 kB
JavaScript
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import HdsText from './index.js';
import { HdsTextSizeValues, HdsTextWeightValues } from './types.js';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';
/**
* Copyright IBM Corp. 2021, 2025
* SPDX-License-Identifier: MPL-2.0
*/
const SIZES = [HdsTextSizeValues.ThreeHundred, HdsTextSizeValues.TwoHundred, HdsTextSizeValues.OneHundred];
const DEFAULT_SIZE = HdsTextSizeValues.TwoHundred;
const DEFAULT_WEIGHT = HdsTextWeightValues.Regular;
const WEIGHTS_PER_SIZE = {
[HdsTextSizeValues.ThreeHundred]: [HdsTextWeightValues.Regular, HdsTextWeightValues.Bold],
[HdsTextSizeValues.TwoHundred]: [HdsTextWeightValues.Regular, HdsTextWeightValues.Bold],
[HdsTextSizeValues.OneHundred]: [HdsTextWeightValues.Regular, HdsTextWeightValues.Bold]
};
class HdsTextCode extends Component {
// Sets the "size" for the text
get size() {
let {
size = DEFAULT_SIZE
} = this.args;
// let's be a bit forgiving with the consumers
if (typeof size === 'string') {
size = parseInt(size, 10);
}
assert(`@size for "Hds::Text::Code" must be one of the following: ${SIZES.join(', ')}; received: ${size}`, SIZES.includes(size));
return size;
}
// Sets the "weight" for the text
get weight() {
const {
weight = DEFAULT_WEIGHT
} = this.args;
const weights = WEIGHTS_PER_SIZE[this.size];
assert(`@weight for "Hds::Text::Code" with @size=${this.size} must be one of the following: ${weights.join(', ')}; received: ${weight}`, weights.includes(weight));
return weight;
}
static {
setComponentTemplate(precompileTemplate("<HdsText @group=\"code\" @size={{this.size}} @weight={{this.weight}} @align={{@align}} @color={{@color}} @tag={{@tag}} ...attributes>{{yield}}</HdsText>", {
strictMode: true,
scope: () => ({
HdsText
})
}), this);
}
}
export { DEFAULT_SIZE, DEFAULT_WEIGHT, SIZES, WEIGHTS_PER_SIZE, HdsTextCode as default };
//# sourceMappingURL=code.js.map