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

Use logical instead of physical block margins #206

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
13 changes: 13 additions & 0 deletions .changeset/nice-flowers-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@capsizecss/core': major
---

Use logical instead of physical block margins

Capsize does not work on text, that is rotated 90deg (using [`writing-mode: vertical-lr;`](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode)).
The current implementation always applies `margin-top` and `margin-bottom`, regardless of the actual orientation.

This change replaces `margin-top` with `margin-block-start` and `margin-bottom` with `margin-block-end`, as these properties respect aforementioned text orientation.

From [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block#syntax):
> This property corresponds to the [margin-top](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-top) and [margin-bottom](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-bottom), or the [margin-right](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-right) and [margin-left](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-left) properties, depending on the values defined for [writing-mode](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode), [direction](https://developer.mozilla.org/en-US/docs/Web/CSS/direction), and [text-orientation](https://developer.mozilla.org/en-US/docs/Web/CSS/text-orientation).
michaeltaranto marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions packages/core/src/createStyleObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ describe('createStyleObject', () => {
"::after": {
"content": "''",
"display": "table",
"marginTop": "-0.2626em",
"marginBlockStart": "-0.2626em",
},
"::before": {
"content": "''",
"display": "table",
"marginBottom": "-0.2753em",
"marginBlockEnd": "-0.2753em",
},
"fontSize": "150px",
"lineHeight": "180px",
Expand All @@ -43,12 +43,12 @@ describe('createStyleObject', () => {
"::after": {
"content": "''",
"display": "table",
"marginTop": "-0.2375em",
"marginBlockStart": "-0.2375em",
},
"::before": {
"content": "''",
"display": "table",
"marginBottom": "-0.2502em",
"marginBlockEnd": "-0.2502em",
},
"fontSize": "150px",
"lineHeight": "normal",
Expand All @@ -68,12 +68,12 @@ describe('createStyleObject', () => {
"::after": {
"content": "''",
"display": "table",
"marginTop": "-0.2626em",
"marginBlockStart": "-0.2626em",
},
"::before": {
"content": "''",
"display": "table",
"marginBottom": "-0.2753em",
"marginBlockEnd": "-0.2753em",
},
"fontSize": "150px",
"lineHeight": "180px",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/createStyleObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const _createStyleObject = ({
lineHeight,
'::before': {
content: "''",
marginBottom: capHeightTrim,
marginBlockEnd: capHeightTrim,
display: 'table',
},
'::after': {
content: "''",
marginTop: baselineTrim,
marginBlockStart: baselineTrim,
display: 'table',
},
};
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/createStyleString.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('createStyleString', () => {

.testClassName::before {
content: "";
margin-bottom: -0.2753em;
margin-block-end: -0.2753em;
display: table;
}

.testClassName::after {
content: "";
margin-top: -0.2626em;
margin-block-start: -0.2626em;
display: table;
}"
`);
Expand All @@ -50,13 +50,13 @@ describe('createStyleString', () => {

.testClassName::before {
content: "";
margin-bottom: -0.2753em;
margin-block-end: -0.2753em;
display: table;
}

.testClassName::after {
content: "";
margin-top: -0.2626em;
margin-block-start: -0.2626em;
display: table;
}"
`);
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Preview = () => {
backgroundSize: `100% ${resolvedCapHeightFromFontSize + lineGap}px`,
backgroundPosition: `0 calc((${
(resolvedCapHeightFromFontSize + lineGap - lineHeightNormal) / 2
}px) + ${capsizeStyles?.['::before'].marginBottom})`,
}px) + ${capsizeStyles?.['::before'].marginBlockEnd})`,
}
: {
...highlightGradient(
Expand All @@ -100,7 +100,7 @@ const Preview = () => {
),
backgroundPosition: `0 calc((${
(leading - lineHeightNormal) / 2
}px) + ${capsizeStyles?.['::before'].marginBottom})`,
}px) + ${capsizeStyles?.['::before'].marginBlockEnd})`,
},
leading: {
backgroundImage: `linear-gradient(180deg, transparent ${leading}px, ${highlight} ${leading}px, ${highlight} ${
Expand Down