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): Add width-breakpoints-sizes utility classes #2308

Merged
merged 20 commits into from
Jan 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a43df05
feat(styles): Add width-breakpoints-sizes utility classes
imagoiq Nov 27, 2023
dc01bd0
Update packages/documentation/src/stories/components/button/button.do…
imagoiq Nov 29, 2023
196cbfb
Update packages/documentation/src/stories/components/button/button.do…
imagoiq Nov 29, 2023
3356dd7
Update packages/documentation/src/stories/utilities/sizing/sizing.doc…
imagoiq Nov 29, 2023
e9e1587
Update .changeset/gold-chairs-walk.md
imagoiq Nov 29, 2023
e35a062
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
28bd749
Add jest config
imagoiq Nov 30, 2023
bdda9a6
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
314475a
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
6b058bc
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
9c1adb4
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
055fff3
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
45867b5
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Nov 30, 2023
d437096
Fix xs breakpoints and overwrite of basic w-size classes
imagoiq Nov 30, 2023
fd1175a
Fix xs breakpoints and overwrite of basic w-size classes
imagoiq Nov 30, 2023
01105a2
Merge remote-tracking branch 'origin/feat/2249-width-breakpoints-util…
imagoiq Nov 30, 2023
3dfe62b
Fix XS and missing dash
imagoiq Dec 11, 2023
397bd86
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Dec 11, 2023
758c439
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Dec 12, 2023
b597bf7
Merge branch 'main' into feat/2249-width-breakpoints-utility
imagoiq Dec 12, 2023
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/gold-chairs-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@swisspost/design-system-documentation': patch
'@swisspost/design-system-styles': patch
---

Added `w-breakpoints-sizes` utility classes.
Original file line number Diff line number Diff line change
@@ -44,3 +44,12 @@ Besides the usual and the accent button variations, there are also contextual bu
<p className="alert alert-warning">These are only allowed for intranet applications!</p>

<Canvas of={ButtonStories.ContextualColors} />

### Full-width

In some situation, it is desirable to display a button using the full available space width,
for example when the button is displayed on mobile and stacked vertically with others.

To achieve that, you can use `.w-breakpoint-sizes`. e.g. `.w-sm-100` to use the full available space from `sm` viewport size.

<Canvas of={ButtonStories.FullWidth} />
Original file line number Diff line number Diff line change
@@ -222,7 +222,7 @@ const Template = {
`;
} else {
const icon = html`
<post-icon aria-hidden="true" name=${args.icon}></post-icon>
<post-icon aria-hidden="true" name="${args.icon}"></post-icon>
`;
const iconOnlyContent = html`
<span class="visually-hidden">${args.text}</span>
@@ -246,13 +246,15 @@ const Template = {
};

function createProps(args: Args, isAnimated: boolean) {
const additionalClasses = args.additionalClasses ?? [];
return {
class: [
'btn',
args.variant,
args.size,
isAnimated && 'btn-animated',
args.iconOnly && 'btn-icon',
...additionalClasses,
]
.filter(c => c && c !== 'null')
.join(' '),
@@ -326,3 +328,11 @@ export const ContextualColors: Story = {
variants: ['btn-success', 'btn-info', 'btn-warning', 'btn-danger'],
},
};

export const FullWidth: Story = {
...VariantsTemplate,
args: {
variants: ['btn-primary'],
additionalClasses: ['w-sm-100', 'w-md-auto'],
},
};
Original file line number Diff line number Diff line change
@@ -25,13 +25,17 @@ Bootstrap offers sizing classes with the suffixes bellow. They allow you to set
> - `*-75`
> - `*-100`
#### Example

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

### Relative to breakpoints

For width, we offer additionally `w-breakpoints-*` classes (e.g. `w-md-100`) so that you can size only for some specific breakpoints.

See <a href="/?path=/docs/components-button--docs#full-width">Full-width button</a> for a practical example.

### Post-Sizes

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.
@@ -54,8 +58,6 @@ Post sizes can be used as suffixes in the same way. To find out which size name
.join('\n')}
></Source>

#### Example

<Canvas of={SizingStories.Sizes} />
<div className="hide-col-default">
<Controls of={SizingStories.Sizes} />
15 changes: 15 additions & 0 deletions packages/styles/src/components/sizing.scss
Original file line number Diff line number Diff line change
@@ -55,6 +55,21 @@
}
}

// Post breakpoints width - e.g. w-sm-100
@each $breakpoint in map-keys(breakpoints.$grid-breakpoints) {
@include media-breakpoint-up($breakpoint) {
$infix: if($breakpoint == 'xs', '', '-#{$breakpoint}');

@each $prop, $abbrev in (width: w) {
@each $size, $length in spacing.$sizes {
.#{$abbrev}#{$infix}-#{$size} {
#{$prop}: $length !important;
}
}
}
}
}

// Generate responsive spacing utility classes, a lot of them
$cache: ();