Skip to content

Commit

Permalink
fix(alert): adds main slot margin when heading/text is present (VIV-1871
Browse files Browse the repository at this point in the history
) (#1851)

* fix: adds margin to main slot with heading / main text

* chore: fixes stylelint errors

* chore: formatting

* chore: styelint fix

---------

Co-authored-by: James Taylor <jstaylor@vonht2fg32k90.home>
  • Loading branch information
TaylorJ76 and James Taylor authored Jul 17, 2024
1 parent edf18f8 commit 1f7cdaa
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 12 deletions.
21 changes: 12 additions & 9 deletions libs/components/src/lib/alert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Use the `text` attribute to set the alert's main text.
- Default: `undefined`

```html preview 100px
<vwc-alert text="An important information for you" open></vwc-alert>
<vwc-alert text="Some important information for you" open></vwc-alert>
```

### Headline
Expand All @@ -29,7 +29,7 @@ Use the `headline` attribute to add a headline to your alert.
```html preview 100px
<vwc-alert
headline="This requires your attention"
text="An important information for you"
text="Some important information for you"
open
></vwc-alert>
```
Expand All @@ -42,7 +42,7 @@ Use the `open` attribute to toggle the alert open state.
- Default: `false`

```html preview
<vwc-alert text="An important information for you"></vwc-alert>
<vwc-alert text="Some important information for you"></vwc-alert>

<vwc-button
appearance="outlined"
Expand Down Expand Up @@ -74,7 +74,7 @@ Note that each connotation comes with a default icon (that you can override with
}
</style>
<vwc-alert
text="An important information for you"
text="Some important information for you"
connotation="accent"
open
></vwc-alert>
Expand Down Expand Up @@ -107,7 +107,7 @@ over the connotation's icon, if any.

```html preview 100px
<vwc-alert
text="An important information for you"
text="Some important information for you"
open
icon="megaphone-solid"
></vwc-alert>
Expand Down Expand Up @@ -184,7 +184,7 @@ Use the `removable` attribute to add a close button to the alert.
- Default: `false`

```html preview 100px
<vwc-alert text="An important information for you" removable open></vwc-alert>
<vwc-alert text="Some important information for you" removable open></vwc-alert>

<vwc-button
appearance="outlined"
Expand All @@ -208,7 +208,10 @@ Use the `timeoutms` attribute to set the time after which the alert will automat
- Default: `0` (stays open indefinitely)

```html preview
<vwc-alert text="An important information for you" timeoutms="2000"></vwc-alert>
<vwc-alert
text="Some important information for you"
timeoutms="2000"
></vwc-alert>

<vwc-button
appearance="outlined"
Expand Down Expand Up @@ -241,7 +244,7 @@ If you want to add rich content to your alert, you can use the main slot.
You can add action items elements using the `action-items` slot. They will be displayed at the inline-end of the alert.

```html preview 100px
<vwc-alert text="An important information for you" open>
<vwc-alert text="Some important information for you" open>
<vwc-button
slot="action-items"
appearance="outlined"
Expand All @@ -257,7 +260,7 @@ Set the `icon` slot to add an icon to the alert.
If set, the `icon` attribute is ignored.

```html preview 100px
<vwc-alert text="An important information for you" open>
<vwc-alert text="Some important information for you" open>
<vwc-icon slot="icon" name="megaphone-solid" connotation="cta"></vwc-icon>
</vwc-alert>
```
Expand Down
7 changes: 7 additions & 0 deletions libs/components/src/lib/alert/alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ $alert-transition-delay: --transition-delay;
.main-text {
font: var(#{constants.$vvd-typography-base});
}

.headline + ::slotted([slot='main'i]:first-child)::before,
.main-text + ::slotted([slot='main'i]:first-child)::before {
display: block;
margin-top: 8px;
content: '';
}
}

slot[name='icon'] {
Expand Down
3 changes: 1 addition & 2 deletions libs/components/src/lib/alert/alert.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export const AlertTemplate: (
html`<header class="headline">${(x) => x.headline}</header>`
)}
${when((x) => x.text, html`<div class="main-text">${(x) => x.text}</div>`)}
<slot name="main">
</slot>
<slot name="main"></slot>
</div>
<slot class="action-items" name="action-items"></slot>
${when((x) => x.removable, renderDismissButton(buttonTag))}
Expand Down
35 changes: 34 additions & 1 deletion libs/components/src/lib/alert/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('should show the component', async ({ page }: { page: Page }) => {
async function testResponsiveAlert({ page }: { page: Page }) {
const template = `
<div style="margin: 5px; height: 250px; transform: translateY(0px);">
<vwc-alert text="An important information for you" removable open></vwc-alert>
<vwc-alert text="Some important information for you" removable open></vwc-alert>
</div>
`;

Expand Down Expand Up @@ -105,3 +105,36 @@ async function testConnotationAlert({ page }: { page: Page }) {
);
}
test('alert in connotation', testConnotationAlert);

async function testMainSlotAlert({ page }: { page: Page }) {
const template = `
<div style="margin: 5px; height: 250px; transform: translateY(0px);">
<vwc-alert headline="This requires your attention" open placement="top">
<vwc-switch slot="main" label="Do not show more alerts"></vwc-switch>
</vwc-alert>
<vwc-alert headline="This requires your attention" text="Some important information for you" open placement="bottom">
<vwc-switch slot="main" label="Do not show more alerts"></vwc-switch>
</vwc-alert>
</div>
`;

await page.setViewportSize({ width: 560, height: 500 });

await loadComponents({
page,
components,
});
await loadTemplate({
page,
template,
});

const testWrapper = await page.$('#wrapper');

await page.waitForLoadState('networkidle');

expect(await testWrapper?.screenshot()).toMatchSnapshot(
'./snapshots/alert-main-slot.png'
);
}
test('alert with main slot content', testMainSlotAlert);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f7cdaa

Please sign in to comment.