Skip to content

Commit 1ebf8c9

Browse files
feat: add static color background decorator
1 parent 5125328 commit 1ebf8c9

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import { html } from 'lit';
14+
import { makeDecorator } from '@storybook/preview-api';
15+
import type { DecoratorFunction } from '@storybook/types';
16+
17+
/**
18+
* Static color background settings - matching spectrum-css gradients
19+
*/
20+
const staticColorSettings = {
21+
black: 'linear-gradient(45deg, rgb(255 241 246), rgb(238 245 255))',
22+
white: 'linear-gradient(45deg, rgb(64 0 22), rgb(14 24 67))',
23+
} as const;
24+
25+
/**
26+
* Decorator that applies background colors based on static-color arg.
27+
* Wraps the story in a div with the appropriate background when static-color is set.
28+
*/
29+
export const withStaticColorBackground: DecoratorFunction = makeDecorator({
30+
name: 'withStaticColorBackground',
31+
parameterName: 'staticColorBackground',
32+
wrapper: (StoryFn, context) => {
33+
const { args } = context;
34+
const staticColor = args?.[
35+
'static-color'
36+
] as keyof typeof staticColorSettings;
37+
38+
const background =
39+
staticColor && staticColorSettings[staticColor]
40+
? staticColorSettings[staticColor]
41+
: '';
42+
43+
// If no static color is set, just return the story as-is
44+
if (!background) {
45+
return StoryFn(context);
46+
}
47+
48+
// Wrap the story with the background
49+
return html`
50+
<div style="background: ${background}; padding: 24px;">
51+
${StoryFn(context)}
52+
</div>
53+
`;
54+
},
55+
});

second-gen/packages/swc/.storybook/preview.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type Options,
1111
} from '@wc-toolkit/storybook-helpers';
1212
import customElements from './custom-elements.json';
13+
import { withStaticColorBackground } from './decorators/static-color-background';
1314

1415
const options: Options = {
1516
categoryOrder: [
@@ -31,6 +32,7 @@ setStorybookHelpersConfig(options);
3132
setCustomElementsManifest(customElements);
3233

3334
const preview = {
35+
decorators: [withStaticColorBackground],
3436
parameters: {
3537
layout: 'centered',
3638
controls: {

0 commit comments

Comments
 (0)