Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fbed559
feat(statuslight): create shared types file
marissahuysentruyt Oct 8, 2025
7cff961
feat(status-light): import types into core status-light
marissahuysentruyt Oct 9, 2025
45773c1
refactor(status-light): status light base
marissahuysentruyt Oct 9, 2025
1ac3130
refactor(status-light): status light second-gen
marissahuysentruyt Oct 9, 2025
5e40486
refactor(status-light): status light first-gen
marissahuysentruyt Oct 9, 2025
4e3c524
feat(status-light): add s2 styles
marissahuysentruyt Oct 10, 2025
6bc020d
feat(status-light): add second-gen stories
marissahuysentruyt Oct 10, 2025
a8a8cf3
feat(statuslight): add sizeMap decorator
marissahuysentruyt Oct 10, 2025
90e0f34
refactor(statuslight): correct accent and cyan variant selectors
marissahuysentruyt Oct 13, 2025
d493e6e
feat(statuslight): add missing first-gen variants to stories
marissahuysentruyt Oct 13, 2025
ce33a5b
test(status-light): add dev mode warning tests in first-gen
marissahuysentruyt Oct 14, 2025
d0c0893
test(statuslight): add second-gen test file
marissahuysentruyt Oct 14, 2025
381e1c2
revert: feat(statuslight): add missing first-gen variants to stories
marissahuysentruyt Oct 16, 2025
2e7865c
revert: refactor(statuslight): correct accent and cyan variant selectors
marissahuysentruyt Oct 16, 2025
625f49d
chore(statuslight): change todo to deprecated
marissahuysentruyt Oct 16, 2025
b6f2019
docs(statuslight): move variant description to JSDocs
marissahuysentruyt Oct 16, 2025
ac58a1f
chore(statuslight): use story override patterns consistent with badge
marissahuysentruyt Oct 16, 2025
21c29d4
chore: use size override patterns consistent with badge
marissahuysentruyt Oct 16, 2025
59a8c74
fix(statuslight): disabled logic in first-gen
marissahuysentruyt Oct 16, 2025
4d57a9b
refactor: remove disabled logic from base class
marissahuysentruyt Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion first-gen/packages/status-light/src/StatusLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,100 @@
import {
CSSResultArray,
html,
PropertyValues,
TemplateResult,
} from '@spectrum-web-components/base';
import { StatusLightBase } from '@swc/core/components/status-light';

import { property } from '@spectrum-web-components/base/src/decorators.js';

import {
STATUSLIGHT_VARIANTS_COLOR_S1,
STATUSLIGHT_VARIANTS_S1,
STATUSLIGHT_VARIANTS_SEMANTIC_S1,
StatusLightBase,
type StatusLightVariantS1,
} from '@swc/core/components/status-light';

import statusLightStyles from './status-light.css.js';

/**
* @deprecated The `STATUSLIGHT_VARIANTS` export is deprecated and will be removed
* in a future release. If needed, you can access the internal
* `StatusLight.VARIANTS` property from the constructor.
*/
export const STATUSLIGHT_VARIANTS = STATUSLIGHT_VARIANTS_S1;

/**
* @deprecated The `StatusLightVariant` type export is deprecated and will be removed
* in a future release. If needed, you can infer this type from the `StatusLight`
* prototype as follows: `typeof StatusLight.prototype.variant`
*/
export type StatusLightVariant = StatusLightVariantS1;

