Home / Class/ DevToolbarIcon Class — astro Architecture

DevToolbarIcon Class — astro Architecture

Architecture documentation for the DevToolbarIcon class in icon.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  d6c9a997_c573_d283_b6d1_6365995e2a3b["DevToolbarIcon"]
  ff7ec47a_abe9_4d9c_94f2_4252bbdc58c2["icon.ts"]
  d6c9a997_c573_d283_b6d1_6365995e2a3b -->|defined in| ff7ec47a_abe9_4d9c_94f2_4252bbdc58c2
  669b37dc_5ea4_7c66_9d63_618ed7b7df10["icon()"]
  d6c9a997_c573_d283_b6d1_6365995e2a3b -->|method| 669b37dc_5ea4_7c66_9d63_618ed7b7df10
  dd779963_eea5_dbd0_3238_6cb820b12a93["constructor()"]
  d6c9a997_c573_d283_b6d1_6365995e2a3b -->|method| dd779963_eea5_dbd0_3238_6cb820b12a93
  f8c9ee63_1ae1_0bbe_1c73_266a00b0bc18["getIconHTML()"]
  d6c9a997_c573_d283_b6d1_6365995e2a3b -->|method| f8c9ee63_1ae1_0bbe_1c73_266a00b0bc18
  254d8849_519e_5224_59bc_121fbc545bd4["buildTemplate()"]
  d6c9a997_c573_d283_b6d1_6365995e2a3b -->|method| 254d8849_519e_5224_59bc_121fbc545bd4

Relationship Graph

Source Code

packages/astro/src/runtime/client/dev-toolbar/ui-library/icon.ts lines 3–51

export class DevToolbarIcon extends HTMLElement {
	_icon: Icon | undefined = undefined;
	shadowRoot: ShadowRoot;

	get icon() {
		return this._icon;
	}
	set icon(name: Icon | undefined) {
		this._icon = name;
		this.buildTemplate();
	}

	constructor() {
		super();

		this.shadowRoot = this.attachShadow({ mode: 'open' });

		if (this.hasAttribute('icon')) {
			this.icon = this.getAttribute('icon') as Icon;
		} else {
			this.buildTemplate();
		}
	}

	getIconHTML(icon: Icon | undefined) {
		if (icon && isDefinedIcon(icon)) {
			return getIconElement(icon)?.outerHTML ?? '';
		}

		// If the icon that was passed isn't one of the predefined one, assume that they're passing it in as a slot
		return '<slot />';
	}

	buildTemplate() {
		this.shadowRoot.innerHTML = `
			<style>
				svg {
					width: 100%;
					height: 100%;
				}

				@media (forced-colors: active) {
					svg path[fill="#fff"] {
						fill: black;
					}
				}
			</style>\n${this.getIconHTML(this._icon)}`;
	}
}

Domain

Frequently Asked Questions

What is the DevToolbarIcon class?
DevToolbarIcon is a class in the astro codebase, defined in packages/astro/src/runtime/client/dev-toolbar/ui-library/icon.ts.
Where is DevToolbarIcon defined?
DevToolbarIcon is defined in packages/astro/src/runtime/client/dev-toolbar/ui-library/icon.ts at line 3.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free