@kaizen/tailwind 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -102,7 +102,7 @@ var kaizenTailwindTheme = {
|
|
|
102
102
|
screens: {
|
|
103
103
|
md: js.tokens.layout.breakpoints.medium,
|
|
104
104
|
// => @media (min-width: 768px) { ... }
|
|
105
|
-
lg: js.tokens.layout.breakpoints.large // => @media (min-width:
|
|
105
|
+
lg: js.tokens.layout.breakpoints.large // => @media (min-width: 1024px) { ... }
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
var Preset = {
|
|
@@ -100,7 +100,7 @@ var kaizenTailwindTheme = {
|
|
|
100
100
|
screens: {
|
|
101
101
|
md: tokens.layout.breakpoints.medium,
|
|
102
102
|
// => @media (min-width: 768px) { ... }
|
|
103
|
-
lg: tokens.layout.breakpoints.large // => @media (min-width:
|
|
103
|
+
lg: tokens.layout.breakpoints.large // => @media (min-width: 1024px) { ... }
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
var Preset = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaizen/tailwind",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Kaizen Tailwind presets",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,17 +26,18 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@cultureamp/package-bundler": "^2.3.2",
|
|
29
|
+
"@tailwindcss/container-queries": "^0.1.1",
|
|
29
30
|
"classnames": "^2.5.1",
|
|
30
|
-
"rollup": "^4.46.2",
|
|
31
31
|
"react": "^19.1.0",
|
|
32
32
|
"react-dom": "^19.1.0",
|
|
33
|
+
"rollup": "^4.46.2",
|
|
33
34
|
"tailwindcss": "^3.4.17",
|
|
34
35
|
"tslib": "^2.8.1"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"tailwindcss": ">=3.4.7",
|
|
38
38
|
"react": "^18.3.1 || ^19.0.0",
|
|
39
|
-
"react-dom": "^18.3.1 || ^19.0.0"
|
|
39
|
+
"react-dom": "^18.3.1 || ^19.0.0",
|
|
40
|
+
"tailwindcss": ">=3.4.7"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "pnpm package-bundler build",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Description, Meta, Story } from '@storybook/blocks'
|
|
2
|
+
import * as Examples from './container-queries.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={Examples} />
|
|
5
|
+
|
|
6
|
+
# Container Queries
|
|
7
|
+
|
|
8
|
+
<Description />
|
|
9
|
+
|
|
10
|
+
Container queries allow you to apply styles based on the size of a container rather than the viewport. This is especially useful for creating truly reusable components that adapt to their context.
|
|
11
|
+
|
|
12
|
+
## Fallback container parent
|
|
13
|
+
|
|
14
|
+
The Kaizen design system includes a fallback container parent in the `_reset.css` file:
|
|
15
|
+
|
|
16
|
+
```css
|
|
17
|
+
body {
|
|
18
|
+
container-type: inline-size;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
This means that if you use container query classes (like `@md:bg-blue-400`) without explicitly adding an `@container` parent, the body element will act as the container context. In this case, container queries will functionally behave the same as viewport media queries, making the transition from media queries to container queries non-breaking for existing components.
|
|
23
|
+
|
|
24
|
+
## Preset container queries
|
|
25
|
+
|
|
26
|
+
Container queries work by establishing a containment context on a parent element using the `@container` class, then applying conditional styles to child elements using the `@` prefix.
|
|
27
|
+
|
|
28
|
+
<Story of={Examples.ContainerQueries} />
|
|
29
|
+
|
|
30
|
+
## Using arbitrary values
|
|
31
|
+
|
|
32
|
+
For one-off container sizes that don't match your configured breakpoints, you can use arbitrary values in square brackets.
|
|
33
|
+
|
|
34
|
+
<Story of={Examples.ArbitraryContainerQueries} />
|
|
35
|
+
|
|
36
|
+
## Named containers
|
|
37
|
+
|
|
38
|
+
When you have nested containers, you can use named containers to query specific containers by name. This prevents conflicts where a child element might respond to the wrong container.
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
<div className="mt-12 border-1 border-dashed border-purple-300 p-8">
|
|
42
|
+
<Text variant="body">
|
|
43
|
+
<strong>Outer container ("sidebar") - resize to see effect</strong>
|
|
44
|
+
</Text>
|
|
45
|
+
<div className="@container/sidebar mt-4 resize overflow-auto border-2 border-blue-300">
|
|
46
|
+
<div className="p-4">
|
|
47
|
+
<Text variant="body">
|
|
48
|
+
<strong>Inner container ("card")</strong>
|
|
49
|
+
</Text>
|
|
50
|
+
<div className="@container/card mt-2 border border-gray-300 p-2">
|
|
51
|
+
<div className="@md/sidebar:bg-green-400 h-[50px] w-full rounded border-solid">
|
|
52
|
+
<div className="flex h-full items-center justify-center text-xs">
|
|
53
|
+
<Text variant="body">Responds to sidebar container</Text>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
<Story of={Examples.NamedContainers} />
|
|
63
|
+
|
|
64
|
+
## Best practices
|
|
65
|
+
|
|
66
|
+
- **For container behavior**: Always establish a containment context with `@container` (or named `@container/name`) on the parent element
|
|
67
|
+
- **Fallback behavior**: Without an explicit `@container` parent, container queries will use the body element and behave like viewport media queries
|
|
68
|
+
- Container queries respond to the **container's** size, not the viewport size (unless using the body fallback)
|
|
69
|
+
- Use named containers when you have nested container contexts
|
|
70
|
+
- Combine container queries with regular responsive design for optimal flexibility
|
|
71
|
+
- Container queries work great for component-level responsive design
|
|
72
|
+
- The fallback body container makes migrating from media queries to container queries seamless
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { type Meta, type StoryFn } from '@storybook/react'
|
|
3
|
+
import { Heading } from '~components/Heading'
|
|
4
|
+
import { Text } from '~components/Text'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Guides/Tailwind/Utility Class References/Modifiers/Container Queries',
|
|
8
|
+
parameters: {
|
|
9
|
+
docsLayout: 'fullPage',
|
|
10
|
+
docs: {
|
|
11
|
+
a11y: { disable: true },
|
|
12
|
+
description: {
|
|
13
|
+
component: 'Require @kaizen/tailwind and add it into your tailwind config',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
} satisfies Meta
|
|
18
|
+
|
|
19
|
+
type ContainerQueryInfoProps = {
|
|
20
|
+
selector: string
|
|
21
|
+
selectorValue: string
|
|
22
|
+
children: React.ReactElement
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ContainerQueryInfo = ({
|
|
26
|
+
selector,
|
|
27
|
+
selectorValue,
|
|
28
|
+
children,
|
|
29
|
+
}: ContainerQueryInfoProps): React.ReactElement => (
|
|
30
|
+
<div className="my-12">
|
|
31
|
+
<Text variant="intro-lede">Container query selector: @{selector}</Text>
|
|
32
|
+
<Text variant="body">Breakpoint: {selectorValue}</Text>
|
|
33
|
+
<Text variant="body">In this example: @{selector}:bg-blue-400</Text>
|
|
34
|
+
{/* Container wrapper to demonstrate container queries */}
|
|
35
|
+
<div className="mt-12 border-2 border-dashed border-purple-300 p-8">
|
|
36
|
+
<Text variant="body">
|
|
37
|
+
<strong>Container wrapper (resize to see effect)</strong>
|
|
38
|
+
</Text>
|
|
39
|
+
<div className="mt-4 resize overflow-auto border border-gray-300">{children}</div>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
export const ContainerQueries: StoryFn = () => (
|
|
45
|
+
<div className="py-32">
|
|
46
|
+
<Heading tag="p" variant="heading-4" classNameOverride="mb-16">
|
|
47
|
+
Container query breakpoints activate based on the <em>container's</em> width, not the
|
|
48
|
+
viewport. These elements will change color when their parent container reaches the specified
|
|
49
|
+
width.
|
|
50
|
+
</Heading>
|
|
51
|
+
|
|
52
|
+
<ContainerQueryInfo selector="md" selectorValue="768px">
|
|
53
|
+
<div className="@container">
|
|
54
|
+
<div className="@md:bg-blue-400 h-[50px] w-full rounded border-solid" />
|
|
55
|
+
</div>
|
|
56
|
+
</ContainerQueryInfo>
|
|
57
|
+
|
|
58
|
+
<ContainerQueryInfo selector="lg" selectorValue="1080px">
|
|
59
|
+
<div className="@container">
|
|
60
|
+
<div className="@lg:bg-blue-400 h-[50px] w-full rounded border-solid" />
|
|
61
|
+
</div>
|
|
62
|
+
</ContainerQueryInfo>
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
export const ArbitraryContainerQueries: StoryFn = () => (
|
|
67
|
+
<div className="py-32">
|
|
68
|
+
<Heading tag="p" variant="heading-4" classNameOverride="mb-16">
|
|
69
|
+
Custom container query breakpoints can be created with arbitrary values.
|
|
70
|
+
</Heading>
|
|
71
|
+
|
|
72
|
+
<div className="my-12">
|
|
73
|
+
<Text variant="body">
|
|
74
|
+
<strong>Custom container width breakpoint</strong> (applied when the container gets wider
|
|
75
|
+
than 500px)
|
|
76
|
+
</Text>
|
|
77
|
+
<Text variant="body">In this example: @[500px]:bg-green-400</Text>
|
|
78
|
+
<div className="mt-12 border-2 border-dashed border-purple-300 p-8">
|
|
79
|
+
<Text variant="body">
|
|
80
|
+
<strong>Container wrapper (resize to see effect)</strong>
|
|
81
|
+
</Text>
|
|
82
|
+
<div className="@container mt-4 resize overflow-auto border border-gray-300">
|
|
83
|
+
<div className="@[500px]:bg-green-400 h-[50px] w-full rounded border-solid" />
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
export const NamedContainers: StoryFn = () => (
|
|
91
|
+
<div className="py-32">
|
|
92
|
+
<Heading tag="p" variant="heading-4" classNameOverride="mb-16">
|
|
93
|
+
Named containers allow you to query specific containers by name, useful when you have nested
|
|
94
|
+
containers.
|
|
95
|
+
</Heading>
|
|
96
|
+
|
|
97
|
+
<div className="my-12">
|
|
98
|
+
<Text variant="body">
|
|
99
|
+
<strong>Named container example</strong> - The inner element responds to the outer
|
|
100
|
+
"sidebar" container, not the inner "card" container
|
|
101
|
+
</Text>
|
|
102
|
+
<Text variant="body">In this example: @container/sidebar and @md/sidebar:bg-green-400</Text>
|
|
103
|
+
<div className="mt-12 border-1 border-dashed border-purple-300 p-8">
|
|
104
|
+
<Text variant="body">
|
|
105
|
+
<strong>Outer container ("sidebar") - resize to see effect</strong>
|
|
106
|
+
</Text>
|
|
107
|
+
<div className="@container/sidebar mt-4 resize overflow-auto border-2 border-blue-300">
|
|
108
|
+
<div className="p-4">
|
|
109
|
+
<Text variant="body">
|
|
110
|
+
<strong>Inner container ("card")</strong>
|
|
111
|
+
</Text>
|
|
112
|
+
<div className="@container/card mt-2 border border-gray-300 p-2">
|
|
113
|
+
<div className="@md/sidebar:bg-green-400 h-[50px] w-full rounded border-solid">
|
|
114
|
+
<div className="flex h-full items-center justify-center text-xs">
|
|
115
|
+
<Text variant="body">Responds to sidebar container</Text>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
package/src/tailwind-presets.ts
CHANGED
|
@@ -107,7 +107,7 @@ export const kaizenTailwindTheme: KaizenTailwindTheme = {
|
|
|
107
107
|
// A mix of layout styles
|
|
108
108
|
screens: {
|
|
109
109
|
md: tokens.layout.breakpoints.medium, // => @media (min-width: 768px) { ... }
|
|
110
|
-
lg: tokens.layout.breakpoints.large, // => @media (min-width:
|
|
110
|
+
lg: tokens.layout.breakpoints.large, // => @media (min-width: 1024px) { ... }
|
|
111
111
|
},
|
|
112
112
|
} as const
|
|
113
113
|
|