Skip to content
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

feat(documentation): add story to document spacing #1988

Merged
merged 15 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,82 @@
import { Meta } from '@storybook/blocks';
import { Canvas, Controls, Meta } from '@storybook/blocks';
import * as SpacingStories from './spacing.stories';

<Meta of={SpacingStories} />

# Spacing

<div className="alert alert-info">
<h2 className="alert-heading">TODO:</h2>
<p>Document differences to bootstrap and link over for the rest.</p>
<div className="lead">
Spacing values bring a uniform and consistent distance between elements.

By adhering to standardized spacing guidelines, we maintain visual alignment and
improve the overall user interface.

</div>

<div class="alert alert-warning mb-bigger-big">
<h2 class="alert-heading">Sizing variables are deprecated</h2>
<p>
The current set of the post-specific sizing variables is deprecated in favour of a new naming
system that is consistent with the Design. For further information, please read the
<a href="https://github.com/swisspost/design-system/discussions/588">
discussion on sizing variables on GitHub
</a>
and have a look at the
<a href="https://www.figma.com/file/ojCcgC5Zd12eUSzq6V5m24/Foundations?node-id=3%3A2&t=l8qimsXlxeMLOzs6-0">
implementation in Figma.
</a>
</p>
<p>
<b>There is a new solution with updated naming system up coming for spacing sizes.</b>
</p>
</div>
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

## Padding & Margin

Padding and margin can be set using `p*` and `m*` prefixes.
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

You can apply the desired margin / padding all around an element using the prefix alone ( `m-*` / `p-*` ), or you can specify a position (ex: `pt-` , `pb-` , `pe-` , `ps-` respectively for a padding at top, bottom, right and left). You can also set a margin/padding along the horizontal axis (i.e. right and left) using `px-` / `mx-` or along the vertical axis (i.e. top and bottom) using `py`- / `my-` .
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

Bootstrap offers spacing classes with suffixes going from 0 to 5 ( `*-0` , `*-1` , `*-2` , ...) (see [Bootstrap Spacing](https://getbootstrap.com/docs/5.2/utilities/spacing/) for reference).
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

Post sizes can be used in the same way: by adding the name of the desired size to a prefix (to find out which size name to use, see the "Size name in classes" column in the reference table on the [Sizing page](/?path=/docs/utilities-sizing--docs) or use the demo below).
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
### Example

davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
<Canvas of={SpacingStories.Default} />
<div className="hide-col-default">
<Controls of={SpacingStories.Default} />
</div>

### Negative margin

In CSS, margin properties can utilize negative values (padding cannot).

The syntax is nearly the same as the default, positive margin utilities, but with the addition of n before the requested size. For example `mt-n3` would be the opposite of `mt-3`.

davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
## Responsive behavior

By default, the above classes apply to all breakpoints.

If you need to change the size or spacing of an element based on the breakpoint, you should
mention it in the class name using one of the following infixes: `-sm-`, `-rg-`, `-md-`, `-lg-`, `-xl-`, `-xxl-`.
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
When a breakpoint is specified, the size applies to that breakpoint and to all those that are
larger.

Another way to define a responsive size is to use the `-r` suffix. It allows to obtain a size which updates automatically and consistently depending on the breakpoint, without having to specify anything manually.
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

### Example

##### Manually specifying breakpoints
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

The square below has a "big" padding from the large (-lg-) breakpoint and a "regular"
padding below.
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

<Canvas of={SpacingStories.responsiveExample} />

##### Using automatic responsive behavior

The square below has a "large" responsive padding, which means the padding size
automatically changes based on the breakpoint but remains visually consistent.

<Canvas of={SpacingStories.automaticResponsiveExample} />
Original file line number Diff line number Diff line change
@@ -1,15 +1,165 @@
import { Meta, StoryObj } from '@storybook/web-components';
import type { Args, Meta, StoryObj, StoryContext } from '@storybook/web-components';
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
import { BADGE } from '../../../../.storybook/constants';
import { html } from 'lit/static-html.js';

const sizingOptions = [
'0',
'1',
'2',
'3',
'4',
'5',
'auto',
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
'hair',
'line',
'micro',
'mini',
'small-regular',
'regular',
'small-large',
'large',
'big',
'bigger-big',
'small-huge',
'huge',
'giant',
'bigger-giant',
];

const positionOptions = {
'': 'All around',
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
'x': 'Along the horizontal axis',
'y': 'Along the vertical axis',
't': 'At the top',
'b': 'At the bottom',
'r': 'To the right',
'l': 'To the left',
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
};

const meta: Meta = {
title: 'Utilities/Spacing',
parameters: {
badges: [BADGE.TODO],
badges: [BADGE.NEEDS_REVISION],
},
args: {
marginSize: 'regular',
marginPosition: '',
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
paddingSize: 'regular',
paddingPosition: '',
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
},
argTypes: {
marginSize: {
name: 'Margin size',
description: 'Sets the size of the Margin.',
control: {
type: 'select',
},
options: sizingOptions,
table: {
category: 'General',
},
},
marginPosition: {
name: 'Margin Position',
description: 'Sets the position of the Margin.',
control: {
type: 'select',
labels: positionOptions,
},
options: Object.keys(positionOptions),
table: {
category: 'General',
},
},
paddingSize: {
name: 'Padding size',
description: 'Sets the size of the Padding.',
control: {
type: 'select',
},
options: sizingOptions,
table: {
category: 'General',
},
},
paddingPosition: {
name: 'Pading Position',
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved
description: 'Sets the position of the Padding.',
control: {
type: 'select',
labels: positionOptions,
},
options: Object.keys(positionOptions),
table: {
category: 'General',
},
},
},
};

export default meta;

type Story = StoryObj;

export const Default: Story = {};
export const Default: Story = {
render: (args: Args) => {
return html`
<!-- Demo -->
<div class="bg-primary p-regular d-flex align-items-start">
<div class="flex-fill d-flex">
<div class="bg-petrol">
<div
class="bg-petrol-bright border border-dark h-bigger-giant m${args.marginPosition}-${args.marginSize} p${args.paddingPosition}-${args.paddingSize} w-bigger-giant"
>
<div class="bg-light h-100"></div>
</div>
</div>
</div>

<!-- Legend -->
<ul class="ps-regular text-white">
<li class="d-flex align-items-center mb-regular">
<div class="bg-petrol h-regular w-regular me-mini"></div>
<span>margin</span>
</li>
<li class="d-flex align-items-center mb-regular">
<div class="bg-petrol-bright h-regular w-regular me-mini"></div>
<span>padding</span>
</li>
<li class="d-flex align-items-center mb-regular">
<div class="bg-light h-regular w-regular me-mini"></div>
<span>content</span>
</li>
</ul>
</div>
`;
},
};
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved

export const responsiveExample: Story = {
render: (args: Args) => {
return html`
<div class="bg-primary p-regular">
<div
class="border border-dark bg-petrol-bright h-bigger-giant w-bigger-giant p-regular p-lg-big"
>
<div class="bg-light h-100"></div>
</div>
<p class="text-white"><small>Resize the browser window to see changes.</small></p>
</div>
`;
},
};

export const automaticResponsiveExample: Story = {
render: (args: Args) => {
return html`
<div class="bg-primary p-regular">
<div class="border border-dark bg-petrol-bright h-bigger-giant w-bigger-giant p-large-r">
<div class="bg-light h-100"></div>
</div>
<p class="text-white"><small>Resize the browser window to see changes.</small></p>
</div>
`;
},
};
davidritter-dotcom marked this conversation as resolved.
Show resolved Hide resolved