Skip to content

Commit d1b15be

Browse files
committed
Improve: Use config.screens instead of config.variables.screens
1 parent ea6e16c commit d1b15be

11 files changed

Lines changed: 93 additions & 52 deletions

File tree

packages/core/src/config/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import variables from './variables'
66
import rules from './rules'
77
import modes from './modes'
88
import functions from './functions'
9+
import screens from './screens'
910
import { Config } from '../types/config'
1011

1112
const config: Config = {
@@ -17,6 +18,7 @@ const config: Config = {
1718
animations,
1819
variables,
1920
modes,
21+
screens,
2022
scope: '',
2123
rootSize: 16,
2224
baseUnit: 4,
@@ -34,5 +36,6 @@ export {
3436
functions,
3537
animations,
3638
variables,
37-
modes
39+
modes,
40+
screens
3841
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ScreenDefinitions } from '../types/config'
2+
3+
const screens = {
4+
'4xs': 360,
5+
'3xs': 480,
6+
'2xs': 600,
7+
'xs': 768,
8+
'sm': 834,
9+
'md': 1024,
10+
'lg': 1280,
11+
'xl': 1440,
12+
'2xl': 1600,
13+
'3xl': 1920,
14+
'4xl': 2560,
15+
} satisfies ScreenDefinitions
16+
17+
export default screens

packages/core/src/config/variables.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ const _variables = {
66
fit: 'fit-content',
77
max: 'max-content',
88
min: 'min-content',
9-
screen: {
10-
'4xs': 360,
11-
'3xs': 480,
12-
'2xs': 600,
13-
'xs': 768,
14-
'sm': 834,
15-
'md': 1024,
16-
'lg': 1280,
17-
'xl': 1440,
18-
'2xl': 1600,
19-
'3xl': 1920,
20-
'4xl': 2560,
21-
},
229
'font-family': {
2310
mono: [
2411
'ui-monospace',

site/app/[locale]/reference/screens/_opengraph-image.tsx renamed to site/app/[locale]/guide/screens/_opengraph-image.tsx

File renamed without changes.

site/app/[locale]/reference/screens/components/Default.tsx renamed to site/app/[locale]/guide/screens/components/Default.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import DocTable from 'internal/components/DocTable'
2-
import { variables } from '@master/css'
2+
import { screens, variables } from '@master/css'
3+
import InlineCode from '~/internal/components/InlineCode'
34

45
const descriptions = {
56
'4xs': 'iPhone 6, 7, 8, X, 11, 12 / Galaxy S8 / HTC One…',
@@ -20,20 +21,22 @@ export default () => {
2021
<DocTable>
2122
<thead>
2223
<tr>
23-
<th className='w:0'>Token</th>
24+
<th className='w:0'>At</th>
25+
<th className='w:0'>Variable</th>
2426
<th className='w:0'>Value</th>
25-
<th className='w:0'>REM</th>
27+
<th className='w:0'></th>
2628
<th>Description</th>
2729
</tr>
2830
</thead>
2931
<tbody>
3032
{
31-
Object.entries(variables.screen)
33+
Object.entries(screens)
3234
.map(([name, value], index) => (
3335
<tr key={index}>
34-
<td className="white-space:nowrap"><code>screen-{name}</code></td>
35-
<td><code className='token number'>{value}</code></td>
36-
<td><code className='token number'>{value / 16}<span className='token unit'>rem</span></code></td>
36+
<th className="white-space:nowrap"><InlineCode>{`@${name}`}</InlineCode></th>
37+
<th className="white-space:nowrap"><InlineCode>{`screen-${name}`}</InlineCode></th>
38+
<td><InlineCode>{`${value}`}</InlineCode></td>
39+
<td><InlineCode>{`(${value / 16}rem)`}</InlineCode></td>
3740
<td>{descriptions[name as keyof typeof descriptions]}</td>
3841
</tr>
3942
))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
```js name=master.css.js
2+
export default {
3+
screens: {
4+
md: 1024, // [!code highlight]
5+
lg: 1280, // [!code highlight]
6+
}
7+
}
8+
```
9+
For example, a screen size token can be used in the following ways:
10+
```html
11+
<!-- @MARK @md -->
12+
<div class="font:32@md">…</div>
13+
<!-- @MARK screen-md -->
14+
<div class="max-w:screen-md">…</div>
15+
<!-- @MARK @container(md) -->
16+
<div class="hidden@container(md)">…</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Overview [sr-only]
2+
<Default />
3+
In Master CSS, the [screen sizes](/guide/screens) are simultaneously used as *responsive breakpoints*, *screen size variables*, and *container query sizes*.
4+
<Overview />
5+
6+
---
7+
8+
## Basic usage
9+
### Add a screen size
10+
Add a screen size token to `config.screens`.
11+
```js name=master.css.js
12+
export default {
13+
screens: {
14+
md: 1024, // [!code highlight]
15+
}
16+
}
17+
```
18+
Apply the screen size `screen-md` as a variable:
19+
```html
20+
<!-- @MARK @screen-md -->
21+
<div class="w:screen-md">…</div>
22+
```
23+
Apply the screen size `@md` as a responsive breakpoint:
24+
```html
25+
<!-- @MARK @md -->
26+
<div class="font:32@md">…</div>
27+
```
28+
Apply the screen size `(md)` as a container query:
29+
```html
30+
<!-- @MARK (md) -->
31+
<div class="hidden@container(md)">…</div>
32+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import define from 'internal/utils/metadata'
2+
3+
const metadata = define({
4+
title: 'Customizing Screen Sizes',
5+
description: 'A guide to adding custom screen sizes for breakpoints, containers, and variables.',
6+
category: 'Customization',
7+
other: {
8+
subject: 'Screen Sizes',
9+
},
10+
fileURL: import.meta.url
11+
})
12+
13+
export default metadata

site/app/[locale]/reference/screens/page.tsx renamed to site/app/[locale]/guide/screens/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function generateMetadata(props: any, parent: any) {
1111
return await generate(metadata, props, parent)
1212
}
1313

14-
import pageCategories from '~/site/.categories/reference.json'
14+
import pageCategories from '~/site/.categories/guide.json'
1515

1616
export default async function Page(props: any) {
1717
return (

site/app/[locale]/reference/screens/content.mdx

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)