Skip to content

Commit d54ea3f

Browse files
feat(docs, styles): improve position utilities. (#6002)
## 📄 Description The _position_ utility classes allow defining the inset of an element. The classes available are - top-[position] - bottom-[position] - start-[position] - end-[position] where [position] can be 0, 50, or 100. The goal was to improve these _position_ utilities and their documentation by: - `inline-*` and `block-*` properties: Replaced `top`, `bottom`, `right` and `left` with `inset-block-start`, `inset-block-end`, `inset-inline-start` and `inset-inline-end`. - Added a control for the `bottom-*` and `end-* classes` in the _position_ utility documentation. Consequently classes for `bottom` and `end` were added to the SCSS variables on styles. --------- Co-authored-by: Alona Zherdetska <[email protected]>
1 parent 79f7dc5 commit d54ea3f

File tree

5 files changed

+73
-58
lines changed

5 files changed

+73
-58
lines changed

.changeset/busy-lines-pick.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@swisspost/design-system-documentation': minor
3+
'@swisspost/design-system-styles': minor
4+
---
5+
6+
Added missing `bottom` and `end` controls to position utilities for complete configuration.
7+
Replaced empty label option with `unset` for better clarity across all position controls (`top`, `bottom`, `start`, `end`).
8+
Position utilities now use logical CSS inset properties (inset-block-start, inset-block-end, inset-inline-start, inset-inline-end).
9+
This means `start` and `end` follow the writing direction — left in LTR and right in RTL.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ styles/stylelint-report.txt
3131
.netlify
3232

3333
# Turborepo
34-
.turbo
34+
.turbo
35+
36+
# Intellij IDEA
37+
.idea

packages/documentation/src/stories/utilities/position/position.stories.ts

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ const meta: MetaExtended = {
99
title: 'Utilities/Position',
1010
args: {
1111
position: 'absolute',
12-
start: '50',
1312
top: '0',
13+
bottom: 'unset',
14+
start: '50',
15+
end: 'unset',
1416
translateMiddle: 'both',
1517
},
1618
argTypes: {
@@ -31,90 +33,83 @@ const meta: MetaExtended = {
3133
control: {
3234
type: 'select',
3335
},
34-
options: ['', '0', '50', '100'],
36+
options: ['unset', '0', '50', '100'],
3537
table: {
3638
category: 'General',
3739
},
38-
if: {
39-
arg: 'bottom',
40-
truthy: false,
41-
},
4240
},
4341
bottom: {
4442
name: 'Bottom',
4543
description: 'Sets the distance from bottom. ',
4644
control: {
4745
type: 'select',
4846
},
49-
options: ['', '0', '50', '100'],
47+
options: ['unset', '0', '50', '100'],
5048
table: {
5149
category: 'General',
5250
},
53-
if: {
54-
arg: 'top',
55-
truthy: false,
56-
},
5751
},
5852
start: {
5953
name: 'Start',
6054
description: 'Sets the distance from start (left in LTR). ',
6155
control: {
6256
type: 'select',
6357
},
64-
options: ['', '0', '50', '100'],
58+
options: ['unset', '0', '50', '100'],
6559
table: {
6660
category: 'General',
6761
},
68-
if: {
69-
arg: 'end',
70-
truthy: false,
71-
},
7262
},
7363
end: {
7464
name: 'End',
7565
description: 'Sets the distance from end (right in LTR). ',
7666
control: {
7767
type: 'select',
7868
},
79-
options: ['', '0', '50', '100'],
69+
options: ['unset', '0', '50', '100'],
8070
table: {
8171
category: 'General',
8272
},
83-
if: {
84-
arg: 'start',
85-
truthy: false,
86-
},
8773
},
8874
translateMiddle: {
8975
name: 'Translate middle',
9076
description: 'Set to true to center align an element based on its x and y position.',
9177
control: {
9278
type: 'select',
9379
},
94-
options: ['', 'both', 'x', 'y'],
80+
options: ['unset', 'both', 'x', 'y'],
9581
table: {
9682
category: 'General',
9783
},
9884
},
9985
},
10086
render: (args: Args) => {
101-
let translateMiddleValue = '';
87+
let classes = '';
88+
if (args.start !== 'unset') {
89+
classes += ' start-' + args.start;
90+
}
91+
92+
if (args.end !== 'unset') {
93+
classes += ' end-' + args.end;
94+
}
95+
96+
if (args.top !== 'unset') {
97+
classes += ' top-' + args.top;
98+
}
99+
100+
if (args.bottom !== 'unset') {
101+
classes += ' bottom-' + args.bottom;
102+
}
103+
102104
if (args.translateMiddle === 'both') {
103-
translateMiddleValue = ' translate-middle';
105+
classes += ' translate-middle';
104106
} else if (args.translateMiddle === 'x') {
105-
translateMiddleValue = ' translate-middle-x';
107+
classes += ' translate-middle-x';
106108
} else if (args.translateMiddle === 'y') {
107-
translateMiddleValue = ' translate-middle-y';
109+
classes += ' translate-middle-y';
108110
}
109-
return html`
110-
<div
111-
class="my-element position-${args.position} ${args.top
112-
? 'top-' + args.top
113-
: ''}${args.bottom ? 'bottom-' + args.bottom : ''} ${args.start
114-
? 'start-' + args.start
115-
: ''}${args.end ? 'end-' + args.end : ''}${translateMiddleValue}"
116-
></div>
117-
`;
111+
112+
return html` <div class="my-element position-${args.position}${classes}"></div> `;
118113
},
119114
};
120115

@@ -124,23 +119,22 @@ type Story = StoryObj;
124119

125120
export const Default: Story = {
126121
decorators: [
127-
(story, context) =>
128-
html`
129-
<div class="position-outer-container position-outer-container-${context.args.position}">
130-
${context.args.position === 'fixed'
131-
? html`<img src="../images/browser-bg-top.png" />`
132-
: ''}
133-
<div class="position-container position-relative">
134-
${story()}
135-
${bombArgs({
136-
start: ['0', '50', '100'],
137-
top: ['0', '50', '100'],
138-
}).map(
139-
args => html` <div class="pos-element top-${args.top} start-${args.start}"></div> `,
140-
)}
141-
</div>
122+
(story, context) => html`
123+
<div class="position-outer-container position-outer-container-${context.args.position}">
124+
${context.args.position === 'fixed' ? html`<img src="../images/browser-bg-top.png" />` : ''}
125+
<div class="position-container position-relative">
126+
${story()}
127+
${bombArgs({
128+
start: ['0', '50', '100'],
129+
bottom: ['0', '50', '100'],
130+
top: ['0', '50', '100'],
131+
end: ['0', '50', '100'],
132+
}).map(
133+
args => html` <div class="pos-element top-${args.top} start-${args.start}"></div> `,
134+
)}
142135
</div>
143-
`,
136+
</div>
137+
`,
144138
],
145139
};
146140

@@ -149,7 +143,7 @@ export const TranslateMiddle: Story = {
149143
story => html` <div class="translate-middle-container position-relative">${story()}</div> `,
150144
],
151145
render: () => {
152-
return html`<div class="position-absolute start-50 top-50"></div>
146+
return html` <div class="position-absolute start-50 top-50"></div>
153147
<div class="position-absolute start-50 top-50 translate-middle"></div>`;
154148
},
155149
};

packages/documentation/src/stories/utilities/position/position.styles.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,16 @@
6161

6262
.my-element {
6363
background: post.$yellow;
64+
min-width: 2rem;
65+
min-height: 2rem;
66+
border-radius: post.$border-radius;
67+
}
68+
69+
.position-relative & {
6470
width: 2rem;
6571
height: 2rem;
66-
border-radius: post.$border-radius;
72+
min-width: unset;
73+
min-height: unset;
6774
}
6875
}
6976

packages/styles/src/utilities/_variables.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,20 +446,22 @@ $utilities: (
446446
values: static relative absolute fixed sticky,
447447
),
448448
'top': (
449-
property: top,
449+
property: inset-block-start,
450+
class: top,
450451
values: $position-values,
451452
),
452453
'bottom': (
453-
property: bottom,
454+
property: inset-block-end,
455+
class: bottom,
454456
values: $position-values,
455457
),
456458
'start': (
457-
property: left,
459+
property: inset-inline-start,
458460
class: start,
459461
values: $position-values,
460462
),
461463
'end': (
462-
property: right,
464+
property: inset-inline-end,
463465
class: end,
464466
values: $position-values,
465467
),

0 commit comments

Comments
 (0)