-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(segmeted-control): new component (#1460)
* feat(segment): add new component * chore(): fix focus * chore(): add docs and first tests * chore(): fix a11y issues * update base images * chore(): add changesets * Revert "chore(): add changesets" This reverts commit 37f7803. * chore: add changeset * chore: format files * chore: fix invalid style * chore: fix spelling * chore: fix spelling * update base images --------- Co-authored-by: hirsch88 <hirsch88@users.noreply.github.com>
- Loading branch information
Showing
50 changed files
with
1,866 additions
and
29 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,5 @@ | ||
--- | ||
'@baloise/ds-core': minor | ||
--- | ||
|
||
**segment**: new component |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Canvas, Meta, Markdown } from '@storybook/blocks' | ||
import { Banner, Lead, PlaygroundBar, StoryHeading, Footer } from '../../../.storybook/blocks' | ||
import * as SegmentStories from './bal-segment.stories' | ||
|
||
<Meta of={SegmentStories} /> | ||
|
||
<StoryHeading of={SegmentStories.Basic} hidden></StoryHeading> | ||
|
||
<Banner of={SegmentStories} /> | ||
|
||
<Lead> | ||
**Segment** offers a list of options. The user can only select one option from a number of choices. It automatically | ||
detects if it has enough space and changes to Vertical. | ||
</Lead> | ||
|
||
<Canvas of={SegmentStories.Basic} sourceState="shown" /> | ||
|
||
<PlaygroundBar of={SegmentStories.Basic}></PlaygroundBar> | ||
|
||
{/* STORIES */} | ||
{/* ------------------------------------------------------ */} | ||
|
||
<StoryHeading of={SegmentStories.Vertical}></StoryHeading> | ||
|
||
The segment items can be displayed as a list just set `vertical`. | ||
|
||
<Canvas of={SegmentStories.Vertical} sourceState="shown" /> | ||
|
||
{/* ------------------------------------------------------ */} | ||
|
||
<StoryHeading of={SegmentStories.Expanded}></StoryHeading> | ||
|
||
Set `expanded` to stretch the component over the full width. | ||
|
||
<Canvas of={SegmentStories.Expanded} sourceState="shown" /> | ||
|
||
{/* ------------------------------------------------------ */} | ||
|
||
## Component API | ||
|
||
import api from './api.md?raw' | ||
import apiItem from './bal-segment-item/api.md?raw' | ||
|
||
<Markdown>{api}</Markdown> | ||
|
||
<Markdown>{apiItem}</Markdown> | ||
|
||
## Integration | ||
|
||
import integration from '../../snippets/integration.md?raw' | ||
|
||
<Markdown>{integration}</Markdown> | ||
|
||
import theming from './theming.md?raw' | ||
|
||
<Markdown>{theming}</Markdown> | ||
|
||
import testing from './testing.md?raw' | ||
|
||
<Markdown>{testing}</Markdown> | ||
|
||
<Footer /> |
53 changes: 53 additions & 0 deletions
53
docs/stories/components/bal-segment/bal-segment.stories.ts
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,53 @@ | ||
import type { JSX } from '@baloise/ds-core' | ||
import type { Meta } from '@storybook/html' | ||
import { props, withRender, withComponentControls, StoryFactory } from '../../utils' | ||
|
||
type Args = JSX.BalSegment | ||
|
||
const meta: Meta<Args> = { | ||
title: 'Components/Form/Segment', | ||
args: { | ||
value: 'yes', | ||
}, | ||
argTypes: { | ||
...withComponentControls({ tag: 'bal-segment' }), | ||
}, | ||
...withRender( | ||
({ ...args }) => `<bal-segment ${props(args)}> | ||
<bal-segment-item value="yes" label="Yes"></bal-segment-item> | ||
<bal-segment-item value="no" label="No"></bal-segment-item> | ||
</bal-segment>`, | ||
), | ||
} | ||
|
||
export default meta | ||
|
||
/** | ||
* STORIES | ||
* ------------------------------------------------------ | ||
*/ | ||
|
||
const Story = StoryFactory<Args>(meta) | ||
|
||
export const Basic = Story() | ||
|
||
export const Vertical = Story({ | ||
...withRender( | ||
() => ` | ||
<bal-segment vertical value="10000"> | ||
<bal-segment-item value="7000" label="max. 7’000 km">entspricht rund 186 km pro Woche</bal-segment-item> | ||
<bal-segment-item value="10000" label="max. 10’000 km">entspricht rund 186 km pro Woche</bal-segment-item> | ||
<bal-segment-item value="15000" label="max. 15’000 km">entspricht rund 186 km pro Woche</bal-segment-item> | ||
<bal-segment-item value="20000" label="max. 20’000 km">entspricht rund 186 km pro Woche</bal-segment-item> | ||
<bal-segment-item value="21000" label="mehr als 20’000 km" | ||
>entspricht rund 186 km pro Woche</bal-segment-item | ||
> | ||
</bal-segment>`, | ||
), | ||
}) | ||
|
||
export const Expanded = Story({ | ||
args: { | ||
expanded: true, | ||
}, | ||
}) |
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,12 @@ | ||
## Testing | ||
|
||
The Baloise Design System provides a collection of custom cypress commands for the components. Moreover, some basic cypress commands like `should` or `click` have been overridden to work with the components. | ||
|
||
<a class="sb-unstyled button is-primary" href="../?path=/docs/development-testing--documentation">Go to testing guide</a> | ||
|
||
<!-- START: human documentation --> | ||
|
||
|
||
|
||
<!-- END: human documentation --> | ||
|
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,34 @@ | ||
## Theming | ||
|
||
The component can be customization by changing the CSS variables. | ||
|
||
<a class="sb-unstyled button is-primary" href="../?path=/docs/development-theming--page">Go to theming guide</a> | ||
|
||
<!-- START: human documentation --> | ||
|
||
|
||
|
||
<!-- END: human documentation --> | ||
|
||
### Variables | ||
|
||
| Variable | | ||
| -------------------------------------------------- | | ||
| `--bal-badge-background` | | ||
| `--bal-segment-background` | | ||
| `--bal-segment-background-invalid` | | ||
| `--bal-segment-item-focus-border` | | ||
| `--bal-segment-item-text-color` | | ||
| `--bal-segment-item-text-color-checked` | | ||
| `--bal-segment-item-text-color-checked-hovered` | | ||
| `--bal-segment-item-text-color-checked-pressed` | | ||
| `--bal-segment-item-text-color-invalid` | | ||
| `--bal-segment-item-text-color-invalid-hovered` | | ||
| `--bal-segment-item-text-color-invalid-pressed` | | ||
| `--bal-segment-item-text-color-disabled` | | ||
| `--bal-segment-item-text-color-disabled-checked` | | ||
| `--bal-segment-item-divider-background` | | ||
| `--bal-segment-item-divider-background-invalid` | | ||
| `--bal-segment-item-indicator-background` | | ||
| `--bal-segment-item-indicator-background-invalid` | | ||
| `--bal-segment-item-indicator-background-disabled` | |
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,46 @@ | ||
import { Components } from '../support/utils' | ||
|
||
describe('bal-segment', () => { | ||
it('should fire change event', () => { | ||
const onBalChangeSpy = cy.spy().as('balChange') | ||
|
||
cy.mount<Components.BalSegment, HTMLBalSegmentElementEventMap>( | ||
`<bal-segment> | ||
<bal-segment-item value="yes" label="Yes"></bal-segment-item> | ||
<bal-segment-item value="no" label="No"></bal-segment-item> | ||
</bal-segment>`, | ||
{ | ||
props: {}, | ||
events: { | ||
balChange: onBalChangeSpy, | ||
}, | ||
}, | ||
) | ||
|
||
cy.get('bal-segment-item').contains('Yes').closest('bal-segment-item').click() | ||
cy.get('@balChange').should('have.been.calledOnce') | ||
cy.get('@balChange').shouldHaveEventDetail('yes') | ||
}) | ||
|
||
it('should not fire change event', () => { | ||
const onBalChangeSpy = cy.spy().as('balChange') | ||
|
||
cy.mount<Components.BalSegment, HTMLBalSegmentElementEventMap>( | ||
`<bal-segment> | ||
<bal-segment-item value="yes" label="Yes"></bal-segment-item> | ||
<bal-segment-item value="no" label="No"></bal-segment-item> | ||
</bal-segment>`, | ||
{ | ||
props: { | ||
value: 'yes', | ||
}, | ||
events: { | ||
balChange: onBalChangeSpy, | ||
}, | ||
}, | ||
) | ||
|
||
cy.get('bal-segment-item').contains('Yes').closest('bal-segment-item').click() | ||
cy.get('@balChange').should('not.have.been.called') | ||
}) | ||
}) |
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,11 @@ | ||
describe('bal-segment', () => { | ||
context('a11y', () => { | ||
beforeEach(() => cy.platform('desktop').pageA11y('/components/bal-segment/test/bal-segment.a11y.html')) | ||
|
||
describe('have the AA standard', () => { | ||
it('basic', () => { | ||
cy.getByTestId('basic').testA11y() | ||
}) | ||
}) | ||
}) | ||
}) |
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,27 @@ | ||
describe('bal-segment', () => { | ||
beforeEach(() => cy.visit('/components/bal-segment/test/bal-segment.visual.html').waitForDesignSystem()) | ||
|
||
it('basic component', () => { | ||
cy.platform('desktop') | ||
cy.getByTestId('basic').testVisual('icon-desktop') | ||
|
||
cy.platform('mobile') | ||
cy.getByTestId('basic').testVisual('icon-mobile') | ||
}) | ||
|
||
it('component horizontal', () => { | ||
cy.platform('desktop') | ||
cy.getByTestId('horizontal').testVisual('horizontal-desktop') | ||
|
||
cy.platform('mobile') | ||
cy.getByTestId('horizontal').testVisual('horizontal-mobile') | ||
}) | ||
|
||
it('component vertical', () => { | ||
cy.platform('desktop') | ||
cy.getByTestId('vertical').testVisual('vertical-desktop') | ||
|
||
cy.platform('mobile') | ||
cy.getByTestId('vertical').testVisual('vertical-mobile') | ||
}) | ||
}) |
Binary file added
BIN
+13.6 KB
e2e/cypress/snapshots/base/visual/bal-segment.visual.cy.ts/horizontal-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.36 KB
e2e/cypress/snapshots/base/visual/bal-segment.visual.cy.ts/horizontal-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.9 KB
e2e/cypress/snapshots/base/visual/bal-segment.visual.cy.ts/icon-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.2 KB
e2e/cypress/snapshots/base/visual/bal-segment.visual.cy.ts/icon-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36 KB
e2e/cypress/snapshots/base/visual/bal-segment.visual.cy.ts/vertical-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.3 KB
e2e/cypress/snapshots/base/visual/bal-segment.visual.cy.ts/vertical-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.