Skip to content

Commit

Permalink
chore(documentation,styles): create display utility (#3661)
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Gfeller <[email protected]>
  • Loading branch information
leagrdv and gfellerph authored Oct 11, 2024
1 parent c9be0cb commit 9b35d70
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/components/post-tooltip/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ graph TD;

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('Display', () => {
it('display', () => {
cy.visit('/iframe.html?id=snapshots--display');
cy.get('.display-example', { timeout: 30000 }).should('be.visible');
cy.percySnapshot('Display', { widths: [320, 1440] });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Canvas, Meta } from '@storybook/blocks';
import * as DisplayStories from './display.stories';
import { breakpoints, firstBreakpoint } from '../spacing/spacing.docs.mdx';
import { forEach } from '@/utils/react';

export const displayOptions = [
'none',
'inline',
'inline-block',
'block',
'grid',
'inline-grid',
'table',
'table-cell',
'table-row',
'flex',
'inline-flex',
];

<Meta of={DisplayStories} />

# Display

<div className="lead">
Use the display utility classes to set the display of an element to any possible display CSS
value.
</div>

The naming convention for display utilities follows this pattern:

- For all breakpoints (<code>{firstBreakpoint}</code> and up): `d-{display}`
- Starting from a specific breakpoint ({breakpoints.map(([b, isLast]) => (<span key={b}><code>{b}</code>{isLast ? ', ' : ''}</span>))}): `d-{breakpoint}-{display}`

### Available display values

The available display utilities values are the following:

<ul>
{forEach(displayOptions, function ({ value }) {
return <li>{value}</li>;
})}
</ul>

### Usage

To set a display on an element, simply add a `d-{display}` class to it.

<Canvas of={DisplayStories.Default} sourceState="shown" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import meta from './display.stories';
import { displayOptions } from './display.docs.mdx';
import './display.styles.scss';

const { id, ...metaWithoutId } = meta;

export default {
...metaWithoutId,
title: 'Snapshots',
};

type Story = StoryObj;

export const Display: Story = {
render: () => {
return html`
<div class="display-example">
${displayOptions.map(
display => html`
<div class="display-container p-8">
<div class="d-${display} p-8">${display}</div>
<div class="d-${display} p-8">${display}</div>
</div>
`,
)}
</div>
`;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import { MetaExtended } from '@root/types';

const meta: MetaExtended = {
id: '1bb8a4a7-8205-4dcb-a41c-8f7ab1de1c99',
title: 'Utilities/Display',
};

export default meta;

type Story = StoryObj;

export const Default: Story = {
render: () =>
html`
<div class="d-inline bg-yellow p-8">Content</div>
<div class="d-inline bg-black p-8">Content</div>
`,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use 'sass:color';
@use '@swisspost/design-system-styles/core' as post;

.display-container {
border: post.$border-width solid post.$border-color;

> * {
border: post.$border-width solid post.$border-color;
background-color: color.adjust(post.$border-color, $lightness: 15%);
}
}
2 changes: 2 additions & 0 deletions packages/styles/src/themes/bootstrap/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ $utilities: map.remove($utilities, 'gap');
$utilities: map.remove($utilities, 'row-gap');
$utilities: map.remove($utilities, 'column-gap');

$utilities: map.remove($utilities, 'display');

@import 'bootstrap/scss/utilities/api';
9 changes: 8 additions & 1 deletion packages/styles/src/utilities/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ $utilities: (
class: column-gap,
values: from-tokens('spacing', 'gap'),
),

'display': (
responsive: true,
print: true,
property: display,
class: d,
values: inline inline-block block grid inline-grid table table-row table-cell flex inline-flex
none,
),
// IMPORTANT: When adding new utilities here, please ensure to remove the corresponding bootstrap utilities in `src/themes/bootstrap/_utilities.scss`.
);

0 comments on commit 9b35d70

Please sign in to comment.