Skip to content

Commit

Permalink
feat: add color prop
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideMininni-Fincons committed Sep 27, 2023
1 parent 4c22e58 commit d16f13d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,10 @@ export namespace Components {
"titleLevel"?: InterfaceTitleAttributes['level'];
}
interface SbbLoadingIndicator {
/**
* Color variant.
*/
"color": InterfaceSbbLoadingIndicatorAttributes['color'];
/**
* Whether the animation is enabled.
*/
Expand Down Expand Up @@ -3810,6 +3814,10 @@ declare namespace LocalJSX {
"titleLevel"?: InterfaceTitleAttributes['level'];
}
interface SbbLoadingIndicator {
/**
* Color variant.
*/
"color"?: InterfaceSbbLoadingIndicatorAttributes['color'];
/**
* Whether the animation is enabled.
*/
Expand Down
11 changes: 6 additions & 5 deletions src/components/sbb-loading-indicator/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ and then append the `sbb-loading-indicator` on it after giving it the correct `a

## Properties

| Property | Attribute | Description | Type | Default |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------------- | ---------------------- | ----------- |
| `disableAnimation` | `disable-animation` | Whether the animation is enabled. | `boolean` | `false` |
| `size` | `size` | Size variant, either s or m. | `"l" \| "s"` | `'s'` |
| `variant` | `variant` | Variant of the loading indicator; `circle` is meant to be used inline, while `window` as overlay. | `"circle" \| "window"` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------------- | --------------------------------- | ----------- |
| `color` | `color` | Color variant. | `"default" \| "smoke" \| "white"` | `'default'` |
| `disableAnimation` | `disable-animation` | Whether the animation is enabled. | `boolean` | `false` |
| `size` | `size` | Size variant, either s or m. | `"l" \| "s"` | `'s'` |
| `variant` | `variant` | Variant of the loading indicator; `circle` is meant to be used inline, while `window` as overlay. | `"circle" \| "window"` | `undefined` |


----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface InterfaceSbbLoadingIndicatorAttributes {
variant: 'window' | 'circle';
size: 's' | 'l';
color: 'default' | 'smoke' | 'white';
}
92 changes: 90 additions & 2 deletions src/components/sbb-loading-indicator/sbb-loading-indicator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,61 @@ describe('sbb-loading-indicator', () => {
});

expect(root).toEqualHtml(`
<sbb-loading-indicator variant="window" size="m" role="progressbar" aria-busy='true'>
<sbb-loading-indicator variant="window" size="m" color="default" role="progressbar" aria-busy='true'>
<mock:shadow-root>
<span class="sbb-loading-indicator">
<span class="sbb-loading-indicator__animated-element">
<span>
<span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</span>
</span>
</span>
</span>
</mock:shadow-root>
</sbb-loading-indicator>
`);
});

it('renders with variant `window` and color smoke', async () => {
const { root } = await newSpecPage({
components: [SbbLoadingIndicator],
html: '<sbb-loading-indicator variant="window" size="m" color="smoke"/>',
});

expect(root).toEqualHtml(`
<sbb-loading-indicator variant="window" size="m" color="smoke" role="progressbar" aria-busy='true'>
<mock:shadow-root>
<span class="sbb-loading-indicator">
<span class="sbb-loading-indicator__animated-element">
<span>
<span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</span>
</span>
</span>
</span>
</mock:shadow-root>
</sbb-loading-indicator>
`);
});

it('renders with variant `window` and color white', async () => {
const { root } = await newSpecPage({
components: [SbbLoadingIndicator],
html: '<sbb-loading-indicator variant="window" size="m" color="white"/>',
});

expect(root).toEqualHtml(`
<sbb-loading-indicator variant="window" size="m" color="white" role="progressbar" aria-busy='true'>
<mock:shadow-root>
<span class="sbb-loading-indicator">
<span class="sbb-loading-indicator__animated-element">
Expand All @@ -36,7 +90,41 @@ describe('sbb-loading-indicator', () => {
});

expect(root).toEqualHtml(`
<sbb-loading-indicator variant="circle" size="s" role="progressbar" aria-busy="true">
<sbb-loading-indicator variant="circle" size="s" color="default" role="progressbar" aria-busy="true">
<mock:shadow-root>
<span class="sbb-loading-indicator">
<span class="sbb-loading-indicator__animated-element"></span>
</span>
</mock:shadow-root>
</sbb-loading-indicator>
`);
});

it('renders with variant `circle` and color smoke', async () => {
const { root } = await newSpecPage({
components: [SbbLoadingIndicator],
html: '<sbb-loading-indicator variant="circle" color="smoke"/>',
});

expect(root).toEqualHtml(`
<sbb-loading-indicator variant="circle" color="smoke" size="s" role="progressbar" aria-busy="true">
<mock:shadow-root>
<span class="sbb-loading-indicator">
<span class="sbb-loading-indicator__animated-element"></span>
</span>
</mock:shadow-root>
</sbb-loading-indicator>
`);
});

it('renders with variant `circle` and color white', async () => {
const { root } = await newSpecPage({
components: [SbbLoadingIndicator],
html: '<sbb-loading-indicator variant="circle" color="white"/>',
});

expect(root).toEqualHtml(`
<sbb-loading-indicator variant="circle" color="white" size="s" role="progressbar" aria-busy="true">
<mock:shadow-root>
<span class="sbb-loading-indicator">
<span class="sbb-loading-indicator__animated-element"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class SbbLoadingIndicator implements ComponentInterface {
/** Size variant, either s or m. */
@Prop({ reflect: true }) public size: InterfaceSbbLoadingIndicatorAttributes['size'] = 's';

/** Color variant. */
@Prop({ reflect: true }) public color: InterfaceSbbLoadingIndicatorAttributes['color'] =
'default';

/** Whether the animation is enabled. */
@Prop({ reflect: true }) public disableAnimation = false;

Expand Down

0 comments on commit d16f13d

Please sign in to comment.