|
| 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 | +}); |
0 commit comments