Skip to content

Commit

Permalink
feat(sbb-selection-expansion-panel): introduce size s (#3030)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideMininni-Fincons authored Sep 5, 2024
1 parent a9410ba commit a04b5b4
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 59 deletions.
5 changes: 5 additions & 0 deletions src/elements/core/mixins/panel-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
outline: none !important;
}

:host([size='s']) {
--sbb-selection-panel-input-padding: var(--sbb-spacing-responsive-xxs)
var(--sbb-spacing-responsive-xxxs);
}

:host([color='milk']) {
--sbb-selection-panel-background: var(
--sbb-selection-expansion-panel-inner-background,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const snapshots = {};

snapshots["sbb-selection-expansion-panel renders DOM"] =
`<sbb-selection-expansion-panel
data-size="m"
data-slot-names="content unnamed"
data-state="closed"
>
Expand Down
20 changes: 20 additions & 0 deletions src/elements/selection-expansion-panel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ It's also possible to display the `sbb-selection-expansion-panel` without border
<sbb-selection-expansion-panel borderless> ... </sbb-selection-expansion-panel>
```

The component has no `size` property but, when slotted in a `sbb-radio-button-group` or in a `sbb-checkbox-group`,
it adapts to the parent `size` (`m` or `s`); if there's no wrapping group component,
it adapts its `size` to the slotted `sbb-radio-button-panel` or in a `sbb-checkbox-panel`.

```html
<!-- Adapts to the size of the `sbb-checkbox-group`-->
<sbb-checkbox-group size="s">
<sbb-selection-expansion-panel>
<sbb-checkbox-panel> ... </sbb-checkbox-panel>
<div slot="content">Inner Content</div>
</sbb-selection-expansion-panel>
</sbb-checkbox-group>

<!-- Adapts to the size of the `sbb-checkbox-panel`-->
<sbb-selection-expansion-panel>
<sbb-checkbox-panel size="s"> ... </sbb-checkbox-panel>
<div slot="content">Inner Content</div>
</sbb-selection-expansion-panel>
```

<!-- Auto Generated Below -->

## Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ $open-anim-opacity-to: 1;
display: contents;
}

:host([data-size='s']) {
--sbb-selection-expansion-panel-content-padding-inline: var(--sbb-spacing-responsive-xxxs);
}

:host([color='milk']) {
--sbb-selection-expansion-panel-background: var(--sbb-color-milk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,96 @@ describe(`sbb-selection-expansion-panel`, () => {
expect(checkboxes[5]).not.to.have.attribute('disabled');
});
});

describe('size s', () => {
it('checkbox group', async () => {
const root = await fixture(html`
<sbb-checkbox-group size="s">
<sbb-selection-expansion-panel id="one">
<sbb-checkbox-panel> Value 1 </sbb-checkbox-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
<sbb-selection-expansion-panel id="two">
<sbb-checkbox-panel> Value 2 </sbb-checkbox-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
</sbb-checkbox-group>
`);
await waitForLitRender(root);
expect(
root.querySelector('sbb-selection-expansion-panel#one')!.getAttribute('data-size'),
).to.be.equal('s');
expect(
root.querySelector('sbb-selection-expansion-panel#two')!.getAttribute('data-size'),
).to.be.equal('s');
root.setAttribute('size', 'm');
await waitForLitRender(root);
expect(
root.querySelector('sbb-selection-expansion-panel#one')!.getAttribute('data-size'),
).to.be.equal('m');
expect(
root.querySelector('sbb-selection-expansion-panel#two')!.getAttribute('data-size'),
).to.be.equal('m');
});

it('checkbox panel', async () => {
const root = await fixture(html`
<sbb-selection-expansion-panel>
<sbb-checkbox-panel size="s"> Value </sbb-checkbox-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
`);
await waitForLitRender(root);
expect(root.getAttribute('data-size')).to.be.equal('s');
const panel = root.querySelector('sbb-checkbox-panel')!;
panel.setAttribute('size', 'm');
await waitForLitRender(root);
expect(root.getAttribute('data-size')).to.be.equal('m');
});

it('radio group', async () => {
const root = await fixture(html`
<sbb-radio-button-group size="s">
<sbb-selection-expansion-panel id="one">
<sbb-radio-button-panel> Value 1 </sbb-radio-button-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
<sbb-selection-expansion-panel id="two">
<sbb-radio-button-panel> Value 2 </sbb-radio-button-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
</sbb-radio-button-group>
`);
await waitForLitRender(root);
expect(
root.querySelector('sbb-selection-expansion-panel#one')!.getAttribute('data-size'),
).to.be.equal('s');
expect(
root.querySelector('sbb-selection-expansion-panel#two')!.getAttribute('data-size'),
).to.be.equal('s');
root.setAttribute('size', 'm');
await waitForLitRender(root);
expect(
root.querySelector('sbb-selection-expansion-panel#one')!.getAttribute('data-size'),
).to.be.equal('m');
expect(
root.querySelector('sbb-selection-expansion-panel#two')!.getAttribute('data-size'),
).to.be.equal('m');
});

it('radio panel', async () => {
const root = await fixture(html`
<sbb-selection-expansion-panel>
<sbb-radio-button-panel size="s"> Value </sbb-radio-button-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
`);
await waitForLitRender(root);
expect(root.getAttribute('data-size')).to.be.equal('s');
const panel = root.querySelector('sbb-radio-button-panel')!;
panel.setAttribute('size', 'm');
await waitForLitRender(root);
expect(root.getAttribute('data-size')).to.be.equal('m');
});
});
});
Loading

0 comments on commit a04b5b4

Please sign in to comment.