Skip to content

Use logical properties #246

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changeset/nasty-buttons-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'tailwindcss-capsize': minor
---

Use logical properties

Applies negative margins to `margin-block-end` and `margin-block-start` instead of `margin-bottom` and `margin-top`. This allows the utility to work as expected on text with different `writing-mode` values.
64 changes: 32 additions & 32 deletions __tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Plugin', () => {
.capsize::before {
display: table;
content: '';
margin-bottom: calc(
margin-block-end: calc(
(
(var(--ascent-scale) - var(--cap-height-scale) + var(--line-gap-scale) / 2) - var(
--line-height-offset
Expand All @@ -113,7 +113,7 @@ describe('Plugin', () => {
.capsize::after {
display: table;
content: '';
margin-top: calc(
margin-block-start: calc(
((var(--descent-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) *
-1em
);
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('Plugin', () => {
.capsize::before {
display: table;
content: '';
margin-bottom: calc(
margin-block-end: calc(
(
(var(--ascent-scale) - var(--cap-height-scale) + var(--line-gap-scale) / 2) - var(
--line-height-offset
Expand All @@ -223,7 +223,7 @@ describe('Plugin', () => {
.capsize::after {
display: table;
content: '';
margin-top: calc(
margin-block-start: calc(
((var(--descent-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) *
-1em
);
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('Plugin', () => {
.capsize::before {
display: table;
content: '';
margin-bottom: calc(
margin-block-end: calc(
(
(var(--ascent-scale) - var(--cap-height-scale) + var(--line-gap-scale) / 2) - var(
--line-height-offset
Expand All @@ -308,7 +308,7 @@ describe('Plugin', () => {
.capsize::after {
display: table;
content: '';
margin-top: calc(
margin-block-start: calc(
((var(--descent-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) *
-1em
);
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('Plugin', () => {
.capsize::before {
display: table;
content: "";
margin-bottom: calc(
margin-block-end: calc(
((var(--ascent-scale) - var(--cap-height-scale) + var(--line-gap-scale) / 2) -
var(--line-height-offset)) * -1em
);
Expand All @@ -360,7 +360,7 @@ describe('Plugin', () => {
.capsize::after {
display: table;
content: "";
margin-top: calc(
margin-block-start: calc(
((var(--descent-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) * -1em
);
}
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('Plugin', () => {
.leading-trim::before {
display: table;
content: "";
margin-bottom: calc(
margin-block-end: calc(
((var(--ascent-scale) - var(--cap-height-scale) + var(--line-gap-scale) / 2) -
var(--line-height-offset)) * -1em
);
Expand All @@ -417,7 +417,7 @@ describe('Plugin', () => {
.leading-trim::after {
display: table;
content: "";
margin-top: calc(
margin-block-start: calc(
((var(--descent-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) * -1em
);
}
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-sm.capsize::before,
.text-sm .font-sans .leading-sm.capsize::before {
content: '';
margin-bottom: -0.3506em;
margin-block-end: -0.3506em;
display: table;
}

Expand All @@ -460,7 +460,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-sm.capsize::after,
.text-sm .font-sans .leading-sm.capsize::after {
content: '';
margin-top: -0.3506em;
margin-block-start: -0.3506em;
display: table;
}

Expand All @@ -470,7 +470,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.capsize::before,
.text-sm .font-sans .leading-md.capsize::before {
content: '';
margin-bottom: -1.0649em;
margin-block-end: -1.0649em;
display: table;
}

Expand All @@ -480,7 +480,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.capsize::after,
.text-sm .font-sans .leading-md.capsize::after {
content: '';
margin-top: -1.0649em;
margin-block-start: -1.0649em;
display: table;
}

Expand All @@ -490,7 +490,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-sm.capsize::before,
.text-md .font-sans .leading-sm.capsize::before {
content: '';
margin-bottom: -0.053em;
margin-block-end: -0.053em;
display: table;
}

Expand All @@ -500,7 +500,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-sm.capsize::after,
.text-md .font-sans .leading-sm.capsize::after {
content: '';
margin-top: -0.053em;
margin-block-start: -0.053em;
display: table;
}

Expand All @@ -510,7 +510,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-md.capsize::before,
.text-md .font-sans .leading-md.capsize::before {
content: '';
margin-bottom: -0.4697em;
margin-block-end: -0.4697em;
display: table;
}

Expand All @@ -520,7 +520,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-md.capsize::after,
.text-md .font-sans .leading-md.capsize::after {
content: '';
margin-top: -0.4697em;
margin-block-start: -0.4697em;
display: table;
}
`),
Expand Down Expand Up @@ -550,7 +550,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-sm.capsize::before,
.text-sm .font-sans .leading-sm.capsize::before {
content: '';
margin-bottom: -0.3506em;
margin-block-end: -0.3506em;
display: table;
}

Expand All @@ -560,7 +560,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-sm.capsize::after,
.text-sm .font-sans .leading-sm.capsize::after {
content: '';
margin-top: -0.3506em;
margin-block-start: -0.3506em;
display: table;
}

Expand All @@ -570,7 +570,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.capsize::before,
.text-sm .font-sans .leading-md.capsize::before {
content: '';
margin-bottom: -0.7078em;
margin-block-end: -0.7078em;
display: table;
}

Expand All @@ -580,7 +580,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.capsize::after,
.text-sm .font-sans .leading-md.capsize::after {
content: '';
margin-top: -0.7078em;
margin-block-start: -0.7078em;
display: table;
}

Expand All @@ -590,7 +590,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-sm.capsize::before,
.text-md .font-sans .leading-sm.capsize::before {
content: '';
margin-bottom: -0.1919em;
margin-block-end: -0.1919em;
display: table;
}

Expand All @@ -600,7 +600,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-sm.capsize::after,
.text-md .font-sans .leading-sm.capsize::after {
content: '';
margin-top: -0.1919em;
margin-block-start: -0.1919em;
display: table;
}

Expand All @@ -610,7 +610,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-md.capsize::before,
.text-md .font-sans .leading-md.capsize::before {
content: '';
margin-bottom: -0.4697em;
margin-block-end: -0.4697em;
display: table;
}

Expand All @@ -620,7 +620,7 @@ describe('Plugin', () => {
.text-md .font-sans.leading-md.capsize::after,
.text-md .font-sans .leading-md.capsize::after {
content: '';
margin-top: -0.4697em;
margin-block-start: -0.4697em;
display: table;
}
`),
Expand Down Expand Up @@ -649,7 +649,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-sm.capsize::before,
.text-sm .font-sans .leading-sm.capsize::before {
content: '';
margin-bottom: -0.1364em;
margin-block-end: -0.1364em;
display: table;
}

Expand All @@ -659,7 +659,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-sm.capsize::after,
.text-sm .font-sans .leading-sm.capsize::after {
content: '';
margin-top: -0.1364em;
margin-block-start: -0.1364em;
display: table;
}

Expand All @@ -669,7 +669,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.capsize::before,
.text-sm .font-sans .leading-md.capsize::before {
content: '';
margin-bottom: -0.3864em;
margin-block-end: -0.3864em;
display: table;
}

Expand All @@ -679,7 +679,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.capsize::after,
.text-sm .font-sans .leading-md.capsize::after {
content: '';
margin-top: -0.3864em;
margin-block-start: -0.3864em;
display: table;
}
`),
Expand Down Expand Up @@ -717,7 +717,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.leading-trim::before,
.text-sm .font-sans .leading-md.leading-trim::before {
content: '';
margin-bottom: -0.3864em;
margin-block-end: -0.3864em;
display: table;
}

Expand All @@ -727,7 +727,7 @@ describe('Plugin', () => {
.text-sm .font-sans.leading-md.leading-trim::after,
.text-sm .font-sans .leading-md.leading-trim::after {
content: '';
margin-top: -0.3864em;
margin-block-start: -0.3864em;
display: table;
}
`),
Expand Down
16 changes: 12 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ export default plugin.withOptions<Partial<PluginOptions>>(
})

utilities[makeCssSelectors(fontFamily, sizeName, leading, className)] = {
'&::before': before,
'&::after': after,
'&::before': {
content: before.content,
marginBlockEnd: before.marginBottom,
display: before.display,
},
'&::after': {
content: after.content,
marginBlockStart: after.marginTop,
display: after.display,
},
}
}
}
Expand Down Expand Up @@ -155,13 +163,13 @@ export default plugin.withOptions<Partial<PluginOptions>>(
'&::before': {
display: 'table',
content: '""',
'margin-bottom':
'margin-block-end':
'calc(((var(--ascent-scale) - var(--cap-height-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) * -1em)',
},
'&::after': {
display: 'table',
content: '""',
'margin-top':
'margin-block-start':
'calc(((var(--descent-scale) + var(--line-gap-scale) / 2) - var(--line-height-offset)) * -1em)',
},
},
Expand Down
Loading