/**
* @element sp-status-light
*
* @slot - text label of the Status Light
*/
export class StatusLight extends StatusLightBase {
// ────────────────────
// API OVERRIDES
// ────────────────────

/**
* @internal
*/
static override readonly VARIANTS_COLOR = STATUSLIGHT_VARIANTS_COLOR_S1;

/**
* @internal
*/
static override readonly VARIANTS_SEMANTIC =
STATUSLIGHT_VARIANTS_SEMANTIC_S1;

/**
* @internal
*/
static override readonly VARIANTS = STATUSLIGHT_VARIANTS_S1;

/**
* The variant of the status light.
*/
@property({ type: String, reflect: true })
public override variant: StatusLightVariantS1 = 'info';

// ───────────────────────
// API ADDITIONS
// ───────────────────────

/**
* @deprecated The `disabled` property is is deprecated and will be removed
* in a future release.
*
* A status light in a disabled state shows that a status exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that a status may become available later.
*
*/
@property({ type: Boolean, reflect: true })
public disabled = false;

// ──────────────────────
// IMPLEMENTATION
// ──────────────────────

protected override updated(changes: PropertyValues): void {
super.updated(changes);
if (changes.has('disabled')) {
if (this.disabled) {
this.setAttribute('aria-disabled', 'true');
} else {
this.removeAttribute('aria-disabled');
}
}
}
// ──────────────────────────────
// RENDERING & STYLING
// ──────────────────────────────

public static override get styles(): CSSResultArray {
return [statusLightStyles];
}
Expand Down
38 changes: 38 additions & 0 deletions first-gen/packages/status-light/test/status-light.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import '@spectrum-web-components/status-light/sp-status-light.js';
import { StatusLight } from '@spectrum-web-components/status-light';
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
import { spy } from 'sinon';

describe('Status Light', () => {
it('loads correctly', async () => {
Expand Down Expand Up @@ -41,4 +42,41 @@ describe('Status Light', () => {
expect(el.hasAttribute('aria-disabled')).to.be.true;
expect(el.getAttribute('aria-disabled')).to.equal('true');
});

describe('dev mode warnings', () => {
Copy link
Collaborator Author

@marissahuysentruyt marissahuysentruyt Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had Cursor help me with this- do we want tests for the dev warnings at all? Feedback on this is appreciated either way!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good idea to me, but open to dissenting opinions (cc @rubencarvalho).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do test for dev mode on other components so I think that makes a lot of sense to add here too. Check out this reference for an example:

it('should log dev warning when given invalid variant', async () => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine! We’ll probably want to create a dedicated test helper to remove some boilerplate from these dev warnings tests, but this looks good for now 😃

let warningMessage: typeof window.__swc.warn;

beforeEach(() => {
// Create __swc if it doesn't exist
window.__swc = window.__swc || { warn: () => {} };
// Store original warn function
warningMessage = window.__swc.warn;
// Reset issued warnings to avoid dedupe interference
window.__swc.issuedWarnings = new Set();
// Enable debug guard
window.__swc.DEBUG = true;
});

afterEach(() => {
// Restore original warn function
window.__swc.warn = warningMessage;
});

it('warns when unsupported variant is used (brown)', async () => {
const warnSpy = spy();
window.__swc.warn = warnSpy as unknown as typeof window.__swc.warn;

const el = await fixture<StatusLight>(html`
<sp-status-light variant="brown"></sp-status-light>
`);

await elementUpdated(el);

expect(warnSpy.called).to.be.true;
expect(warnSpy.firstCall.args[0]).to.equal(el);
expect(warnSpy.firstCall.args[1]).to.equal(
`<${el.localName}> element expects the "variant" attribute to be one of the following:`
);
});
});
});
110 changes: 83 additions & 27 deletions second-gen/packages/core/components/status-light/StatusLight.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,108 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import { PropertyValues } from 'lit';
import { property } from 'lit/decorators.js';

import { SizedMixin, SpectrumElement } from '@swc/core/shared/base';

import { type StatusLightVariant } from './StatusLight.types';

/**
* @element sp-status-light
* A status light is a great way to convey semantic meaning and the condition of an entity, such as statuses and categories. It provides visual indicators through colored dots accompanied by descriptive text.
*
* @slot - text label of the Status Light
* @slot - The text label of the status light.
*/
export abstract class StatusLightBase extends SizedMixin(SpectrumElement, {
noDefaultSize: true,
}) {
// ─────────────────────────
// API TO OVERRIDE
// ─────────────────────────

/**
* @internal
*
* A readonly array of the valid color variants for the status light.
*
* This is an actual internal property, intended not for customer use
* but for use in internal validation logic, stories, tests, etc.
*
* Because S1 and S2 support different color variants, the value of this
* property must be set in each subclass.
*/
static readonly VARIANTS_COLOR: readonly string[];

/**
* A status light in a disabled state shows that a status exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that a status may become available later.
* @internal
*
* A readonly array of the valid semantic variants for the status light.
*
* This is an actual internal property, intended not for customer use
* but for use in internal validation logic, stories, tests, etc.
*
* Because S1 and S2 support different semantic variants, the value of this
* property must be set in each subclass.
*/
@property({ type: Boolean, reflect: true })
public disabled = false;
static readonly VARIANTS_SEMANTIC: readonly string[];

/**
* The visual variant to apply to this status light.
* @internal
*
* A readonly array of all valid variants for the status light.
*
* This is an actual internal property, intended not for customer use
* but for use in internal validation logic, stories, tests, etc.
*
* Because S1 and S2 support different variants, the value of this
* property must be set in each subclass.
*/
@property({ reflect: true })
public variant:
| 'negative'
| 'notice'
| 'positive'
| 'info'
| 'neutral'
| 'yellow'
| 'fuchsia'
| 'indigo'
| 'seafoam'
| 'chartreuse'
| 'magenta'
| 'celery'
| 'purple' = 'info';
static readonly VARIANTS: readonly string[];

/**
* @internal
*
* The variant of the status light.
*
* This is a public property, but its valid values vary between S1 and S2,
* so the property (and its docs) need to be redefined in each subclass.
*
* The type declared here is a union of the valid values for S1 and S2,
* and should be narrowed in each subclass.
*/
@property({ type: String, reflect: true })
public variant: StatusLightVariant = 'info';

// ──────────────────────
// IMPLEMENTATION
// ──────────────────────

protected override updated(changes: PropertyValues): void {
super.updated(changes);
if (changes.has('disabled')) {
if (this.disabled) {
this.setAttribute('aria-disabled', 'true');
} else {
this.removeAttribute('aria-disabled');
if (window.__swc?.DEBUG) {
const constructor = this.constructor as typeof StatusLightBase;
if (!constructor.VARIANTS.includes(this.variant)) {
window.__swc.warn(
this,
`<${this.localName}> element expects the "variant" attribute to be one of the following:`,
'https://opensource.adobe.com/spectrum-web-components/components/status-light/#variants',
{
issues: [...constructor.VARIANTS],
}
);
}
// Check disabled property if it exists (S1 only)
if (this.hasAttribute('disabled') && !('disabled' in this)) {
window.__swc.warn(
this,
`<${this.localName}> element does not support the disabled state.`,
'https://opensource.adobe.com/spectrum-web-components/components/status-light/#states',
{
issues: [
'disabled is not a supported property in Spectrum 2',
],
}
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/*
* @todo The S1 types can be removed once we are no longer maintaining 1st-gen.
*/

export const STATUSLIGHT_VARIANTS_SEMANTIC = [
'neutral',
'info',
'positive',
'negative',
'notice',
] as const;

export const STATUSLIGHT_VARIANTS_SEMANTIC_S1 = [
...STATUSLIGHT_VARIANTS_SEMANTIC,
'accent',
] as const;

export const STATUSLIGHT_VARIANTS_SEMANTIC_S2 = [
...STATUSLIGHT_VARIANTS_SEMANTIC,
] as const;

export const STATUSLIGHT_VARIANTS_COLOR_S1 = [
'fuchsia',
'indigo',
'magenta',
'purple',
'seafoam',
'yellow',
'chartreuse',
'celery',
'cyan',
] as const;

export const STATUSLIGHT_VARIANTS_COLOR_S2 = [
...STATUSLIGHT_VARIANTS_COLOR_S1,
'pink',
'turquoise',
'brown',
'cinnamon',
'silver',
] as const;

export const STATUSLIGHT_VARIANTS_S1 = [
...STATUSLIGHT_VARIANTS_SEMANTIC_S1,
...STATUSLIGHT_VARIANTS_COLOR_S1,
] as const;

export const STATUSLIGHT_VARIANTS_S2 = [
...STATUSLIGHT_VARIANTS_SEMANTIC_S2,
...STATUSLIGHT_VARIANTS_COLOR_S2,
] as const;

export type StatusLightVariantS1 = (typeof STATUSLIGHT_VARIANTS_S1)[number];
export type StatusLightVariantS2 = (typeof STATUSLIGHT_VARIANTS_S2)[number];
export type StatusLightVariant = StatusLightVariantS1 | StatusLightVariantS2;
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
* governing permissions and limitations under the License.
*/
export * from './StatusLight.base';
export * from './StatusLight.types';
Loading
Loading