Skip to content

Commit 7262248

Browse files
rise-erpeldingcaseyisonit
authored andcommitted
style(status-light): clean up code styles (#6157)
* refactor: rename STATUSLIGHT to STATUS_LIGHT type * refactor: reorg types file * refactor: standardized debug warnings * refactor: update jsdoc comments --------- Co-authored-by: Casey Eickhoff <48574582+caseyisonit@users.noreply.github.com>
1 parent f759298 commit 7262248

4 files changed

Lines changed: 71 additions & 51 deletions

File tree

2nd-gen/packages/core/components/status-light/StatusLight.base.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { SpectrumElement } from '@spectrum-web-components/core/element/index.js'
1616
import { SizedMixin } from '@spectrum-web-components/core/mixins/index.js';
1717

1818
import {
19-
STATUSLIGHT_VALID_SIZES,
19+
STATUS_LIGHT_VALID_SIZES,
2020
type StatusLightVariant,
2121
} from './StatusLight.types.js';
2222

@@ -27,7 +27,7 @@ import {
2727
* @attribute {ElementSize} size - The size of the status light.
2828
*/
2929
export abstract class StatusLightBase extends SizedMixin(SpectrumElement, {
30-
validSizes: STATUSLIGHT_VALID_SIZES,
30+
validSizes: STATUS_LIGHT_VALID_SIZES,
3131
noDefaultSize: true,
3232
}) {
3333
// ─────────────────────────
@@ -91,15 +91,14 @@ export abstract class StatusLightBase extends SizedMixin(SpectrumElement, {
9191
// IMPLEMENTATION
9292
// ──────────────────────
9393

94-
protected override updated(changes: PropertyValues): void {
95-
super.updated(changes);
94+
protected override update(changedProperties: PropertyValues): void {
9695
if (window.__swc?.DEBUG) {
9796
const constructor = this.constructor as typeof StatusLightBase;
9897
if (!constructor.VARIANTS.includes(this.variant)) {
9998
window.__swc.warn(
10099
this,
101100
`<${this.localName}> element expects the "variant" attribute to be one of the following:`,
102-
'https://opensource.adobe.com/spectrum-web-components/components/status-light/#variants',
101+
'https://opensource.adobe.com/spectrum-web-components/second-gen/?path=/docs/components-status-light--docs',
103102
{
104103
issues: [...constructor.VARIANTS],
105104
}
@@ -110,12 +109,13 @@ export abstract class StatusLightBase extends SizedMixin(SpectrumElement, {
110109
window.__swc.warn(
111110
this,
112111
`<${this.localName}> element does not support the disabled state.`,
113-
'https://opensource.adobe.com/spectrum-web-components/components/status-light/#states',
112+
'https://opensource.adobe.com/spectrum-web-components/second-gen/?path=/docs/components-status-light--docs',
114113
{
115114
issues: ['disabled is not a supported property in Spectrum 2'],
116115
}
117116
);
118117
}
119118
}
119+
super.update(changedProperties);
120120
}
121121
}

2nd-gen/packages/core/components/status-light/StatusLight.types.ts

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,45 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
/**
13+
/*
1414
* @todo The S1 types can be removed once we are no longer maintaining 1st-gen.
15-
* @todo Rename STATUSLIGHT_ prefix to STATUS_LIGHT_ to align with type prefix
16-
* naming convention (use underscore separators for multi-word names). This
17-
* requires updating all imports in 1st-gen and 2nd-gen that reference these
18-
* constants.
1915
*/
16+
2017
import type { ElementSize } from '@spectrum-web-components/core/mixins/index.js';
2118

22-
export const STATUSLIGHT_VALID_SIZES = [
19+
// ──────────────────
20+
// SHARED
21+
// ──────────────────
22+
23+
export const STATUS_LIGHT_VALID_SIZES = [
2324
's',
2425
'm',
2526
'l',
2627
'xl',
2728
] as const satisfies readonly ElementSize[];
2829

29-
export const STATUSLIGHT_VARIANTS_SEMANTIC = [
30+
export const STATUS_LIGHT_VARIANTS_SEMANTIC = [
3031
'neutral',
3132
'info',
3233
'positive',
3334
'negative',
3435
'notice',
3536
] as const;
3637

37-
export const STATUSLIGHT_VARIANTS_SEMANTIC_S1 = [
38-
...STATUSLIGHT_VARIANTS_SEMANTIC,
39-
'accent',
38+
export const STATUS_LIGHT_VARIANTS_SEMANTIC_S2 = [
39+
...STATUS_LIGHT_VARIANTS_SEMANTIC,
4040
] as const;
4141

42-
export const STATUSLIGHT_VARIANTS_SEMANTIC_S2 = [
43-
...STATUSLIGHT_VARIANTS_SEMANTIC,
42+
// ──────────────────────────────────────────
43+
// S1-ONLY (remove with 1st-gen)
44+
// ──────────────────────────────────────────
45+
46+
export const STATUS_LIGHT_VARIANTS_SEMANTIC_S1 = [
47+
...STATUS_LIGHT_VARIANTS_SEMANTIC,
48+
'accent',
4449
] as const;
4550

46-
export const STATUSLIGHT_VARIANTS_COLOR_S1 = [
51+
export const STATUS_LIGHT_VARIANTS_COLOR_S1 = [
4752
'fuchsia',
4853
'indigo',
4954
'magenta',
@@ -55,43 +60,54 @@ export const STATUSLIGHT_VARIANTS_COLOR_S1 = [
5560
'cyan',
5661
] as const;
5762

58-
export const STATUSLIGHT_VARIANTS_COLOR_S2 = [
59-
...STATUSLIGHT_VARIANTS_COLOR_S1,
63+
export const STATUS_LIGHT_VARIANTS_S1 = [
64+
...STATUS_LIGHT_VARIANTS_SEMANTIC_S1,
65+
...STATUS_LIGHT_VARIANTS_COLOR_S1,
66+
] as const;
67+
68+
// ──────────────────
69+
// CANONICAL
70+
// ──────────────────
71+
72+
export const STATUS_LIGHT_VARIANTS_COLOR_S2 = [
73+
...STATUS_LIGHT_VARIANTS_COLOR_S1,
6074
'pink',
6175
'turquoise',
6276
'brown',
6377
'cinnamon',
6478
'silver',
6579
] as const;
6680

67-
export const STATUSLIGHT_VARIANTS_S1 = [
68-
...STATUSLIGHT_VARIANTS_SEMANTIC_S1,
69-
...STATUSLIGHT_VARIANTS_COLOR_S1,
81+
export const STATUS_LIGHT_VARIANTS_S2 = [
82+
...STATUS_LIGHT_VARIANTS_SEMANTIC_S2,
83+
...STATUS_LIGHT_VARIANTS_COLOR_S2,
7084
] as const;
7185

72-
export const STATUSLIGHT_VARIANTS_S2 = [
73-
...STATUSLIGHT_VARIANTS_SEMANTIC_S2,
74-
...STATUSLIGHT_VARIANTS_COLOR_S2,
75-
] as const;
86+
// ──────────────────
87+
// TYPES
88+
// ──────────────────
7689

90+
// S1-only (remove with 1st-gen)
7791
export type StatusLightSemanticVariantS1 =
78-
(typeof STATUSLIGHT_VARIANTS_SEMANTIC_S1)[number];
92+
(typeof STATUS_LIGHT_VARIANTS_SEMANTIC_S1)[number];
93+
export type StatusLightColorVariantS1 =
94+
(typeof STATUS_LIGHT_VARIANTS_COLOR_S1)[number];
95+
export type StatusLightVariantS1 = (typeof STATUS_LIGHT_VARIANTS_S1)[number];
96+
97+
// Canonical (S2)
7998
export type StatusLightSemanticVariantS2 =
80-
(typeof STATUSLIGHT_VARIANTS_SEMANTIC_S2)[number];
99+
(typeof STATUS_LIGHT_VARIANTS_SEMANTIC_S2)[number];
100+
export type StatusLightColorVariantS2 =
101+
(typeof STATUS_LIGHT_VARIANTS_COLOR_S2)[number];
102+
export type StatusLightVariantS2 = (typeof STATUS_LIGHT_VARIANTS_S2)[number];
103+
104+
// Base class (S1 | S2)
81105
export type StatusLightSemanticVariant =
82106
| StatusLightSemanticVariantS1
83107
| StatusLightSemanticVariantS2;
84-
85-
export type StatusLightColorVariantS1 =
86-
(typeof STATUSLIGHT_VARIANTS_COLOR_S1)[number];
87-
export type StatusLightColorVariantS2 =
88-
(typeof STATUSLIGHT_VARIANTS_COLOR_S2)[number];
89108
export type StatusLightColorVariant =
90109
| StatusLightColorVariantS1
91110
| StatusLightColorVariantS2;
92-
93-
export type StatusLightVariantS1 = (typeof STATUSLIGHT_VARIANTS_S1)[number];
94-
export type StatusLightVariantS2 = (typeof STATUSLIGHT_VARIANTS_S2)[number];
95111
export type StatusLightVariant = StatusLightVariantS1 | StatusLightVariantS2;
96112

97-
export type StatusLightSize = (typeof STATUSLIGHT_VALID_SIZES)[number];
113+
export type StatusLightSize = (typeof STATUS_LIGHT_VALID_SIZES)[number];

2nd-gen/packages/swc/components/status-light/StatusLight.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { property } from 'lit/decorators.js';
1515
import { classMap } from 'lit/directives/class-map.js';
1616

1717
import {
18-
STATUSLIGHT_VARIANTS_COLOR_S2,
19-
STATUSLIGHT_VARIANTS_S2,
20-
STATUSLIGHT_VARIANTS_SEMANTIC_S2,
18+
STATUS_LIGHT_VARIANTS_COLOR_S2,
19+
STATUS_LIGHT_VARIANTS_S2,
20+
STATUS_LIGHT_VARIANTS_SEMANTIC_S2,
2121
StatusLightBase,
2222
type StatusLightVariantS2 as StatusLightVariant,
2323
} from '@spectrum-web-components/core/components/status-light';
@@ -31,6 +31,9 @@ import styles from './status-light.css';
3131
* @status preview
3232
* @since 0.0.1
3333
*
34+
* @property {string} variant - Semantic or non-semantic color variant for the status dot.
35+
* @attribute {ElementSize} size - The size of the status light.
36+
*
3437
* @example
3538
* <swc-status-light variant="positive">Approved</swc-status-light>
3639
*
@@ -45,17 +48,18 @@ export class StatusLight extends StatusLightBase {
4548
/**
4649
* @internal
4750
*/
48-
static override readonly VARIANTS_COLOR = STATUSLIGHT_VARIANTS_COLOR_S2;
51+
static override readonly VARIANTS_COLOR = STATUS_LIGHT_VARIANTS_COLOR_S2;
4952

5053
/**
5154
* @internal
5255
*/
53-
static override readonly VARIANTS_SEMANTIC = STATUSLIGHT_VARIANTS_SEMANTIC_S2;
56+
static override readonly VARIANTS_SEMANTIC =
57+
STATUS_LIGHT_VARIANTS_SEMANTIC_S2;
5458

5559
/**
5660
* @internal
5761
*/
58-
static override readonly VARIANTS = STATUSLIGHT_VARIANTS_S2;
62+
static override readonly VARIANTS = STATUS_LIGHT_VARIANTS_S2;
5963

6064
/**
6165
* Changes the color of the status dot. The variant list includes both semantic and non-semantic options.

2nd-gen/packages/swc/components/status-light/stories/status-light.stories.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import { getStorybookHelpers } from '@wc-toolkit/storybook-helpers';
1616

1717
import { StatusLight } from '@adobe/spectrum-wc/status-light';
1818
import {
19-
STATUSLIGHT_VALID_SIZES,
20-
STATUSLIGHT_VARIANTS_COLOR_S2,
21-
STATUSLIGHT_VARIANTS_SEMANTIC_S2,
19+
STATUS_LIGHT_VALID_SIZES,
20+
STATUS_LIGHT_VARIANTS_COLOR_S2,
21+
STATUS_LIGHT_VARIANTS_SEMANTIC_S2,
2222
StatusLightColorVariantS2,
2323
StatusLightSemanticVariantS2,
2424
type StatusLightSize,
@@ -190,7 +190,7 @@ export const Anatomy: Story = {
190190
*/
191191
export const Sizes: Story = {
192192
render: (args) => html`
193-
${STATUSLIGHT_VALID_SIZES.map((size) =>
193+
${STATUS_LIGHT_VALID_SIZES.map((size) =>
194194
template({
195195
...args,
196196
size,
@@ -215,7 +215,7 @@ export const Sizes: Story = {
215215
*/
216216
export const SemanticVariants: Story = {
217217
render: (args) => html`
218-
${STATUSLIGHT_VARIANTS_SEMANTIC_S2.map(
218+
${STATUS_LIGHT_VARIANTS_SEMANTIC_S2.map(
219219
(variant: StatusLightSemanticVariantS2) =>
220220
template({
221221
...args,
@@ -249,7 +249,7 @@ export const SemanticVariants: Story = {
249249
*/
250250
export const NonSemanticVariants: Story = {
251251
render: (args) => html`
252-
${STATUSLIGHT_VARIANTS_COLOR_S2.map((variant: StatusLightColorVariantS2) =>
252+
${STATUS_LIGHT_VARIANTS_COLOR_S2.map((variant: StatusLightColorVariantS2) =>
253253
template({
254254
...args,
255255
variant,

0 commit comments

Comments
 (0)