Skip to content

Commit 0f9feba

Browse files
authored
chore: fix storybook dev mode warning (#5896)
1 parent 50ad026 commit 0f9feba

File tree

6 files changed

+55
-32
lines changed

6 files changed

+55
-32
lines changed

1st-gen/packages/action-menu/src/ActionMenu.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,21 @@ export class ActionMenu extends ObserveSlotPresence(
148148
}
149149

150150
protected override warnNoLabel(): void {
151-
window.__swc.warn(
152-
this,
153-
`<${this.localName}> needs one of the following to be accessible:`,
154-
'https://opensource.adobe.com/spectrum-web-components/components/action-menu/#accessibility',
155-
{
156-
type: 'accessibility',
157-
issues: [
158-
`an <sp-field-label> element with a \`for\` attribute referencing the \`id\` of the \`<${this.localName}>\`, or`,
159-
'value supplied to the "label" attribute, which will be displayed visually as placeholder text',
160-
'text content supplied in a <span> with slot="label", or, text content supplied in a <span> with slot="label-only"',
161-
'which will also be displayed visually as placeholder text.',
162-
],
163-
}
164-
);
151+
if (window.__swc?.DEBUG) {
152+
window.__swc.warn(
153+
this,
154+
`<${this.localName}> needs one of the following to be accessible:`,
155+
'https://opensource.adobe.com/spectrum-web-components/components/action-menu/#accessibility',
156+
{
157+
type: 'accessibility',
158+
issues: [
159+
`an <sp-field-label> element with a \`for\` attribute referencing the \`id\` of the \`<${this.localName}>\`, or`,
160+
'value supplied to the "label" attribute, which will be displayed visually as placeholder text',
161+
'text content supplied in a <span> with slot="label", or, text content supplied in a <span> with slot="label-only"',
162+
'which will also be displayed visually as placeholder text.',
163+
],
164+
}
165+
);
166+
}
165167
}
166168
}

1st-gen/packages/overlay/src/slottable-request-directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class SlottableRequestDirective extends AsyncDirective {
7474
{ signal }
7575
);
7676

77-
if (window.__swc.DEBUG) {
77+
if (window.__swc?.DEBUG) {
7878
window.__swc.warn(
7979
undefined,
8080
`⚠️ WARNING ⚠️ : The Overlay Trigger Directive is experimental and there is no guarantees behind its usage in an application!! Its API and presence within the library could be changed at anytime. See "sp-overlay" or "Overlay.open()" for a stable API for overlaying content on your application.`,

1st-gen/packages/overlay/src/slottable-request-event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class SlottableRequestEvent extends Event {
2323
this.name = name;
2424
this.data = data;
2525
this.slotName = key !== undefined ? `${name}.${key}` : name;
26-
if (window.__swc.DEBUG) {
26+
if (window.__swc?.DEBUG) {
2727
window.__swc.warn(
2828
undefined,
2929
`⚠️ WARNING ⚠️ : \`slottable-request\` events are experimental and there is no guarantees behind usage of them in an application!! Their shape and presence within the library could be changed at anytime.

1st-gen/packages/picker/src/Picker.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -556,19 +556,21 @@ export class PickerBase extends SizedMixin(SpectrumElement, {
556556
}
557557

558558
protected warnNoLabel(): void {
559-
window.__swc.warn(
560-
this,
561-
`<${this.localName}> needs one of the following to be accessible:`,
562-
'https://opensource.adobe.com/spectrum-web-components/components/picker/#accessibility',
563-
{
564-
type: 'accessibility',
565-
issues: [
566-
`an <sp-field-label> element with a \`for\` attribute referencing the \`id\` of the \`<${this.localName}>\`, or`,
567-
'value supplied to the "label" attribute, which will be displayed visually as placeholder text, or',
568-
'text content supplied in a <span> with slot="label", which will also be displayed visually as placeholder text.',
569-
],
570-
}
571-
);
559+
if (window.__swc?.DEBUG) {
560+
window.__swc.warn(
561+
this,
562+
`<${this.localName}> needs one of the following to be accessible:`,
563+
'https://opensource.adobe.com/spectrum-web-components/components/picker/#accessibility',
564+
{
565+
type: 'accessibility',
566+
issues: [
567+
`an <sp-field-label> element with a \`for\` attribute referencing the \`id\` of the \`<${this.localName}>\`, or`,
568+
'value supplied to the "label" attribute, which will be displayed visually as placeholder text, or',
569+
'text content supplied in a <span> with slot="label", which will also be displayed visually as placeholder text.',
570+
],
571+
}
572+
);
573+
}
572574
}
573575

574576
protected renderOverlay(menu: TemplateResult): TemplateResult {
@@ -1000,7 +1002,7 @@ export class Picker extends PickerBase {
10001002
);
10011003
if (!this.value || nextItem !== this.selectedItem) {
10021004
// updates picker text but does not fire change event until action is completed
1003-
if (!!nextItem) this.setValueFromItem(nextItem as MenuItem);
1005+
if (nextItem) this.setValueFromItem(nextItem as MenuItem);
10041006
}
10051007
};
10061008
}

1st-gen/packages/slider/src/Slider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131

3232
import sliderStyles from './slider.css.js';
3333
import { ObserveSlotText } from '@spectrum-web-components/shared/src/observe-slot-text.js';
34-
import { StyleInfo } from 'lit/directives/style-map.js';
34+
import type { StyleInfo } from '@spectrum-web-components/base/src/directives.js';
3535
import '@spectrum-web-components/field-label/sp-field-label.js';
3636
import type { NumberField } from '@spectrum-web-components/number-field';
3737
import { HandleController, HandleValueDictionary } from './HandleController.js';
@@ -232,7 +232,7 @@ export class Slider extends SizedMixin(ObserveSlotText(SliderHandle, ''), {
232232
this.handleController.hostConnected();
233233

234234
// Deprecation warning for default slot when content is provided
235-
if (window.__swc.DEBUG && this.textContent?.trim()) {
235+
if (window.__swc?.DEBUG && this.textContent?.trim()) {
236236
window.__swc.warn(
237237
this,
238238
`The default slot for text label in <${this.localName}> has been deprecated and will be removed in a future release. Use the "label" property instead.`,

1st-gen/storybook/preview.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ import { Locales } from '@spectrum-web-components/story-decorator/src/locales.js
1616
import DocumentationTemplate from './DocumentationTemplate.mdx';
1717
import '@spectrum-web-components/story-decorator/sp-story-decorator.js';
1818

19+
/**
20+
* Ensure that window.__swc is defined in the storybook runtime.
21+
*
22+
* This prevents debug-only calls like `window.__swc.warn(...)` from throwing
23+
* when the debug flag is inlined to `true` by the dev build configuration.
24+
*/
25+
if (typeof window !== 'undefined') {
26+
window.__swc = window.__swc || {};
27+
if (typeof window.__swc.DEBUG === 'undefined') {
28+
window.__swc.DEBUG = true;
29+
}
30+
if (typeof window.__swc.warn !== 'function') {
31+
window.__swc.warn = (...args) => {
32+
// Forward warnings to the console for visibility in storybook.
33+
console.warn('[SWC]', ...args);
34+
};
35+
}
36+
}
37+
1938
// const cem = await import('./custom-elements.json', {
2039
// assert: { type: 'json' },
2140
// });

0 commit comments

Comments
 (0)