Skip to content

Commit 571bccb

Browse files
authored
Setup box sizing (#138)
* Add postcss box-sizing plugin * Remove unnecessary box-sizing declarations * Formatting fixes * Bump version to 1.0.0-beta.23
1 parent 89e43fb commit 571bccb

13 files changed

Lines changed: 70 additions & 19 deletions

File tree

packages/ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@synergycodes/overflow-ui",
33
"type": "module",
4-
"version": "1.0.0-beta.22",
4+
"version": "1.0.0-beta.23",
55
"description": "A React library for creating node-based UIs and diagram-driven applications. Perfect for React Flow users, providing ready-to-use node templates and components that work seamlessly with React Flow's ecosystem.",
66
"keywords": [
77
"react",
@@ -66,6 +66,7 @@
6666
"@vitejs/plugin-react": "^4.3.4",
6767
"eslint-plugin-react": "^7.37.4",
6868
"eslint-plugin-react-hooks": "^5.2.0",
69+
"postcss": "^8.5.3",
6970
"react": "^18.3.1",
7071
"react-dom": "^18.3.1",
7172
"typescript": "^5.6.3",

packages/ui/postcss-box-sizing.mts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { Plugin } from 'postcss';
2+
3+
/**
4+
* PostCSS plugin that adds `box-sizing: border-box` to every rule
5+
* in CSS Module files (*.module.css). This ensures all library
6+
* components use border-box sizing without leaking styles to users.
7+
*/
8+
export function boxSizingPlugin(): Plugin {
9+
return {
10+
postcssPlugin: 'postcss-box-sizing',
11+
prepare() {
12+
return {
13+
OnceExit(root) {
14+
const file = root.source?.input?.file ?? '';
15+
if (!file.endsWith('.module.css')) return;
16+
17+
root.walkRules((rule) => {
18+
if (rule.selector === ':root') return;
19+
20+
const hasDeclarations = rule.nodes?.some(
21+
(node) => node.type === 'decl',
22+
);
23+
24+
// Skip rules that only contain nested rules (no declarations).
25+
// Adding box-sizing to such container rules would leak to unintended elements
26+
if (!hasDeclarations) return;
27+
28+
const hasBoxSizing = rule.nodes?.some(
29+
(node) => node.type === 'decl' && node.prop === 'box-sizing',
30+
);
31+
32+
if (!hasBoxSizing) {
33+
rule.prepend({ prop: 'box-sizing', value: 'border-box' });
34+
}
35+
});
36+
},
37+
};
38+
},
39+
};
40+
}
41+
42+
boxSizingPlugin.postcss = true;

packages/ui/src/components/avatar/avatar.module.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
justify-content: center;
2020

2121
&.extra-large {
22-
width: 2.5rem;
23-
height: 2.5rem;
22+
width: calc(2.5rem + 2 * var(--ax-public-avatar-border-size));
23+
height: calc(2.5rem + 2 * var(--ax-public-avatar-border-size));
2424
}
2525

2626
&.large {
27-
width: 2rem;
28-
height: 2rem;
27+
width: calc(2rem + 2 * var(--ax-public-avatar-border-size));
28+
height: calc(2rem + 2 * var(--ax-public-avatar-border-size));
2929
}
3030

3131
&.medium {
32-
width: 1.5rem;
33-
height: 1.5rem;
32+
width: calc(1.5rem + 2 * var(--ax-public-avatar-border-size));
33+
height: calc(1.5rem + 2 * var(--ax-public-avatar-border-size));
3434
}
3535

3636
&.small {
37-
width: 1.125rem;
38-
height: 1.125rem;
37+
width: calc(1.125rem + 2 * var(--ax-public-avatar-border-size));
38+
height: calc(1.125rem + 2 * var(--ax-public-avatar-border-size));
3939
}
4040

4141
img {

packages/ui/src/components/collapsible/collapsible.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
overflow: hidden;
2323
transition: grid-template-rows
2424
var(--ax-public-collapsible-transition-duration) ease;
25-
box-sizing: border-box;
2625

2726
&.expanded {
2827
overflow: unset;

packages/ui/src/components/modal/modal.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
align-items: center;
6464
justify-content: center;
6565
height: 100vh;
66-
box-sizing: border-box;
6766
padding: 1.5rem;
6867
overflow: auto;
6968
}

packages/ui/src/components/segment-picker/segment-picker.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
&:not(.circle) {
2424
width: 100%;
25-
box-sizing: border-box;
2625
}
2726
}
2827
}

packages/ui/src/components/snackbar/snackbar.module.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@
7272

7373
.container {
7474
display: flex;
75-
width: var(--ax-public-snackbar-width);
75+
width: calc(
76+
var(--ax-public-snackbar-width) + 2 *
77+
var(--ax-token-spacing-snackbar-h-pad-1) + 2 *
78+
var(--ax-public-snackbar-border-size)
79+
);
7680
border: var(--ax-public-snackbar-border-size) solid
7781
var(--ax-public-snackbar-default-border);
7882
border-radius: var(--ax-public-snackbar-border-radius);

packages/ui/src/components/switch/switch.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
border-radius: 100px;
3434
border: var(--ax-public-switch-border-size) solid
3535
var(--ax-public-switch-outline-color);
36-
box-sizing: border-box;
3736

3837
&:not(:hover) {
3938
transition: background-color var(--ax-public-transition);

packages/ui/src/components/tooltip/tooltip.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
.container {
1212
padding: var(--ax-public-tooltip-padding);
1313
border-radius: var(--ax-public-tooltip-radius-size);
14-
box-sizing: border-box;
1514
width: max-content;
1615
max-width: 33vw;
1716
z-index: 100;

packages/ui/src/shared/styles/list-item.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
border-radius: var(--ax-public-list-border-radius);
3232
width: max-content;
3333
min-width: 100%;
34-
box-sizing: border-box;
3534
cursor: pointer;
3635
color: var(--ax-public-list-item-color);
3736

0 commit comments

Comments
 (0)