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

Utility API: improve class generation #4389

Open
alizedebray opened this issue Jan 7, 2025 · 0 comments · May be fixed by #4654
Open

Utility API: improve class generation #4389

alizedebray opened this issue Jan 7, 2025 · 0 comments · May be fixed by #4654
Assignees
Labels
📦 styles Related to the @swisspost/design-system-styles package

Comments

@alizedebray
Copy link
Contributor

With the current utility API you need one entry per class.
For example:

 'margin-top': (
    responsive: true,
    property: margin-top,
    class: mt,
    values: from-tokens('spacing', 'margin'),
  ),
 'margin-bottom': (
    responsive: true,
    property: margin-bottom,
    class: mb,
    values: from-tokens('spacing', 'margin'),
  ),
 'margin-y': (
    responsive: true,
    property: margin-top margin-bottom,
    class: my,
    values: from-tokens('spacing', 'margin'),
  ),

generates classes like:

.mt-1 { margin-top: 1px; }
.mt-2 { margin-top: 2px; }
.mt-3 { margin-top: 3px; }
.mb-1 { margin-bottom: 1px; }
.mb-2 { margin-bottom: 2px; }
.mb-3 { margin-bottom: 3px; }
.my-1 { margin-top: 1px; margin-bottom: 1px; }
.my-2 { margin-top: 2px; margin-bottom: 2px; }
.my-3 {margin-top: 3px;  margin-bottom: 3px; }

To reduce the CSS output we could improve the API to allow for multiple classes to be set at the same time like so:

 'margin-top': (
    responsive: true,
    property: margin-top,
    class: mt, my,
    values: from-tokens('spacing', 'margin'),
  ),
 'margin-bottom': (
    responsive: true,
    property: margin-bottom,
    class: mb, my,
    values: from-tokens('spacing', 'margin'),
  ),

and generate classes like:

.mt-1, .my-1 { margin-top: 1px; }
.mt-2, .my-2 { margin-top: 2px; }
.mt-3, .my-3 { margin-top: 3px; }
.mb-1, .my-1 { margin-bottom: 1px; }
.mb-2, .my-2 { margin-bottom: 2px; }
.mb-3, .my-3 { margin-bottom: 3px; }
@alizedebray alizedebray added the 📦 styles Related to the @swisspost/design-system-styles package label Jan 7, 2025
@alizedebray alizedebray added this to the Maintenance III milestone Jan 7, 2025
@gfellerph gfellerph moved this from 👀 Triage to 💻 Ready for development in Design System Production Board Jan 8, 2025
@leagrdv leagrdv self-assigned this Feb 4, 2025
@leagrdv leagrdv moved this from 💻 Ready for development to 🕹️ Coding in progress in Design System Production Board Feb 11, 2025
@leagrdv leagrdv linked a pull request Feb 12, 2025 that will close this issue
@leagrdv leagrdv moved this from 🕹️ Coding in progress to 🤬 Dev in Code Review in Design System Production Board Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 styles Related to the @swisspost/design-system-styles package
Projects
Status: 🤬 Dev in Code Review
Development

Successfully merging a pull request may close this issue.

2 participants