Skip to content

Commit

Permalink
feat(sbb-badge): draft implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed May 7, 2024
1 parent 4c222ce commit 3c50852
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/badge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './badge/badge.js';
21 changes: 21 additions & 0 deletions src/components/badge/__snapshots__/badge.spec.snap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["sbb-badge should render with default values"] =
`<slot>
</slot>
<div class="sbb-badge">
</div>
`;
/* end snapshot sbb-badge should render with default values */

snapshots["sbb-badge A11y tree Chrome"] =
`<p>
{
"role": "WebArea",
"name": ""
}
</p>
`;
/* end snapshot sbb-badge A11y tree Chrome */

17 changes: 17 additions & 0 deletions src/components/badge/badge.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@use '../core/styles' as sbb;

// Box-sizing rules contained in typography are not traversing Shadow DOM boundaries. We need to include box-sizing mixin in every component.
@include sbb.box-sizing;

:host {
position: relative;
display: inline-flex;
}

.sbb-badge {
position: absolute;
inset-block-start: #{sbb.px-to-rem-build(-2)};
inset-inline-end: #{sbb.px-to-rem-build(-2)};

@include sbb.badge;
}
18 changes: 18 additions & 0 deletions src/components/badge/badge.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../core/testing/private.js';

import type { SbbBadgeElement } from './badge.js';

import './badge.js';

describe(`sbb-badge`, () => {
it('should render with default values', async () => {
const element: SbbBadgeElement = await fixture(html`<sbb-badge></sbb-badge>`);

await expect(element).shadowDom.to.equalSnapshot();
});

testA11yTreeSnapshot(html`<sbb-badge></sbb-badge>`);
});
26 changes: 26 additions & 0 deletions src/components/badge/badge.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Meta, StoryObj } from '@storybook/web-components';
import type { TemplateResult } from 'lit';
import { html } from 'lit';

import readme from './readme.md?raw';
import './badge.js';
import '../icon.js';

const Template = (): TemplateResult => html`
<sbb-badge label="2"><sbb-icon name="arrow-right-small"></sbb-icon></sbb-badge>
`;

export const Badge: StoryObj = {
render: Template,
};

const meta: Meta = {
parameters: {
docs: {
extractComponentDescription: () => readme,
},
},
title: 'components/sbb-badge',
};

export default meta;
29 changes: 29 additions & 0 deletions src/components/badge/badge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { CSSResultGroup, TemplateResult } from 'lit';
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';

import { SbbNegativeMixin } from '../core/mixins.js';

import style from './badge.scss?lit&inline';

/**
* It displays a badge.
*/
@customElement('sbb-badge')
export class SbbBadgeElement extends SbbNegativeMixin(LitElement) {
public static override styles: CSSResultGroup = style;

@property() public label?: string;

protected override render(): TemplateResult {
return html`<slot></slot>
<div class="sbb-badge">${this.label}</div> `;
}
}

declare global {
interface HTMLElementTagNameMap {
// eslint-disable-next-line @typescript-eslint/naming-convention
'sbb-badge': SbbBadgeElement;
}
}
10 changes: 10 additions & 0 deletions src/components/badge/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The `sbb-badge` is used to display amount information.

<!-- Auto Generated Below -->

## Properties

| Name | Attribute | Privacy | Type | Default | Description |
| ------------- | ---------- | ------- | ---------------- | -------------- | --------------------------------------------------------------------------------------------- |
| `orientation` | - | public | `SbbOrientation` | `'horizontal'` | Orientation property with possible values 'horizontal' \| 'vertical'. Defaults to horizontal. |
| `negative` | `negative` | public | `boolean` | `false` | Negative coloring variant flag. |
3 changes: 2 additions & 1 deletion src/components/core/styles/mixins/badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
border-radius: var(--sbb-border-radius-infinity);
background-color: var(--sbb-color-red);
color: var(--sbb-color-white);
min-width: fit-content;
min-width: var(--sbb-spacing-fixed-4x);
max-height: var(--sbb-spacing-fixed-4x);
}
1 change: 0 additions & 1 deletion src/components/menu/common/menu-action.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

margin-inline-start: auto;
width: var(--sbb-spacing-fixed-4x);
max-height: var(--sbb-spacing-fixed-4x);

@include sbb.if-forced-colors {
color: var(--sbb-menu-action-color);
Expand Down

0 comments on commit 3c50852

Please sign in to comment.