Skip to content

Commit b977f68

Browse files
committed
implement container, container-inline and container-block
These can all take modifiers for naming purposes.
1 parent 0b59ed8 commit b977f68

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

src/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import plugin from 'tailwindcss/plugin'
22
import { normalize } from 'tailwindcss/lib/util/dataTypes'
33

4-
export = plugin(function containerQueries({ matchVariant, theme }) {
4+
export = plugin(function containerQueries({ matchUtilities, matchVariant, theme }) {
55
let values: Record<string, string> = theme('containers') ?? {}
66

77
function parseValue(value: string): {
@@ -55,9 +55,28 @@ export = plugin(function containerQueries({ matchVariant, theme }) {
5555
}
5656
}
5757

58+
matchUtilities(
59+
{
60+
container: (value, { modifier }) => {
61+
return {
62+
'container-type': value,
63+
'container-name': modifier,
64+
}
65+
},
66+
},
67+
{
68+
values: {
69+
DEFAULT: 'inline',
70+
block: 'block',
71+
inline: 'inline',
72+
},
73+
modifiers: true,
74+
}
75+
)
76+
5877
matchVariant(
5978
'@',
60-
({ value = '', modifier }) => {
79+
(value = '', { modifier }) => {
6180
let parsed = parseValue(value)
6281

6382
return parsed !== null ? `@container ${modifier ?? ''} ${parsed.raw}` : []

tests/index.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ it('container queries', () => {
66
content: [
77
{
88
raw: html`
9-
<div>
9+
<div
10+
class="container container-block container-inline container/sidebar container-block/sidebar container-inline/sidebar container-[block] container-[block]/sidebar"
11+
>
1012
<div class="@md:underline"></div>
1113
<div class="@md/container1:underline"></div>
1214
<div class="@md/container2:underline"></div>
@@ -54,6 +56,46 @@ it('container queries', () => {
5456

5557
return run(input, config).then((result) => {
5658
expect(result.css).toMatchFormattedCss(css`
59+
.block {
60+
display: block;
61+
}
62+
63+
.container {
64+
container-type: inline;
65+
}
66+
67+
.container-block {
68+
container-type: block;
69+
}
70+
71+
.container-inline {
72+
container-type: inline;
73+
}
74+
75+
.container\/sidebar {
76+
container-type: inline;
77+
container-name: sidebar;
78+
}
79+
80+
.container-block\/sidebar {
81+
container-type: block;
82+
container-name: sidebar;
83+
}
84+
85+
.container-inline\/sidebar {
86+
container-type: inline;
87+
container-name: sidebar;
88+
}
89+
90+
.container-\[block\] {
91+
container-type: block;
92+
}
93+
94+
.container-\[block\]\/sidebar {
95+
container-type: block;
96+
container-name: sidebar;
97+
}
98+
5799
@container (min-width: 280px) and (max-width: 300px) {
58100
.\@\[\(min-width\:_280px\)_and_\(max-width\:_300px\)\]\:underline {
59101
text-decoration-line: underline;

0 commit comments

Comments
 (0)