Skip to content

Commit

Permalink
fix: structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Apr 18, 2024
1 parent 0024b06 commit d37c484
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
21 changes: 9 additions & 12 deletions src/storybook/testing/chromatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import type {
import type { TemplateResult } from 'lit';
import { html } from 'lit';

import { withBackgroundDecorator } from './with-background-decorator.js';

import '../../components/title.js';

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -23,25 +21,24 @@ export function combineStories(config: Meta, stories: StoryParameter): StoryObj[
const decorators = (name: string, story: StoryObj): Decorator[] =>
(
[
(story) =>
(story, context) =>
html`<div style="margin-block-end: 2rem;">
<sbb-title
level="5"
style="margin-block-end: 1rem; margin-block-start: 0; text-transform: capitalize;"
>
${unCamelCase(name)} ${story()}
${unCamelCase(name)}
</sbb-title>
</div>`,
withBackgroundDecorator,
(story, context) => html`
<div style="outline: 1px solid #ad00ff;${
context.parameters.originalLayout !== 'fullscreen' ? 'padding: 2rem' : ''
}"
<div
style="outline: 1px solid #ad00ff;${context.parameters.originalLayout !== 'fullscreen'
? 'padding: 2rem;'
: ''}${context.parameters.backgroundColor
? `background-color:${context.parameters.backgroundColor(context)};`
: ''}"
>
${story()}
</div>
</div>
`,
</div> `,
] as Decorator[]
)
.concat(config.decorators || [])
Expand Down
18 changes: 8 additions & 10 deletions src/storybook/testing/with-background-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ export const withBackgroundDecorator = makeDecorator({

// For Chromatic we need to return html
if (context.name === 'Chromatic Stories') {
if (!backgroundColor) {
const isChromaticStoriesMain = !(
getStory(context) as { strings: string[] }
).strings[0].includes('outline');

if (!backgroundColor || isChromaticStoriesMain) {
return getStory(context);
} else {
const isChromaticStoriesMain = !(
getStory(context) as { strings: string[] }
).strings[0].includes('outline');

return !isChromaticStoriesMain
? html`<div style="background-color: ${backgroundColor(context)}">
${getStory(context)}
</div>`
: getStory(context);
return html`<div style="background-color: ${backgroundColor(context)}">
${getStory(context)}
</div>`;
}
} else {
// For standard case we manipulate the body
Expand Down

0 comments on commit d37c484

Please sign in to comment.