Home / Class/ DevToolbarCard Class — astro Architecture

DevToolbarCard Class — astro Architecture

Architecture documentation for the DevToolbarCard class in card.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd["DevToolbarCard"]
  d4065da0_74c3_5b02_1edc_8fe4548c9edf["card.ts"]
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd -->|defined in| d4065da0_74c3_5b02_1edc_8fe4548c9edf
  d9424fb6_44c6_d9af_a768_ffea3baf21d8["cardStyle()"]
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd -->|method| d9424fb6_44c6_d9af_a768_ffea3baf21d8
  495d22e2_f89e_7919_fdcd_e144a123f30b["constructor()"]
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd -->|method| 495d22e2_f89e_7919_fdcd_e144a123f30b
  ea9a6b6e_7887_5160_cb08_58d74f806583["attributeChangedCallback()"]
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd -->|method| ea9a6b6e_7887_5160_cb08_58d74f806583
  4ef8718e_c8d4_405d_588e_d180e0a1916b["updateStyle()"]
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd -->|method| 4ef8718e_c8d4_405d_588e_d180e0a1916b
  22c5c240_9892_2b43_4ee1_718cd9e4bfb7["connectedCallback()"]
  37f75f3c_f7fc_630d_6b0d_4943b32b71bd -->|method| 22c5c240_9892_2b43_4ee1_718cd9e4bfb7

Relationship Graph

Source Code

packages/astro/src/runtime/client/dev-toolbar/ui-library/card.ts lines 7–133

export class DevToolbarCard extends HTMLElement {
	link?: string | undefined | null;
	clickAction?: () => void | (() => Promise<void>);
	shadowRoot: ShadowRoot;

	_cardStyle: CardStyle = 'purple';

	get cardStyle() {
		return this._cardStyle;
	}

	set cardStyle(value) {
		if (!styles.includes(value)) {
			settings.logger.error(
				`Invalid style: ${value}, expected one of ${styles.join(', ')}, got ${value}.`,
			);
			return;
		}
		this._cardStyle = value;
		this.updateStyle();
	}

	static observedAttributes = ['card-style'];

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

		this.link = this.getAttribute('link');
	}

	attributeChangedCallback() {
		if (this.hasAttribute('card-style'))
			this.cardStyle = this.getAttribute('card-style') as CardStyle;

		this.updateStyle();
	}

	updateStyle() {
		const style = this.shadowRoot.querySelector<HTMLStyleElement>('#selected-style');

		if (style) {
			style.innerHTML = `
				:host {
					--hover-background: var(--${this.cardStyle}-hover-background);
					--hover-border: var(--${this.cardStyle}-hover-border);
				}
			`;
		}
	}

	connectedCallback() {
		const element = this.link ? 'a' : this.clickAction ? 'button' : 'div';

		this.shadowRoot.innerHTML += `
			<style>
				:host {
					--purple-hover-background: rgba(136, 58, 234, 0.33);
					--purple-hover-border: 1px solid rgba(113, 24, 226, 1);

					--gray-hover-background: rgba(191, 193, 201, 0.33);
					--gray-hover-border: 1px solid rgba(191, 193, 201, 1);

					--red-hover-background: rgba(249, 196, 215, 0.33);
					--red-hover-border: 1px solid rgba(179, 62, 102, 1);

					--green-hover-background: rgba(213, 249, 196, 0.33);
					--green-hover-border: 1px solid rgba(61, 125, 31, 1);

					--yellow-hover-background: rgba(255, 236, 179, 0.33);
					--yellow-hover-border: 1px solid rgba(255, 191, 0, 1);

					--blue-hover-background: rgba(189, 195, 255, 0.33);
					--blue-hover-border: 1px solid rgba(54, 69, 217, 1);
				}

				:host>a, :host>button, :host>div {
					box-sizing: border-box;
					padding: 16px;
					display: block;
					border-radius: 8px;

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free