-
Notifications
You must be signed in to change notification settings - Fork 21
feat(docs, styles): create html/css Divider component #6783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4decc15
a543c1f
0fffbf8
10b124f
7413a38
3c65eb0
9a257ab
5c57faa
25290b4
d239d1b
5ecc51b
e738639
07f12c2
a71fec0
3eba9a4
9f62ea7
a6aa5a2
a9a923e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@swisspost/design-system-documentation': minor | ||
| '@swisspost/design-system-styles': minor | ||
| --- | ||
|
|
||
| Implemented a `Divider` html/css component using tokens for styles. Divider documentation is also added to /Foundations/Typography page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| describe('Divider', () => { | ||
| describe('Accessibility', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/iframe.html?id=snapshots--divider'); | ||
| cy.get('hr', { timeout: 30000 }).should('be.visible'); | ||
| cy.injectAxe(); | ||
| }); | ||
|
|
||
| it('Has no detectable a11y violations on load for all variants', () => { | ||
| cy.checkA11y('#root-inner'); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Canvas, Controls, Meta } from '@storybook/addon-docs/blocks'; | ||
| import meta, * as DividerStories from './divider.stories'; | ||
| import StylesPackageImport from '@/shared/styles-package-import.mdx'; | ||
| import PackageTag from '@/shared/package-tag'; | ||
|
|
||
| <Meta of={DividerStories} /> | ||
|
|
||
| <div className="docs-title"> | ||
| # Divider | ||
|
|
||
| <link-design of={JSON.stringify(DividerStories)}></link-design> | ||
| </div> | ||
|
|
||
| <PackageTag meta={meta}/> | ||
|
|
||
| <p className="lead">A Divider is a horizontal line used to visually separate or group content, improving the readability of a page.</p> | ||
| <p>Dividers can be used in various contexts, for example within forms, lists or sections. The `<hr>` HTML tag represents a thematic break between paragraph elements.</p> | ||
|
|
||
| <Canvas sourceState="shown" of={DividerStories.Default} /> | ||
| <div className="hide-col-default"> | ||
| <Controls of={DividerStories.Default} /> | ||
| </div> | ||
|
Comment on lines
+19
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should mention here, that one can simply use our spacing utilities to change the default margin above/below. e.g.
|
||
|
|
||
| <StylesPackageImport components={['divider']} /> | ||
|
|
||
| ## Usage | ||
|
|
||
| Dividers are often used within forms. | ||
|
Comment on lines
+26
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove that, as it does not provide any value. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { Args, StoryContext, StoryObj } from '@storybook/web-components-vite'; | ||
| import meta from './divider.stories'; | ||
| import { html } from 'lit'; | ||
| import { schemes } from '@/shared/snapshots/schemes'; | ||
| import { bombArgs } from '@/utils'; | ||
|
|
||
| const { id, ...metaWithoutId } = meta; | ||
|
|
||
| export default { | ||
| ...metaWithoutId, | ||
| title: 'Snapshots', | ||
| }; | ||
|
|
||
| type Story = StoryObj; | ||
|
|
||
| export const Divider: Story = { | ||
| render: (_args: Args, context: StoryContext) => { | ||
| return schemes( | ||
| () => html` | ||
| <div class="d-flex flex-column gap-32 p-16"> | ||
| ${bombArgs({ | ||
| marginTop: context.argTypes.marginTop.options, | ||
| marginBottom: context.argTypes.marginBottom.options, | ||
| }).map((args: Args) => { | ||
| return html` | ||
| <div class="position-relative" style="width: 600px;"> | ||
| ${meta.render?.({ ...context.args, ...args }, context)} | ||
| </div> | ||
| `; | ||
| })} | ||
| </div> | ||
| `, | ||
| ); | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { MetaComponent } from '@root/types'; | ||
| import type { Args, StoryObj } from '@storybook/web-components-vite'; | ||
| import { html } from 'lit/static-html.js'; | ||
| import { nothing } from 'lit'; | ||
|
|
||
| const meta: MetaComponent = { | ||
| id: 'a1eef11e-b5db-4066-99a8-9723a6cdef12', | ||
| title: 'Components/Divider', | ||
| tags: ['package:Styles', 'status:Experimental'], | ||
| render, | ||
| parameters: { | ||
| badges: [], | ||
| design: { | ||
| type: 'figma', | ||
| url: 'https://www.figma.com/design/JIT5AdGYqv6bDRpfBPV8XR/Foundations---Components-Next-Level?node-id=13995-180113&t=w6yq9dykdA3NLIPh-4', | ||
| }, | ||
| }, | ||
| args: { | ||
| marginTop: 'null', | ||
| marginBottom: 'null', | ||
| }, | ||
| argTypes: { | ||
| marginTop: { | ||
| name: 'Margin top', | ||
| description: 'Sets the margin between the divider line and the content above.', | ||
| control: { | ||
| type: 'select', | ||
| labels: { | ||
| 'mt-4': '4', | ||
| 'null': '8 (default)', | ||
| 'mt-16': '16', | ||
| 'mt-24': '24', | ||
| 'mt-32': '32', | ||
| 'mt-40': '40', | ||
| }, | ||
| }, | ||
| options: ['mt-4', 'null', 'mt-16', 'mt-24', 'mt-32', 'mt-40'], | ||
| table: { | ||
| category: 'General', | ||
| }, | ||
| }, | ||
| marginBottom: { | ||
| name: 'Margin bottom', | ||
| description: 'Sets the margin between the divider line and the content below.', | ||
| control: { | ||
| type: 'select', | ||
| labels: { | ||
| 'mb-4': '4', | ||
| 'null': '8 (default)', | ||
| 'mb-16': '16', | ||
| 'mb-24': '24', | ||
| 'mb-32': '32', | ||
| 'mb-40': '40', | ||
| }, | ||
| }, | ||
| options: ['mb-4', 'null', 'mb-16', 'mb-24', 'mb-32', 'mb-40'], | ||
| table: { | ||
| category: 'General', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj; | ||
|
|
||
| // | ||
| // RENDERER | ||
| // | ||
| function render(args: Args) { | ||
| const classes = [ | ||
| args.marginTop !== 'null' ? args.marginTop : '', | ||
| args.marginBottom !== 'null' ? args.marginBottom : '', | ||
| ] | ||
| .filter(Boolean) | ||
| .join(' '); | ||
|
|
||
| return html` | ||
| <p>This is some content above the divider.</p> | ||
|
|
||
| <hr class="${classes || nothing}" /> | ||
|
|
||
| <p>This is some content below the divider.</p> | ||
| `; | ||
| } | ||
| export const Default: Story = {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| @use '../functions/tokens'; | ||
| @use '../tokens/components'; | ||
|
|
||
| tokens.$default-map: components.$post-divider; | ||
|
|
||
| hr { | ||
| border-color: tokens.get('post-divider-border'); | ||
| border-width: tokens.get('post-divider-border-width'); | ||
| margin-block: tokens.get('post-divider-margin-block'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.