Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sbb-container, sbb-sticky-bar): add new color variants #3337

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/elements/container/container/container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

:host {
--sbb-container-background-border-radius: 0;
--sbb-container-color: inherit;

display: block;
}
Expand All @@ -17,6 +18,20 @@
--sbb-container-background-color: var(--sbb-color-milk);
}

:host([color='midnight']),
:host([color='charcoal']) {
--sbb-focus-outline-color: var(--sbb-focus-outline-color-dark);
jeripeierSBB marked this conversation as resolved.
Show resolved Hide resolved
--sbb-container-color: var(--sbb-color-white);
}

:host([color='midnight']) {
--sbb-container-background-color: var(--sbb-color-midnight);
}

:host([color='charcoal']) {
--sbb-container-background-color: var(--sbb-color-charcoal);
}

:host([data-slot-names~='image']) {
--sbb-container-background-color: transparent;
--sbb-container-padding: var(--sbb-spacing-responsive-xxl);
Expand All @@ -37,6 +52,7 @@
}

.sbb-container {
color: var(--sbb-container-color);
background-color: var(--sbb-container-background-color);
padding: var(--sbb-container-padding);

Expand Down
55 changes: 46 additions & 9 deletions src/elements/container/container/container.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ import './container.js';

import readme from './readme.md?raw';

const containerContent = (title: string, last = false): TemplateResult => html`
<sbb-title level="4">${title}</sbb-title>
const containerContent = (title: string, isDark: boolean, last = false): TemplateResult => html`
<sbb-title level="4" ?negative=${isDark}>${title}</sbb-title>
<p class="sbb-text-s">The container component will give its content the correct spacing.</p>
<p class="sbb-text-s">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
${isDark
? html`
In <code>"midnight"</code> and <code>"charcoal"</code> variants the slotted text has
<code>"white"</code> color; however, you have to manually set the
<code>"negative"</code> property on sbb-components when needed.
`
: html`
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
`}
</p>
<sbb-secondary-button style=${last ? 'margin-block-end: 3rem;' : nothing}>
See more
Expand All @@ -44,7 +52,7 @@ const color: InputType = {
control: {
type: 'select',
},
options: ['white', 'transparent', 'milk'],
options: ['white', 'transparent', 'milk', 'midnight', 'charcoal'],
};

const expanded: InputType = {
Expand Down Expand Up @@ -79,10 +87,15 @@ const defaultArgs: Args = {
'image-src': undefined,
};

function isDark(colorArg: string): boolean {
return colorArg === 'midnight' || colorArg === 'charcoal';
}

const DefaultTemplate = (args: Args): TemplateResult => html`
<sbb-container ${sbbSpread(args)}>
${containerContent('Example title')} ${containerContent('Another one')}
${containerContent('And another one', true)}
${containerContent('Example title', isDark(args.color))}
${containerContent('Another one', isDark(args.color))}
${containerContent('And another one', isDark(args.color), true)}
</sbb-container>
`;

Expand Down Expand Up @@ -131,6 +144,18 @@ export const Milk: StoryObj = {
args: { ...defaultArgs, color: color.options![2] },
};

export const Midnight: StoryObj = {
render: DefaultTemplate,
argTypes: defaultArgTypes,
args: { ...defaultArgs, color: color.options![3] },
};

export const Charcoal: StoryObj = {
render: DefaultTemplate,
argTypes: defaultArgTypes,
args: { ...defaultArgs, color: color.options![4] },
};

export const BackgroundImage: StoryObj = {
render: BackgroundImageTemplate,
argTypes: defaultArgTypes,
Expand All @@ -152,6 +177,18 @@ export const MilkBackgroundExpanded: StoryObj = {
args: { ...defaultArgs, color: color.options![2], 'background-expanded': true },
};

export const MidnightBackgroundExpanded: StoryObj = {
render: DefaultTemplate,
argTypes: defaultArgTypes,
args: { ...defaultArgs, color: color.options![3], 'background-expanded': true },
};

export const CharcoalBackgroundExpanded: StoryObj = {
render: DefaultTemplate,
argTypes: defaultArgTypes,
args: { ...defaultArgs, color: color.options![4], 'background-expanded': true },
};

const meta: Meta = {
parameters: {
docs: {
Expand Down
7 changes: 6 additions & 1 deletion src/elements/container/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class SbbContainerElement extends LitElement {
public accessor backgroundExpanded: boolean = false;

/** Color of the container, like transparent, white etc. */
@property({ reflect: true }) public accessor color: 'transparent' | 'white' | 'milk' = 'white';
@property({ reflect: true }) public accessor color:
| 'transparent'
| 'white'
| 'milk'
| 'midnight'
| 'charcoal' = 'white';

protected override willUpdate(changedProperties: PropertyValues<this>): void {
super.willUpdate(changedProperties);
Expand Down
12 changes: 8 additions & 4 deletions src/elements/container/container/container.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import './container.js';
const imageUrl = import.meta.resolve('../../core/testing/assets/placeholder-image.png');
const imageBase64 = await loadAssetAsBase64(imageUrl);

function isDark(color: string): boolean {
return color === 'midnight' || color === 'charcoal';
}

describe(`sbb-container`, () => {
const colorCases = ['transparent', 'white', 'milk'];
const colorCases = ['transparent', 'white', 'milk', 'midnight', 'charcoal'];
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved

const backgroundExpandedCases = [false, true];

Expand Down Expand Up @@ -57,8 +61,8 @@ describe(`sbb-container`, () => {
},
];

const containerContent = (): TemplateResult => html`
<sbb-title level="4">Example title</sbb-title>
const containerContent = (color?: string): TemplateResult => html`
<sbb-title level="4" ?negative=${!!color && isDark(color)}>Example title</sbb-title>
<p class="sbb-text-s">The container component will give its content the correct spacing.</p>
<p class="sbb-text-s">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
Expand All @@ -85,7 +89,7 @@ describe(`sbb-container`, () => {
`color=${color}`,
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`<sbb-container color=${color}>${containerContent()}</sbb-container>`,
html`<sbb-container color=${color}>${containerContent(color)}</sbb-container>`,
wrapperStyles,
);
}),
Expand Down
23 changes: 16 additions & 7 deletions src/elements/container/container/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,32 @@ Optionally, you can add an overlapping `sbb-chip-label` by wrapping the `sbb-ima

## Style

By default `sbb-container` uses the `page spacing` defined in the [layout documentation](/docs/styles-layout--docs). Optionally the user can use the `expanded` property (default: `false`) to switch to the `page spacing expanded` layout.
By default `sbb-container` uses the `page spacing` defined in the [layout documentation](/docs/styles-layout--docs).
Optionally the user can use the `expanded` property (default: `false`) to switch to the `page spacing expanded` layout.
Spacing options are applied to all the container's content, including the `sbb-sticky-bar`.
The component has also four color variants that can be set using the `color` property (default: `white`).

The component has also five color variants that can be set using the `color` property (default: `white`).
In `midnight` and `charcoal` variants, the slotted content text color and the focus outline color change to white,
but it's up to the consumer to correctly set the `negative` property on slotted Lyne components, if needed.

```html
<sbb-container expanded variant="milk"> ... </sbb-container>

<sbb-container variant="midnight">
<sbb-title negative>Title</sbb-title>
<p>Text</p>
</sbb-container>
```

<!-- Auto Generated Below -->

## Properties

| Name | Attribute | Privacy | Type | Default | Description |
| -------------------- | --------------------- | ------- | ------------------------------------ | --------- | ------------------------------------------------------------------------------- |
| `backgroundExpanded` | `background-expanded` | public | `boolean` | `false` | Whether the background color is shown on full container width on large screens. |
| `color` | `color` | public | `'transparent' \| 'white' \| 'milk'` | `'white'` | Color of the container, like transparent, white etc. |
| `expanded` | `expanded` | public | `boolean` | `false` | Whether the container is expanded. |
| Name | Attribute | Privacy | Type | Default | Description |
| -------------------- | --------------------- | ------- | ---------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------- |
| `backgroundExpanded` | `background-expanded` | public | `boolean` | `false` | Whether the background color is shown on full container width on large screens. |
| `color` | `color` | public | `'transparent' \| 'white' \| 'milk' \| 'midnight' \| 'charcoal'` | `'white'` | Color of the container, like transparent, white etc. |
| `expanded` | `expanded` | public | `boolean` | `false` | Whether the container is expanded. |

## Slots

Expand Down
9 changes: 5 additions & 4 deletions src/elements/container/sticky-bar/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ The `sbb-sticky-bar` content is provided via an unnamed slot.
## Style

The `sbb-sticky-bar` inherits its variant from the `sbb-container` it's placed in.
Optionally the user can set the `color` property on the `sbb-sticky-bar` in order to override the one inherited by the `sbb-container`. The color is only applied when the sticky bar is sticking, and will become transparent once it settles on the bottom of the container.
Optionally the user can set the `color` property on the `sbb-sticky-bar` in order to override the one inherited by the `sbb-container`.
The color is only applied when the sticky bar is sticking, and will become transparent once it settles on the bottom of the container.

<!-- Auto Generated Below -->

## Properties

| Name | Attribute | Privacy | Type | Default | Description |
| ------- | --------- | ------- | --------------------------- | ------- | ---------------------------------------------------- |
| `color` | `color` | public | `'white' \| 'milk' \| null` | `null` | Color of the container, like transparent, white etc. |
| Name | Attribute | Privacy | Type | Default | Description |
| ------- | --------- | ------- | ------------------------------------------------------- | ------- | ---------------------------------------------------- |
| `color` | `color` | public | `'white' \| 'milk' \| 'midnight' \| 'charcoal' \| null` | `null` | Color of the container, like transparent, white etc. |

## Methods

Expand Down
8 changes: 8 additions & 0 deletions src/elements/container/sticky-bar/sticky-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ $intersector-overlapping: 1px;
--sbb-sticky-bar-sticky-background-color: var(--sbb-color-milk);
}

:host([data-sticking]:not([data-state='unsticky'])[color='midnight']) {
DavideMininni-Fincons marked this conversation as resolved.
Show resolved Hide resolved
--sbb-sticky-bar-sticky-background-color: var(--sbb-color-midnight);
}

:host([data-sticking]:not([data-state='unsticky'])[color='charcoal']) {
--sbb-sticky-bar-sticky-background-color: var(--sbb-color-charcoal);
}

:host(
:is(
[data-sticking]:is([data-slide-vertically], [data-state='sticking'], [data-state='unsticking']),
Expand Down
Loading
Loading