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(styles): updated sizing utility (no tokens) #4012

Merged
merged 83 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
c3db078
feat(Styles): Updated sizing utility (no tokens)
myrta2302 Oct 8, 2024
f0d3a1b
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Oct 10, 2024
a82d513
chore(Styles): Merged and adjusted Sizing utility to the updated util…
myrta2302 Oct 10, 2024
468a09a
fix(Styles): Corrected an error in Sizing utility min-vw and min-vh c…
myrta2302 Oct 10, 2024
4ee679c
chore(Styles): Removed formatter entries in settings.json
myrta2302 Oct 10, 2024
5f3ace3
chore(styles): reverted to default linting
myrta2302 Oct 15, 2024
058fe52
Update soft-pugs-dream.md
myrta2302 Oct 16, 2024
be57e5d
chore(styles): review corrections
myrta2302 Oct 16, 2024
63c8dda
Update soft-pugs-dream.md
myrta2302 Oct 16, 2024
1b7492e
Delete packages/documentation/src/stories/utilities/spacing/spacing.s…
myrta2302 Oct 29, 2024
646aa95
Update packages/documentation/src/stories/utilities/sizing/sizing.doc…
myrta2302 Oct 29, 2024
f6bd8e9
Update packages/styles/src/utilities/_variables.scss
myrta2302 Oct 29, 2024
a15095b
Revert "Delete packages/documentation/src/stories/utilities/spacing/s…
myrta2302 Oct 29, 2024
705d74c
review comments update
myrta2302 Oct 29, 2024
16eb19d
fix commit error
myrta2302 Oct 29, 2024
f924141
review comments update - merged snapshots
myrta2302 Oct 29, 2024
1bae545
minor
myrta2302 Oct 29, 2024
6da50e6
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Oct 29, 2024
d6efe73
Update sizing.stories.ts
myrta2302 Oct 29, 2024
0430161
Update sizing.styles.scss
myrta2302 Oct 29, 2024
d1a8183
fix linting errors
myrta2302 Oct 29, 2024
3d4bec3
Update sizing.snapshot.ts
myrta2302 Oct 29, 2024
e5c0324
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Oct 31, 2024
576de4a
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Oct 31, 2024
42d2f5f
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 4, 2024
7e22271
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 8, 2024
ba233e9
Update packages/documentation/src/stories/utilities/sizing/sizing.doc…
myrta2302 Nov 11, 2024
49a7beb
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 11, 2024
714dee2
review comments update
myrta2302 Nov 11, 2024
5c5c154
minor
myrta2302 Nov 11, 2024
514dd7a
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 11, 2024
6cadf22
minor
myrta2302 Nov 11, 2024
93e4b90
revert file changes
myrta2302 Nov 12, 2024
2e54943
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 12, 2024
e9c0c6c
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 12, 2024
3ecb288
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 12, 2024
d48c295
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 14, 2024
544854d
Merge branch '3433-component-sizing-utilities' of https://github.com/…
myrta2302 Nov 14, 2024
87e4eac
replace deprecated sizing classes
myrta2302 Nov 15, 2024
f913594
Update slider.stories.ts
myrta2302 Nov 15, 2024
edaca52
Revert "Update slider.stories.ts"
myrta2302 Nov 15, 2024
c9cf170
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Nov 18, 2024
9b33652
update logo test - remove deprecated classes
myrta2302 Nov 18, 2024
c2d8756
update mw to max-w
myrta2302 Nov 18, 2024
747e7c2
create pixel based sizes
myrta2302 Dec 2, 2024
be4811e
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Dec 3, 2024
047b606
remove size- prefix
myrta2302 Dec 3, 2024
5a5e886
Merge branch 'main' into feat(styles)-create-pixel-sizing-classes-and…
myrta2302 Dec 3, 2024
25ca5ba
updated docs with new px sizes
myrta2302 Dec 3, 2024
e791ae8
create text classes for percentages
myrta2302 Dec 3, 2024
3254c48
add changset
myrta2302 Dec 3, 2024
5148374
Merge branch '3433-component-sizing-utilities' into feat(styles)-crea…
myrta2302 Dec 3, 2024
8881cf4
update documentation
myrta2302 Dec 3, 2024
0fe1d3a
refactored stories code
myrta2302 Dec 3, 2024
2d78a1b
revert file
myrta2302 Dec 3, 2024
566d95f
Update packages/migrations/src/utils/constants.ts
myrta2302 Dec 3, 2024
ca9c8f7
Merge branch '3433-component-sizing-utilities' of https://github.com/…
myrta2302 Dec 3, 2024
bf64306
Merge branch 'feat(styles)-create-pixel-sizing-classes-and-update-dep…
myrta2302 Dec 3, 2024
5daa606
logo error fixed
myrta2302 Dec 3, 2024
d697488
lint error fix
myrta2302 Dec 3, 2024
e07061e
revert file
myrta2302 Dec 3, 2024
92f7fe2
lint error
myrta2302 Dec 3, 2024
3b7dfbf
vh additions and snapshot refactor
myrta2302 Dec 4, 2024
c8aabc1
minor
myrta2302 Dec 4, 2024
0a2d6d7
fix code smell
myrta2302 Dec 4, 2024
fda1cdb
code smell fix
myrta2302 Dec 4, 2024
39f2ada
minor
myrta2302 Dec 4, 2024
8f49467
update references
myrta2302 Dec 4, 2024
92439cf
Update packages/documentation/src/stories/utilities/sizing/sizing.doc…
myrta2302 Dec 13, 2024
f5393b5
Update packages/documentation/src/stories/utilities/sizing/sizing.sto…
myrta2302 Dec 13, 2024
bfd0db0
reset file
myrta2302 Dec 13, 2024
777f5f2
review comments update
myrta2302 Dec 13, 2024
ac87ada
Merge branch '3433-component-sizing-utilities' of https://github.com/…
myrta2302 Dec 13, 2024
7926b2a
minor
myrta2302 Dec 13, 2024
27d5e16
update sizing class
myrta2302 Dec 13, 2024
84dcc6b
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Dec 13, 2024
30a1555
error fix
myrta2302 Dec 13, 2024
7c70c43
doc update
myrta2302 Dec 13, 2024
0aa8cc6
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Dec 13, 2024
01c159b
revert migration file
myrta2302 Dec 13, 2024
1fe8556
review update
myrta2302 Dec 13, 2024
a00b695
revert migration file
myrta2302 Dec 13, 2024
aabde77
Merge branch 'main' into 3433-component-sizing-utilities
myrta2302 Dec 13, 2024
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
6 changes: 6 additions & 0 deletions .changeset/soft-pugs-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@swisspost/design-system-documentation': minor
'@swisspost/design-system-styles': minor
---

