@hashicorp/design-system-components
Version:
Helios Design System Components
93 lines (90 loc) • 3.96 kB
JavaScript
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { eq } from 'ember-truth-helpers';
import { HdsLinkColorValues, HdsLinkIconPositionValues, HdsLinkStandaloneSizeValues } from './types.js';
import HdsInteractive from '../interactive/index.js';
import HdsIcon from '../icon/index.js';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';
/**
* Copyright IBM Corp. 2021, 2025
* SPDX-License-Identifier: MPL-2.0
*/
const DEFAULT_ICON_POSITION = HdsLinkIconPositionValues.Leading;
const DEFAULT_COLOR = HdsLinkColorValues.Primary;
const DEFAULT_SIZE = HdsLinkStandaloneSizeValues.Medium;
const ICON_POSITIONS = Object.values(HdsLinkIconPositionValues);
const COLORS = Object.values(HdsLinkColorValues);
const SIZES = Object.values(HdsLinkStandaloneSizeValues);
class HdsLinkStandalone extends Component {
constructor(owner, args) {
super(owner, args);
if (!(this.args.href || this.args.route)) {
assert('@href or @route must be defined for <Hds::Link::Standalone>');
}
}
get text() {
const {
text
} = this.args;
assert('@text for "Hds::Link::Standalone" must have a valid value', text !== undefined);
return text;
}
get color() {
const {
color = DEFAULT_COLOR
} = this.args;
assert(`@color for "Hds::Link::Standalone" must be one of the following: ${COLORS.join(', ')}; received: ${color}`, COLORS.includes(color));
return color;
}
get icon() {
const {
icon
} = this.args;
assert('@icon for "Hds::Link::Standalone" must have a valid value', icon !== undefined);
return icon;
}
get iconPosition() {
const {
iconPosition = DEFAULT_ICON_POSITION
} = this.args;
assert(`@iconPosition for "Hds::Link::Standalone" must be one of the following: ${ICON_POSITIONS.join(', ')}; received: ${iconPosition}`, ICON_POSITIONS.includes(iconPosition));
return iconPosition;
}
get size() {
const {
size = DEFAULT_SIZE
} = this.args;
assert(`@size for "Hds::Link::Standalone" must be one of the following: ${SIZES.join(', ')}; received: ${size}`, SIZES.includes(size));
return size;
}
get iconSize() {
if (this.args.size === 'large') {
return '24';
} else {
return '16';
}
}
get classNames() {
const classes = ['hds-link-standalone'];
// add a class based on the @size argument
classes.push(`hds-link-standalone--size-${this.size}`);
// add a class based on the @color argument
classes.push(`hds-link-standalone--color-${this.color}`);
// add a class based on the @iconPosition argument
classes.push(`hds-link-standalone--icon-position-${this.iconPosition}`);
return classes.join(' ');
}
static {
setComponentTemplate(precompileTemplate("<HdsInteractive class={{this.classNames}} @current-when={{@current-when}} @models={{@models}} @model={{@model}} @query={{@query}} @replace={{@replace}} @route={{@route}} @isRouteExternal={{@isRouteExternal}} @href={{@href}} @isHrefExternal={{@isHrefExternal}} ...attributes>\n {{#if (eq this.iconPosition \"leading\")}}\n <span class=\"hds-link-standalone__icon\">\n <HdsIcon @name={{this.icon}} @size={{this.iconSize}} @stretched={{true}} />\n </span>\n <span class=\"hds-link-standalone__text\">\n {{this.text}}\n </span>\n {{else}}\n <span class=\"hds-link-standalone__text\">\n {{this.text}}\n </span>\n <span class=\"hds-link-standalone__icon\">\n <HdsIcon @name={{this.icon}} @size={{this.iconSize}} @stretched={{true}} />\n </span>\n {{/if}}\n</HdsInteractive>", {
strictMode: true,
scope: () => ({
HdsInteractive,
eq,
HdsIcon
})
}), this);
}
}
export { COLORS, DEFAULT_COLOR, DEFAULT_ICON_POSITION, DEFAULT_SIZE, ICON_POSITIONS, SIZES, HdsLinkStandalone as default };
//# sourceMappingURL=standalone.js.map