Skip to content

Commit

Permalink
feat: added rounding to theme configuration capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Milfred committed Jun 4, 2024
1 parent 069a617 commit 35f4e43
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/>
<div class="text-strong @fish:bg-[red]">Test?</div>
</div>
<div class="bg-primary">
<div class="bg-primary px-layout-margin py-layout-gutter">
<div class="u-theme-default bg-primary border-3 border-danger">
<div class="text-onSurfaceDanger">Test?</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions .playground/assets/js/theme-configuration.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
export default {
// Testing only - set to false when done testing
minify: true, // Can be turned to false for a more readable output in the style tag
round: '1px', // Round to nearest pixel

// Setup
baseFontSize: 16, // For rem conversion
Expand Down
23 changes: 23 additions & 0 deletions components/ThemeConfiguration/ThemeConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,29 @@ function extractRules(
}
}
// Apply roundings
if (compConfig.value.round) {
[rules, mdScreenRules, lgScreenRules].forEach((ruleSet) => {
if (ruleSet.length === 0) return;
const roundTo =
typeof compConfig.value.round === 'boolean'
? '1px'
: typeof compConfig.value.round === 'number'
? `${compConfig.value.round}px`
: compConfig.value.round;
const roundedRules = [`@supports (padding: round(1%, ${roundTo})) {`];
ruleSet.forEach((rule) => {
const ruleParts = rule.split(': ');
const property = ruleParts[0];
const value = ruleParts[1].substring(0, ruleParts[1].length - 1);
roundedRules.push(`${property}: round(${value}, ${roundTo});`);
});
ruleSet.push(...roundedRules, '}');
});
}
// Return rules
if (compConfig.value.minify) {
return {
Expand Down

0 comments on commit 35f4e43

Please sign in to comment.