Skip to content

Commit 4ef4996

Browse files
committed
update FAQ, add mobile related pages, link from RAC styling
1 parent 0b2751d commit 4ef4996

File tree

6 files changed

+90
-45
lines changed

6 files changed

+90
-45
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@ With this configured, all states for React Aria Components can be accessed with
252252
</ListBoxItem>
253253
```
254254

255+
## Style macro
256+
257+
If you want to build custom components that follow Spectrum design tokens and styling, you can use the [style macro](../s2/styling.html) from React Spectrum. The `style` macro is a build-time CSS generator that provides type safe access to Spectrum 2 design tokens including colors, spacing, sizing, and typography.
258+
259+
```tsx
260+
import {Checkbox} from 'react-aria-components';
261+
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
262+
263+
<Checkbox
264+
className={style({
265+
backgroundColor: {
266+
default: 'gray-100',
267+
isHovered: 'gray-200',
268+
isSelected: 'gray-900'
269+
}
270+
})}
271+
/>
272+
```
273+
255274
## Animation
256275

257276
React Aria Components supports both [CSS transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions) and [keyframe animations](https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes), and works with JavaScript animation libraries like [Framer Motion](https://www.framer.com/motion/).

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {InlineAlert, Heading, Content, Link} from '@react-spectrum/s2';
33
import {S2Colors} from '../../src/S2Colors';
44
import {S2Typography} from '../../src/S2Typography';
55
import {S2StyleProperties} from '../../src/S2StyleProperties';
6+
import {S2FAQ} from '../../src/S2FAQ';
67
export default Layout;
78

89
export const section = 'Guides';
@@ -241,21 +242,4 @@ we have MCP servers for [React Aria](#TODO) and [React Spectrum](https://www.npm
241242

242243
## FAQ
243244

244-
> I'm getting a "Could not statically evaluate macro argument" error.
245-
246-
This indicates that your `style` macro has a condition that isn't evaluable at build time. This can happen for a variety of reasons such
247-
as if you've referenced non-constant variables within your `style` macro or if you've called non-macro functions within your `style` macro.
248-
If you are using Typescript, it can be as simple as forgetting to add `as const` to your own defined reusable macro.
249-
250-
> I'm seeing a ton of duplicate rules being generated and/or my dev tools are very slow.
251-
252-
Please make sure you've followed the [best practices listed above](#css-optimization).
253-
254-
> I tried to pass my `style` macro to `UNSAFE_className` but it doesn't work.
255-
256-
The `style` macro is not meant to be used with `UNSAFE_className`. Overrides to the Spectrum styles is highly discouraged,
257-
consider styling an equivalent React Aria Component instead.
258-
259-
> I'm coming from S1, but where are Flex/Grid/etc?
260-
261-
These no longer exist. Please style `<div>`, `<span>`, and other standard HTML elements with the `style` macro instead.
245+
<S2FAQ />

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,6 @@ const components = {
3131
p: ({children, ...props}) => <p {...props} className={style({font: {default: 'body', lg: 'body-lg'}, marginY: 24})}>{children}</p>,
3232
ul: (props) => <ul {...props} />,
3333
li: ({children, ...props}) => <li {...props} className={style({font: {default: 'body', lg: 'body-lg'}, marginY: 0})}>{children}</li>,
34-
blockquote: ({children, ...props}) => (
35-
<blockquote
36-
{...props}
37-
className={style({
38-
borderStartWidth: 4,
39-
borderEndWidth: 0,
40-
borderTopWidth: 0,
41-
borderBottomWidth: 0,
42-
borderStyle: 'solid',
43-
borderColor: 'gray-400',
44-
paddingStart: 12,
45-
font: {default: 'body', lg: 'body-lg'},
46-
margin: 'unset'
47-
})}>
48-
{children}
49-
</blockquote>
50-
),
5134
Figure: (props) => <figure {...props} className={style({display: 'flex', flexDirection: 'column', alignItems: 'center', marginY: 32, marginX: 0})} />,
5235
Caption: (props) => <figcaption {...props} className={style({font: 'body-sm'})} />,
5336
CodeBlock: CodeBlock,
@@ -243,6 +226,9 @@ export function Layout(props: PageProps & {children: ReactElement<any>}) {
243226
<article
244227
className={articleStyles({isWithToC: hasToC})}>
245228
{React.cloneElement(children, {components})}
229+
{currentPage.exports?.relatedPages && (
230+
<MobileRelatedPages pages={currentPage.exports.relatedPages} />
231+
)}
246232
</article>
247233
<aside
248234
className={style({
@@ -306,6 +292,35 @@ function RelatedPages({pages}: {pages: Array<{title: string, url: string}>}) {
306292
);
307293
}
308294

295+
function MobileRelatedPages({pages}: {pages: Array<{title: string, url: string}>}) {
296+
const P = components.p;
297+
const Li = components.li;
298+
const Ul = components.ul;
299+
300+
return (
301+
<div
302+
className={style({
303+
display: {
304+
default: 'block',
305+
lg: 'none'
306+
}
307+
})}>
308+
<H2>Related pages</H2>
309+
<Ul>
310+
{pages.map((page, i) => (
311+
<Li key={i}>
312+
<P>
313+
<Link href={page.url}>
314+
{page.title}
315+
</Link>
316+
</P>
317+
</Li>
318+
))}
319+
</Ul>
320+
</div>
321+
);
322+
}
323+
309324
function MobileToc({toc, currentPage}) {
310325
let relatedPages = currentPage.exports?.relatedPages;
311326
return (

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Disclosure, DisclosurePanel, DisclosureTitle} from '@react-spectrum/s2';
2+
import React from 'react';
3+
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
4+
5+
export function S2FAQ() {
6+
return (
7+
<div className={style({display: 'flex', flexDirection: 'column', gap: 16})}>
8+
<Disclosure isQuiet>
9+
<DisclosureTitle>I'm getting a "Could not statically evaluate macro argument" error.</DisclosureTitle>
10+
<DisclosurePanel>
11+
This indicates that your <code>style</code> macro has a condition that isn't evaluable at build time. This can happen for a variety of reasons such
12+
as if you've referenced non-constant variables within your <code>style</code> macro or if you've called non-macro functions within your <code>style</code> macro.
13+
If you are using Typescript, it can be as simple as forgetting to add <code>as const</code> to your own defined reusable macro.
14+
</DisclosurePanel>
15+
</Disclosure>
16+
<Disclosure isQuiet>
17+
<DisclosureTitle>I'm seeing a ton of duplicate rules being generated and/or my dev tools are very slow.</DisclosureTitle>
18+
<DisclosurePanel>
19+
Please make sure you've followed the best practices listed above.
20+
</DisclosurePanel>
21+
</Disclosure>
22+
<Disclosure isQuiet>
23+
<DisclosureTitle>I tried to pass my <code>style</code> macro to <code>UNSAFE_className</code> but it doesn't work.</DisclosureTitle>
24+
<DisclosurePanel>
25+
The <code>style</code> macro is not meant to be used with <code>UNSAFE_className</code>. Overrides to the Spectrum styles is highly discouraged,
26+
consider styling an equivalent React Aria Component instead.
27+
</DisclosurePanel>
28+
</Disclosure>
29+
<Disclosure isQuiet>
30+
<DisclosureTitle>I'm coming from S1, but where are Flex/Grid/etc?</DisclosureTitle>
31+
<DisclosurePanel>
32+
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.
33+
</DisclosurePanel>
34+
</Disclosure>
35+
</div>
36+
);
37+
}

packages/dev/s2-docs/src/styleProperties.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ const negativeSpacingProperties = new Set([
4747
const baseSpacingValues = ['0', '2', '4', '8', '12', '16', '20', '24', '28', '32', '36', '40', '44', '48', '56', '64', '80', '96'];
4848
const negativeBaseSpacingValues = ['-2', '-4', '-8', '-12', '-16', '-20', '-24', '-28', '-32', '-36', '-40', '-44', '-48', '-56', '-64', '-80', '-96'];
4949
const relativeSpacingValues = ['text-to-control', 'text-to-visual', 'edge-to-text', 'pill'];
50-
// const spacingValues = [...baseSpacingValues, ...relativeSpacingValues];
51-
// const marginValues = [...spacingValues, ...negativeBaseSpacingValues, 'auto'];
52-
// const insetValues = [...baseSpacingValues, ...negativeBaseSpacingValues, 'auto', 'full'];
53-
// const translateValues = [...baseSpacingValues, ...negativeBaseSpacingValues, 'full'];
5450
const heightBaseValues = ['auto', 'full', 'min', 'max', 'fit', 'screen'];
5551
const fontSize = [
5652
'ui-xs', 'ui-sm', 'ui', 'ui-lg', 'ui-xl', 'ui-2xl', 'ui-3xl',
@@ -442,10 +438,6 @@ const properties: {[key: string]: {[key: string]: string[]}} = {
442438
conditions: conditionMapping
443439
};
444440

445-
// TODO: will we need something specific for short hand?
446-
// TODO: see if there are any others that we will need to add additional shared types for
447-
// this is less additional types and more that we want to represent the below as a type link
448-
// special custom types that should be appended to the property but need special handling (render a type popover)
449441
export function getAdditionalTypes(propertyName: string): string[] {
450442
let types: string[] = [];
451443

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,5 +856,3 @@ export function StyleMacroProperties({properties}: StyleMacroPropertiesProps) {
856856
</Table>
857857
);
858858
}
859-
860-
// TODO: For the Shorthands, have a column for Name, value (what values it accepts), and mapping where mapping is what properties it maps to

0 commit comments

Comments
 (0)