Skip to content

Commit 3ff6b1b

Browse files
committed
building icon paths
1 parent 231e68f commit 3ff6b1b

File tree

1,349 files changed

+4828
-9857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,349 files changed

+4828
-9857
lines changed

packages/components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@
384384
"./modifiers/hds-code-editor/types.js": "./dist/_app_/modifiers/hds-code-editor/types.js",
385385
"./modifiers/hds-register-event.js": "./dist/_app_/modifiers/hds-register-event.js",
386386
"./modifiers/hds-tooltip.js": "./dist/_app_/modifiers/hds-tooltip.js",
387+
"./services/hds-carbon.js": "./dist/_app_/services/hds-carbon.js",
387388
"./services/hds-intl.js": "./dist/_app_/services/hds-intl.js",
388389
"./services/hds-time.js": "./dist/_app_/services/hds-time.js"
389390
}

packages/components/src/components/hds/icon/index.hbs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@
88
...attributes
99
aria-hidden="{{if @title 'false' 'true'}}"
1010
aria-labelledby={{this.ariaLabelledby}}
11-
data-test-icon={{@name}}
11+
data-test-icon={{this.name}}
1212
fill="{{this.fillColor}}"
1313
id={{this._iconId}}
1414
role={{this.role}}
1515
width="{{this.svgSize.width}}"
1616
height="{{this.svgSize.height}}"
1717
viewBox="0 0 {{this.size}} {{this.size}}"
1818
xmlns="http://www.w3.org/2000/svg"
19+
{{this.loadIconModule name=this.name size=this.size carbonModeEnabled=this.hdsCarbon.carbonModeEnabled}}
1920
>
21+
{{this.iconHtml}}
22+
2023
{{#if @title}}
2124
<title id={{this._titleId}}>{{@title}}</title>
2225
<g role="presentation">
23-
<use href="#flight-{{@name}}-{{this.size}}"></use>
26+
<use href="#{{this.uniqueSymbolId}}"></use>
2427
</g>
2528
{{else}}
26-
<use href="#flight-{{@name}}-{{this.size}}"></use>
29+
<use href="#{{this.uniqueSymbolId}}"></use>
2730
{{/if}}
2831
</svg>

packages/components/src/components/hds/icon/index.ts

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@
44
*/
55

66
import Component from '@glimmer/component';
7+
import { tracked } from '@glimmer/tracking';
8+
import { service } from '@ember/service';
79
import { guidFor } from '@ember/object/internals';
810
import { assert } from '@ember/debug';
11+
import { htmlSafe } from '@ember/template';
912
import { iconNames } from '@hashicorp/flight-icons/svg';
13+
import { IconRegistry } from '@hashicorp/flight-icons/js-symbols/registry';
14+
import { task } from 'ember-concurrency';
15+
import { modifier } from 'ember-modifier';
1016
import { HdsIconSizeValues, HdsIconColorValues } from './types.ts';
11-
import type { HdsIconSizes, HdsIconColors } from './types';
17+
18+
import type { SafeString } from '@ember/template';
1219
import type { IconName } from '@hashicorp/flight-icons/svg';
13-
import type Owner from '@ember/owner';
20+
import type { IconModuleName } from '@hashicorp/flight-icons/js-symbols/registry.ts';
21+
import type { HdsIconSizes, HdsIconColors } from './types';
22+
import type HdsCarbonService from '../../../services/hds-carbon.ts';
1423

1524
export const COLORS: HdsIconColors[] = Object.values(HdsIconColorValues);
1625
export const NAMES = iconNames;
1726

27+
interface IconModule {
28+
flight: (symbolId: string) => string;
29+
carbon: ((symbolId: string) => string) | null;
30+
}
31+
1832
export interface HdsIconSignature {
1933
Args: {
2034
name: IconName;
@@ -29,19 +43,58 @@ export interface HdsIconSignature {
2943
}
3044

3145
export default class HdsIcon extends Component<HdsIconSignature> {
46+
@service declare readonly hdsCarbon: HdsCarbonService;
47+
48+
@tracked iconModule: IconModule | null = null;
49+
3250
private _iconId = 'icon-' + guidFor(this);
3351
private _titleId = 'title-' + guidFor(this);
3452

35-
constructor(owner: Owner, args: HdsIconSignature['Args']) {
36-
super(owner, args);
53+
loadIconModule = modifier(
54+
(
55+
_element: SVGElement,
56+
57+
_positional: [],
58+
{
59+
name,
60+
size,
61+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
62+
carbonModeEnabled,
63+
}: { name: IconName; size: HdsIconSizes; carbonModeEnabled: boolean }
64+
) => {
65+
void this.loadIconModuleTask.perform(name, size);
66+
}
67+
);
68+
69+
get name(): HdsIconSignature['Args']['name'] {
70+
const { name } = this.args;
3771

38-
if (!this.args.name) {
72+
if (name === undefined) {
3973
assert('Please provide to <Hds::Icon> a value for @name');
40-
} else if (!iconNames.includes(this.args.name)) {
41-
assert(
42-
`The icon @name "${this.args.name}" provided to <Hds::Icon> is not correct. Please verify it exists on https://helios.hashicorp.design/icons/library`
43-
);
4474
}
75+
76+
return name;
77+
}
78+
79+
get iconHtml(): SafeString | undefined {
80+
const module = this.iconModule;
81+
82+
if (module == null) {
83+
return undefined;
84+
}
85+
86+
const generator =
87+
this.hdsCarbon.carbonModeEnabled && module.carbon !== null
88+
? module.carbon
89+
: module.flight;
90+
91+
const iconHtml = htmlSafe(generator(this.uniqueSymbolId));
92+
93+
return iconHtml;
94+
}
95+
96+
get uniqueSymbolId(): string {
97+
return `${this._iconId}-symbol`;
4598
}
4699

47100
get isInline(): boolean {
@@ -66,7 +119,7 @@ export default class HdsIcon extends Component<HdsIconSignature> {
66119
}
67120
}
68121

69-
get size(): string {
122+
get size(): HdsIconSizes {
70123
return this.args.size ?? HdsIconSizeValues.Sixteen;
71124
}
72125

@@ -112,4 +165,19 @@ export default class HdsIcon extends Component<HdsIconSignature> {
112165

113166
return classes.join(' ');
114167
}
168+
169+
loadIconModuleTask = task(
170+
async (name: IconName, size: HdsIconSizes): Promise<void> => {
171+
const iconModuleName: IconModuleName = `${name}-${size}`;
172+
const importFn = IconRegistry[iconModuleName];
173+
174+
if (importFn === undefined) {
175+
assert(
176+
`The icon @name "${this.args.name}" or @size "${this.args.size}" provided to <Hds::Icon> is not correct. Please verify the icon exists on https://helios.hashicorp.design/icons/library`
177+
);
178+
} else {
179+
this.iconModule = await importFn();
180+
}
181+
}
182+
);
115183
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
import Service from '@ember/service';
7+
import { tracked } from '@glimmer/tracking';
8+
9+
export default class HdsCarbonService extends Service {
10+
@tracked carbonModeEnabled: boolean = false;
11+
12+
toggleCarbonMode() {
13+
this.carbonModeEnabled = !this.carbonModeEnabled;
14+
}
15+
}

packages/flight-icons/js-symbols/accessibility-16.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/flight-icons/js-symbols/accessibility-24.js

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
/**
2-
* Generated Icon: activity-16
3-
*/
41
export const flight = function (id) {
5-
return `<symbol id="${id}" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" fill-rule="evenodd" d="M6.016 1a.75.75 0 01.698.521l3.306 10.33 1.47-4.341A.75.75 0 0112.2 7H15a.75.75 0 010 1.5h-2.262l-2.028 5.99a.75.75 0 01-1.424-.011L5.952 4.06 4.504 8.008A.75.75 0 013.8 8.5H1A.75.75 0 111 7h2.276l2.02-5.508c.11-.301.4-.499.72-.492z" clip-rule="evenodd"/></symbol>`;
6-
};
7-
8-
export const carbon = function (id) {
9-
return `<symbol id="${id}" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12,29a1,1,0,0,1-.92-.62L6.33,17H2V15H7a1,1,0,0,1,.92.62L12,25.28,20.06,3.65A1,1,0,0,1,21,3a1,1,0,0,1,.93.68L25.72,15H30v2H25a1,1,0,0,1-.95-.68L21,7,12.94,28.35A1,1,0,0,1,12,29Z"/></symbol>`;
2+
return `<symbol id="${id}" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><path fill="currentColor" fill-rule="evenodd" d="M6.016 1a.75.75 0 01.698.521l3.306 10.33 1.47-4.341A.75.75 0 0112.2 7H15a.75.75 0 010 1.5h-2.262l-2.028 5.99a.75.75 0 01-1.424-.011L5.952 4.06 4.504 8.008A.75.75 0 013.8 8.5H1A.75.75 0 111 7h2.276l2.02-5.508c.11-.301.4-.499.72-.492z" clip-rule="evenodd"/></g></symbol>`;
103
};
4+
export const carbon = null;
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
/**
2-
* Generated Icon: activity-24
3-
*/
41
export const flight = function (id) {
5-
return `<symbol id="${id}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" fill-rule="evenodd" d="M9.003 2a.75.75 0 01.71.519l5.278 16.27 2.294-7.265A.75.75 0 0118 11h4a.75.75 0 010 1.5h-3.45l-2.835 8.976a.75.75 0 01-1.428.005L8.99 5.151l-2.278 6.836A.75.75 0 016 12.5H2A.75.75 0 012 11h3.46l2.828-8.487A.75.75 0 019.003 2z" clip-rule="evenodd"/></symbol>`;
6-
};
7-
8-
export const carbon = function (id) {
9-
return `<symbol id="${id}" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12,29a1,1,0,0,1-.92-.62L6.33,17H2V15H7a1,1,0,0,1,.92.62L12,25.28,20.06,3.65A1,1,0,0,1,21,3a1,1,0,0,1,.93.68L25.72,15H30v2H25a1,1,0,0,1-.95-.68L21,7,12.94,28.35A1,1,0,0,1,12,29Z"/></symbol>`;
2+
return `<symbol id="${id}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><path fill="currentColor" fill-rule="evenodd" d="M9.003 2a.75.75 0 01.71.519l5.278 16.27 2.294-7.265A.75.75 0 0118 11h4a.75.75 0 010 1.5h-3.45l-2.835 8.976a.75.75 0 01-1.428.005L8.99 5.151l-2.278 6.836A.75.75 0 016 12.5H2A.75.75 0 012 11h3.46l2.828-8.487A.75.75 0 019.003 2z" clip-rule="evenodd"/></g></symbol>`;
103
};
4+
export const carbon = null;

packages/flight-icons/js-symbols/alert-circle-16.js

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
/**
2-
* Generated Icon: alert-circle-24
3-
*/
41
export const flight = function (id) {
5-
return `<symbol id="${id}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zM12 15a1 1 0 100 2h.01a1 1 0 100-2H12z"/><path fill-rule="evenodd" d="M1 12C1 5.925 5.925 1 12 1s11 4.925 11 11-4.925 11-11 11S1 18.075 1 12zm11-9.5a9.5 9.5 0 100 19 9.5 9.5 0 000-19z" clip-rule="evenodd"/></g></symbol>`;
6-
};
7-
8-
export const carbon = function (id) {
9-
return `<symbol id="${id}" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16,2A14,14,0,1,0,30,16,14,14,0,0,0,16,2Zm0,26A12,12,0,1,1,28,16,12,12,0,0,1,16,28Z"/><path d="M15 8H17V19H15zM16 22a1.5 1.5 0 101.5 1.5A1.5 1.5 0 0016 22z"/></symbol>`;
2+
return `<symbol id="${id}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><g fill="currentColor"><path d="M12 7a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0112 7zM12 15a1 1 0 100 2h.01a1 1 0 100-2H12z"/><path fill-rule="evenodd" d="M1 12C1 5.925 5.925 1 12 1s11 4.925 11 11-4.925 11-11 11S1 18.075 1 12zm11-9.5a9.5 9.5 0 100 19 9.5 9.5 0 000-19z" clip-rule="evenodd"/></g></g></symbol>`;
103
};
4+
export const carbon = null;

0 commit comments

Comments
 (0)