Files
vault/ui/lib/core/addon/components/icon.js
claire bontempo e61bd967e3 Add docfy for addon components (#27188)
* move script to scripts folder

* add docfy to router and scripts

* add docfy to router and scripts

* fix jsdoc syntax

* add component markdown files to gitignore

* improve error handling for scripts

* tidy up remaining jsdoc syntax

* add sample jsdoc components

* add known issue info

* make not using multi-line components clearer

* make generating docs clearer

* update copy

* final how to docfy cleanup

* fix ts file @module syntax

* fix read more syntax

* make docfy typescript compatible
2024-05-29 14:06:38 -07:00

46 lines
1.4 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import flightIconMap from '@hashicorp/flight-icons/catalog.json';
const flightIconNames = flightIconMap.assets.map((asset) => asset.iconName).uniq();
/**
* @module Icon
* `Icon` components are used to display an icon.
*
* Flight icon documentation at https://helios.hashicorp.design/icons/usage-guidelines?tab=code#how-to-use-icons
* Flight icon library at https://helios.hashicorp.design/icons/library
*
* @example
* <Icon @name="heart" @size="24" />
*
* @param {string} name - The name of the SVG to render inline. Required.
* @param {string} [size=16] - size for flight icon, can be 16 or 24
*
*/
export default class IconComponent extends Component {
constructor(owner, args) {
super(owner, args);
assert('Icon component size argument must be either "16" or "24"', ['16', '24'].includes(this.size));
assert('Icon name argument must be provided', this.args.name);
}
get size() {
return this.args.size || '16';
}
// favor flight icon set and fall back to structure icons if not found
get isFlightIcon() {
return this.args.name ? flightIconNames.includes(this.args.name) : false;
}
get hsIconClass() {
return this.size === '24' ? 'hs-icon-xlm' : 'hs-icon-l';
}
}