Skip to content

Commit 4b38f98

Browse files
committed
addressing feedback from quarry team
1 parent 6e508f2 commit 4b38f98

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

packages/dev/s2-docs/pages/s2/reference.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The `style` macro supports a constrained set of values per property that conform
1717
## Colors
1818

1919
All Spectrum 2 color tokens are available across color properties (e.g., `backgroundColor`, `color`, `borderColor`).
20+
`baseColors` consists of the semantic and global colors listed below.
2021

2122
<S2Colors />
2223

packages/dev/s2-docs/pages/s2/styling.mdx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ React Spectrum includes a build-time `style` macro that generates atomic CSS and
1414

1515
## Style macro
1616

17-
The `style` macro runs at build time and returns a class name for applying Spectrum 2 design tokens (colors, spacing, sizing, typography, etc.).
17+
The `style` macro runs at build time and returns a class name for applying Spectrum 2 design tokens (colors, spacing, sizing, typography, etc.). As can been seen below,
18+
the keys of the object passed to the `style` macro correspond to a CSS property, each paired with the property's desired value. See [here](./reference.html) for a full list
19+
of supported values.
1820

1921
```tsx
2022
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
@@ -39,7 +41,7 @@ Colocating styles with your component code means:
3941
<InlineAlert variant="informative">
4042
<Heading>Important Note</Heading>
4143
<Content>
42-
Due to the atomic nature of the generated CSS rules, it is strongly recommended that you follow the best practices listed [below](#css-optimization).
44+
Due to the atomic nature of the generated CSS rules, it is strongly recommended that you follow the CSS optimization guide listed [below](#css-optimization).
4345
Failure to do so can result in large number of duplicate rules and obtuse styling bugs.
4446
</Content>
4547
</InlineAlert>
@@ -96,23 +98,28 @@ import {Button} from '@react-spectrum/s2';
9698
## Conditional styles
9799

98100
Define conditional values as objects to handle media queries, UI states (hover/press), and variants. This keeps all values for a property together.
99-
Note how the example below uses a predefined [breakpoint](./reference.html#conditions) alongside a custom media query.
100101

101102
```tsx
102103
<div
103104
className={style({
104105
padding: {
105106
default: 8,
106107
lg: 32,
107-
'@media (min-width: 2560px)': 64,
108+
'@media (min-width: 2560px)': 64
108109
}
109110
})}
110111
/>
111112
```
112113

114+
In the example above, the keys of the nested object now map out the "conditions" that govern the padding of the `div`. This translates to the following:
115+
116+
- If the viewport is larger than `2560px`, as specified by a user defined [media query](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries), the padding of the `div` is set to `64px`.
117+
- If the viewport matches the `style` macro's predefined `lg` [breakpoint](./reference.html#conditions) (i.e. the viewport is larger than `1024px`), but does not exceed previous condition, the padding of the `div` is set to `32px`
118+
- Otherwise, default to a padding of `8px`.
119+
113120
Conditions are mutually exclusive and ordered. The macro uses CSS cascade layers so the last matching condition wins without specificity issues.
114121

115-
## Runtime conditions
122+
### Runtime conditions
116123

117124
When runtime conditions are detected (e.g., variants, UI states), the macro returns a function to resolve styles at runtime.
118125

@@ -310,6 +317,8 @@ The `style` macro relies on CSS bundling and minification for optimal output. Fo
310317
- Use a CSS minifier like `lightningcss` to deduplicate common rules (consider in dev for easier debugging).
311318
- Bundle all CSS for S2 components and style macros into a single CSS bundle rather than code splitting to avoid duplicate rules across chunks.
312319

320+
**Failure to perform this optimization will result in a suboptimal developer experience and obtuse styling bugs.**
321+
313322
### Parcel
314323

315324
Parcel supports macros out of the box and optimizes CSS with [Lightning CSS](https://lightningcss.dev). You can bundle all S2 and macro CSS into a single file using [manual shared bundles](https://parceljs.org/features/code-splitting/#manual-shared-bundles).

packages/dev/s2-docs/src/S2FAQ.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Disclosure, DisclosurePanel, DisclosureTitle} from '@react-spectrum/s2';
1+
import {Disclosure, DisclosurePanel, DisclosureTitle, Link} from '@react-spectrum/s2';
22
import React from 'react';
33
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
44

@@ -32,6 +32,12 @@ export function S2FAQ() {
3232
These no longer exist. Please style <code>&lt;div&gt;</code>, <code>&lt;span&gt;</code>, and other standard HTML elements with the <code>style</code> macro instead.
3333
</DisclosurePanel>
3434
</Disclosure>
35+
<Disclosure isQuiet>
36+
<DisclosureTitle>Where can I find a list of what values are supported by the style macro?</DisclosureTitle>
37+
<DisclosurePanel>
38+
See the <Link href="./reference.html">following page</Link> for a full list of what values are supported by the <code>style</code> macro.
39+
</DisclosurePanel>
40+
</Disclosure>
3541
</div>
3642
);
3743
}

0 commit comments

Comments
 (0)