Updated the utility classes for sizing.
6 changes: 6 additions & 0 deletions .changeset/violet-poems-attend.md
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 new pixel based sizes.
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe('Sizing', () => {
// Parent based sizing classes [e.g. .quarter, .third, .half, etc.]
it('Sizing Percentages', () => {
cy.visit('/iframe.html?id=snapshots--percentage-sizing');
cy.get('.snapshot', { timeout: 30000 }).should('be.visible');
cy.percySnapshot('Sizing', { widths: [320, 1440] });
});

// Percentage sizing classes relative to viewport [e.g. vh-25, vw-33, min-vh-50, max-vw-100, etc.]
it('Sizing Viewport Percentages', () => {
cy.visit('/iframe.html?id=snapshots--percentage-vp-sizing');
cy.get('.snapshot', { timeout: 30000 }).should('be.visible');
cy.percySnapshot('Sizing', { widths: [320, 1440] });
});

// Pixel based sizing classes [e.g. h-80, w-56, max-w-24, min-h-24, etc.]
it('Sizing Pixel Based', () => {
cy.visit('/iframe.html?id=snapshots--pixel-sizing');
cy.get('.snapshot', { timeout: 30000 }).should('be.visible');
cy.percySnapshot('Sizing', { widths: [320, 1440] });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span [class.visually-hidden]="selectedOption">Default custom-select</span>
<span *ngIf="selectedOption" aria-hidden="true">{{ selectedOption.label }}</span>
</button>
<div aria-labelledby="customSelectButton" class="w-100 mw-100" ngbDropdownMenu role="listbox">
<div aria-labelledby="customSelectButton" class="w-100 max-w-100" ngbDropdownMenu role="listbox">
<button
(click)="toggle.focus()"
(focus)="selectedOption = option"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<label class="form-label" id="customSelectLabel">
Floatinglabel custom-select {{ infoText }}
</label>
<div aria-labelledby="customSelectLabel" class="w-100 mw-100" ngbDropdownMenu role="listbox">
<div aria-labelledby="customSelectLabel" class="w-100 max-w-100" ngbDropdownMenu role="listbox">
<button
(click)="toggle.focus()"
(focus)="selectedOption = option"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function render(args: Args, context: StoryContext) {
<label class="form-label visually-hidden" for="${inputId}">Range controller</label>
<input
id="${inputId}"
class="form-control mw-giant"
class="form-control min-w-80"
type="text"
inputmode="decimal"
value="${args.value}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const PostLogo: Story = {
<p>${url ? 'Links' : 'Images'}</p>
<div class="row">
<div class="col">
${['big', 'huge', 'giant'].map(
${['32', '56', '80'].map(
(height, i) => html`
<div class="h-${height} ${i === 0 ? 'my' : 'mb'}-16">
${meta.render?.({ ...context.args, url }, context)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default meta;

// DECORATORS
function containerWithHeight(story: StoryFn, context: StoryContext) {
return html` <div class="h-giant">${story(context.args, context)}</div> `;
return html` <div class="h-80">${story(context.args, context)}</div> `;
}

// RENDERER
Expand Down Expand Up @@ -57,5 +57,5 @@ export const Link: Story = {
};

export const Height: Story = {
render: () => html` <post-logo class="h-huge">Logo of the Post</post-logo> `,
render: () => html` <post-logo class="h-56">Logo of the Post</post-logo> `,
};
myrta2302 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ export class MigrationV45ManualListComponent extends LitElement {
${this._templateAutoIconAngular()}
<span class="tag tag-sm tag-danger">breaking</span> Removed
<code>.custom-select-menu</code> class.<br />
Use <em>utility-classes</em>&nbsp;<code>.w-100.mw-100</code>
Use <em>utility-classes</em>&nbsp;<code>.w-100.max-w-100</code>
instead.
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,49 @@ import * as SizingStories from './sizing.stories';

## Height & Width

Height and width can be set using `h-*` and `w-*` prefixes, max-height and max-width can be set using prefixes `mh-*` and `mw-*` .
Height and width can be set using our utility classes `h-{size}` and `w-{size}`, max-height and max-width can be set with `max-h-{size}` and `max-w-{size}` and min-height and min-width can be set with `min-h-{size}` and `min-w-{size}`.

### Parent Based

Bootstrap offers sizing classes with the suffixes bellow. They allow you to set a height / width as a percentage of the parent element (see [Bootstrap Sizing](https://getbootstrap.com/docs/5.3/utilities/sizing/) for reference).
The design system offers classes for percentage based sizing with the suffixes bellow. They allow you to set a height / width as a percentage of the parent element.

> - `*-25`
> - `*-50`
> - `*-75`
> - `*-100`
- `*-auto`
- `*-quarter`
- `*-third`
- `*-half`
- `*-two-thirds`
- `*-three-quarters`
- `*-full`

#### Example
### Example

<Canvas sourceState="shown" of={SizingStories.SizesPercent} />
<Canvas sourceState="shown" of={SizingStories.PercentSizes} />
<div className="hide-col-default">
<Controls of={SizingStories.SizesPercent} />
<Controls of={SizingStories.PercentSizes} />
</div>

### Relative to breakpoints

For width, we offer additionally `.w-{breakpoint}-{size}` classes (e.g. `w-md-100`) so that you can size only for some specific breakpoints.
### Pixel Based

See <a href="/?path=/docs/eb78afcb-ce92-4990-94b6-6536d5ec6af4--docs#full-width">Full-width button</a> for a practical example.
Additional pixel-based sizing classes allow precise height `h-{size}` and width `w-{size}` definitions in pixels (e.g., `w-12` for 12px width and `h-26` for 26px height).

### Post-Sizes
See all available sizes in the example bellow.

Post sizes can be used as suffixes in the same way. To find out which size name to use, see the "Size name in classes" column in the reference table above or use the "Example Post-Sizes" below.
### Example

#### Sass variables

{/* prettier-ignore */}
<div className="banner banner-warning mb-40">
<h2 className="banner-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>There is a new solution with updated naming system up coming for spacing sizes.</p>
<Canvas sourceState="shown" of={SizingStories.PxSizes} />
<div className="hide-col-default">
<Controls of={SizingStories.PxSizes} />
</div>

<Source
language="scss"
dark
code={Object.entries(SizingStories.SCSS_VARIABLES)
.filter(([key, value]) => key !== 'parameters')
.map(([key, value]) => `$${key}: ${formatAsMap(value)};`)
.join('\n')}
></Source>
### Relative to breakpoints

<Canvas of={SizingStories.Sizes} />
<div className="hide-col-default">
<Controls of={SizingStories.Sizes} />
</div>
For width and height, the design system provides additionally `.w-{breakpoint}-{size}` classes (e.g. `w-md-full`, `h-md-56`) so that you can set different sizes for specific breakpoints.

See <a href="/?path=/docs/eb78afcb-ce92-4990-94b6-6536d5ec6af4--docs#full-width">Full-width button</a> for a practical example.

## Viewport Based
### Viewport Based

There is the possibility to set the width and height relative to the viewport.
There is the possibility to set the width and height as a percentage relative to the viewport. Available percentages: `25`, `33`, `50`, `66`, `75`, `100`.

> - `min-vh-100`
> - `min-vw-100`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
@use 'sass:list';
@use 'sass:map';
@use '@swisspost/design-system-styles/core' as post;
@use '@swisspost/design-system-styles/variables/sizing' as tokens;

:export {
@each $key, $value in post.$post-sizes {
#{$key}: #{$value};
@each $key, $value in tokens.$post-percentage-sizes {
pcsizes_#{$key}: #{$value};
}
@each $key, $value in tokens.$post-px-sizes {
pxsizes_#{$key}: #{$value};
}
@each $breakpoint in post.$grid-breakpoints-list {
@if (map.get(post.$grid-breakpoints, $breakpoint) == 0) {
firstBreakpoint_#{$breakpoint}: $breakpoint;
}
@if (map.get(post.$grid-breakpoints, $breakpoint) != 0) {
breakpoints_#{$breakpoint}: $breakpoint;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import type { StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import './sizing.styles.scss';
import meta from './sizing.stories';
import { COLOR_SCHEMES, schemes } from '@/shared/snapshots/schemes';

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

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

const samples = [
{ w: 'third', h: 'full', maxW: 'third', minW: 'full', maxH: 'half', minH: 'two-thirds' },
{ w: 'quarter', h: 'half', maxW: 'quarter', minW: 'half', maxH: 'full', minH: 'quarter' },
{ w: 'half', h: 'quarter', maxW: 'half', minW: 'quarter', maxH: 'two-thirds', minH: 'third' },
{
w: 'three-quarters',
h: 'quarter',
maxW: 'three-quarters',
minW: 'three-quarters',
maxH: 'quarter',
minH: 'half',
},
{ w: 'full', h: 'half', maxW: 'full', minW: 'third', maxH: 'auto', minH: 'auto' },
];

const vpSamples = [
{ w: '33', h: '100', maxvW: '33', minvW: '100', maxvH: '50', minvH: '66' },
{ w: '50', h: '50', maxvW: '25', minvW: '50', maxvH: '100', minvH: '25' },
{ w: '50', h: '25', maxvW: '50', minvW: '25', maxvH: '66', minvH: '33' },
{
w: '75',
h: '25',
maxvW: '75',
minvW: '25',
maxvH: '50',
minvH: '25',
},
{ w: '100', h: '50', maxvW: '100', minvW: '33', maxvH: 'auto', minvH: 'auto' },
];

const pxSamples = [
{ w: '12', h: '18', maxW: '33', minW: '12', maxH: '48', minH: '22' },
{ w: '24', h: '36', maxW: '32', minW: '20', maxH: '40', minH: '24' },
{ w: '40', h: '56', maxW: '48', minW: '24', maxH: '56', minH: '32' },
{ w: '28', h: '64', maxW: '80', minW: '56', maxH: '96', minH: '36' },
{ w: '96', h: '48', maxW: '100', minW: '40', maxH: '112', minH: '48' },
{ w: '64', h: '56', maxW: '80', minW: '32', maxH: '78', minH: '64' },
{ w: '20', h: '15', maxW: '22', minW: '12', maxH: '32', minH: '18' },
{ w: '32', h: '22', maxW: '40', minW: '24', maxH: '36', minH: '20' },
{ w: '78', h: '96', maxW: '80', minW: '40', maxH: '112', minH: '56' },
{ w: '48', h: '80', maxW: '96', minW: '50', maxH: '112', minH: '56' },
{ w: '80', h: '96', maxW: '112', minW: '64', maxH: '100', minH: '36' },
];
function generateClassNames(sample: Record<string, string>, isViewport = false) {
const prefix = isViewport ? 'v' : '';

const classNames = ['content'];

classNames.push(prefix + 'h-' + sample.h);
classNames.push(prefix + 'w-' + sample.w);

if (sample['max' + prefix + 'H'] && sample['max' + prefix + 'H'] !== 'none') {
classNames.push('max-vh-' + sample['max' + prefix + 'H']);
}

if (sample['max' + prefix + 'W'] && sample['max' + prefix + 'W'] !== 'none') {
classNames.push('max-vw-' + sample['max' + prefix + 'W']);
}

if (sample['min' + prefix + 'H'] && sample['min' + prefix + 'H'] !== 'none') {
classNames.push('min-vh-' + sample['min' + prefix + 'H']);
}

if (sample['min' + prefix + 'W'] && sample['min' + prefix + 'W'] !== 'none') {
classNames.push('min-vw-' + sample['min' + prefix + 'W']);
}

return classNames.filter(Boolean).join(' ');
}

export const PercentageSizing: StoryObj = {
render() {
return schemes(
() => {
return html`
${samples.map(sample => {
return html`<div class="sizing-example snapshot">
<div class="${generateClassNames(sample)}"></div>
</div>`;
})};
`;
},
{ filter: scheme => scheme === COLOR_SCHEMES.light },
);
},
};

export const PercentageVpSizing: StoryObj = {
render() {
return schemes(
() => {
return html`
<div class="grid">
${vpSamples.map(sample => {
return html`
<div class="grid-item">
<div class="sizing-example snapshot">
<div class="${generateClassNames(sample, true)}"></div>
</div>
</div>
`;
})}
</div>
`;
},
{ filter: scheme => scheme === COLOR_SCHEMES.light },
);
},
};

export const PixelSizing: StoryObj = {
render() {
return schemes(
() => {
return html`
${pxSamples.map(sample => {
return html`<div class="sizing-px-example snapshot">
<div class="${generateClassNames(sample)}"></div>
</div>`;
})}
`;
},
{ filter: scheme => scheme === COLOR_SCHEMES.light },
);
},
};
Loading
Loading