diff --git a/packages/dev/s2-docs/pages/react-aria/styling.mdx b/packages/dev/s2-docs/pages/react-aria/styling.mdx index c804858de12..68599ea7b74 100644 --- a/packages/dev/s2-docs/pages/react-aria/styling.mdx +++ b/packages/dev/s2-docs/pages/react-aria/styling.mdx @@ -242,25 +242,6 @@ With this configured, all states for React Aria Components can be accessed with ``` -## Style macro - -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. - -```tsx -import {Checkbox} from 'react-aria-components'; -import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; - - -``` - ## Animation 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 [Motion](https://motion.dev/). diff --git a/packages/dev/s2-docs/pages/s2/reference.mdx b/packages/dev/s2-docs/pages/s2/style-macro.mdx similarity index 100% rename from packages/dev/s2-docs/pages/s2/reference.mdx rename to packages/dev/s2-docs/pages/s2/style-macro.mdx diff --git a/packages/dev/s2-docs/pages/s2/styling.mdx b/packages/dev/s2-docs/pages/s2/styling.mdx index 1f244ade31e..6b90151df00 100644 --- a/packages/dev/s2-docs/pages/s2/styling.mdx +++ b/packages/dev/s2-docs/pages/s2/styling.mdx @@ -14,9 +14,7 @@ React Spectrum includes a build-time `style` macro that generates atomic CSS and ## Style macro -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, -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 -of supported values. +The `style` macro runs at build time and returns a class name that applies Spectrum 2 design tokens (colors, spacing, sizing, typography, etc.). See the [reference](style-macro.html) for a full list of supported values. ```tsx import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; @@ -42,7 +40,7 @@ Colocating styles with your component code means: Important Note 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). - Failure to do so can result in large number of duplicate rules and obtuse styling bugs. + Without these optimizations, the generated CSS may contain duplicate rules that affect bundle size and debugging. @@ -97,7 +95,7 @@ import {Button} from '@react-spectrum/s2'; ## Conditional styles -Define conditional values as objects to handle media queries, UI states (hover/press), and variants. This keeps all values for a property together. +Define conditional values such as media queries, UI states (e.g. hover, press), and style variants as objects. Conditional values are mutually exclusive: the last matching condition always wins. ```tsx
'blue-1000' as const; - // component.tsx -import {bannerBackground} from './style-utils' with {type: 'macro'}; const horizontalStack = { display: 'flex', alignItems: 'center', @@ -212,12 +206,11 @@ const horizontalStack = { const styles = style({ ...horizontalStack, - backgroundColor: bannerBackground(), columnGap: 4 }); ``` -Create custom utilities by defining your own macros. +Create custom utilities by defining your own macros as functions in a separate file. ```ts // style-utils.ts @@ -280,7 +273,7 @@ const childStyle = style({ ## CSS optimization -The `style` macro relies on CSS bundling and minification for optimal output. Failure to perform this optimization will result in a suboptimal developer experience and obtuse styling bugs. +The `style` macro relies on CSS bundling and minification for optimal output. Without these optimizations, the generated CSS may contain duplicate rules that affect bundle size and debugging. Follow these best practices: - Ensure styles are extracted into a CSS bundle; do not inject at runtime with `