-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sbb-badge): draft implementation
- Loading branch information
1 parent
4c222ce
commit 3c50852
Showing
9 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './badge/badge.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters