-
Notifications
You must be signed in to change notification settings - Fork 1.4k
docs: Style macro docs #9090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Style macro docs #9090
Changes from 30 commits
edeaa2f
8a1f97e
28eb788
457c59a
a15c24f
819c076
3b991ea
42b0406
36f1a6f
e2b29c9
4c94cd0
83262ef
5d2b172
980d3d6
59e9400
a414886
0b2751d
4ef4996
b04b7af
807beb0
0c6ac3f
a3d57a9
30bab22
44b0d8d
5084b6b
34ad8cc
6bf1724
6e508f2
4b38f98
2e13868
61ba9db
cf728e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -242,6 +242,25 @@ With this configured, all states for React Aria Components can be accessed with | |||||
| </ListBoxItem> | ||||||
| ``` | ||||||
|
|
||||||
| ## 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'}; | ||||||
|
|
||||||
| <Checkbox | ||||||
| className={style({ | ||||||
| backgroundColor: { | ||||||
| default: 'gray-100', | ||||||
| isHovered: 'gray-200', | ||||||
| isSelected: 'gray-900' | ||||||
| } | ||||||
| })} | ||||||
| /> | ||||||
| ``` | ||||||
|
|
||||||
| ## 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 [Framer Motion](https://www.framer.com/motion/). | ||||||
|
||||||
| 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/). | |
| 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/). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ export const title = 'Home'; | |
| {id: 'Divider', name: 'Divider', href: 'Divider.html'}, | ||
| {id: 'DropZone', name: 'DropZone', href: 'DropZone.html'}, | ||
| {id: 'Form', name: 'Form', href: 'Form.html'}, | ||
| {id: 'Icons', name: 'Icons', href: 'Icons.html'}, | ||
| {id: 'Icons', name: 'Icons', href: 'icons.html'}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would this be the only one with a lowercase? seems like the file should be renamed if that's what it relies on, that way it's more predictable. really i'd like to get rid of all the uppercases in the urls... but that's a different issue
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the convention that seems to exist currently is that component pages are capitalized (e.g. DropZone/Menu/etc) and that non component pages aren't (e.g. dnd.mdx/migrating.mdx/etc) and icons fits into the latter. The file should be renamed to be lower case as well with my last commit, forgot to force git to recognize that change since it didn't automatically |
||
| {id: 'IllustratedMessage', name: 'IllustratedMessage', href: 'IllustratedMessage.html'}, | ||
| {id: 'Illustrations', name: 'Illustrations', href: 'Illustrations.html'}, | ||
| {id: 'Image', name: 'Image', href: 'Image.html'}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import {Layout} from '../../src/Layout'; | ||
| import {InlineAlert, Heading, Content, Link} from '@react-spectrum/s2'; | ||
| import {S2Colors} from '../../src/S2Colors'; | ||
| import {S2Typography} from '../../src/S2Typography'; | ||
| import {StyleMacroProperties} from '../../src/types'; | ||
| import {getPropertyDefinitions, getShorthandDefinitions} from '../../src/styleProperties'; | ||
| export default Layout; | ||
|
|
||
| export const section = 'Components'; | ||
| export const tags = ['style', 'macro', 'spectrum', 'custom', 'values', 'reference']; | ||
| export const description = 'Reference table for the style macro'; | ||
|
|
||
| # Style Macro | ||
|
|
||
| The `style` macro supports a constrained set of values per property that conform to Spectrum 2. | ||
|
|
||
| ## Colors | ||
snowystinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| All Spectrum 2 color tokens are available across color properties (e.g., `backgroundColor`, `color`, `borderColor`). | ||
| `baseColors` consists of the semantic and global colors listed below. | ||
|
|
||
| <S2Colors /> | ||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('color')} /> | ||
|
Comment on lines
+22
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ## Dimensions | ||
|
|
||
| Spacing props like `margin` and `padding` accept values on a **4px grid**. These are specified in `px` and get converted to `rem`. In addition to numbers, these named options are available: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we wanna bring up that you can use custom sizes using space()? are we comfortable documenting that api?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I debated doing that (and IMO probably a good idea) but I wasn't quite sure which of those utils we will end up making API on 1.0 release, there still some open questions for some of them in the 1.0 canvas. Other than |
||
|
|
||
| - `edge-to-text` β default spacing between the edge of a control and its text. Relative to control height. | ||
| - `pill` β default spacing between the edge of a pill-shaped control and its text. Relative to control height. | ||
| - `text-to-control` β default spacing between text and a control (e.g., label and input). Scales with font size. | ||
| - `text-to-visual` β default spacing between text and a visual element (e.g., icon). Scales with font size. | ||
|
|
||
| Size props like `width` and `height` accept arbitrary pixel values. Values are converted to `rem` and multiplied by 1.25x on touch devices to increase hit targets. | ||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('dimensions')} /> | ||
|
|
||
| ## Text | ||
|
|
||
| Spectrum 2 typography can be applied via the `font` [shorthand](#shorthands), which sets `fontFamily`, `fontSize`, `fontWeight`, `lineHeight`, and `color`. You can override any of these individually. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the font isn't applied as a global style? |
||
|
|
||
| ```tsx | ||
| <main> | ||
| <h1 className={style({font: 'heading-xl'})}>Heading</h1> | ||
| <p className={style({font: 'body'})}>Body</p> | ||
| <ul className={style({font: 'body-sm', fontWeight: 'bold'})}> | ||
| <li>List item</li> | ||
| </ul> | ||
| </main> | ||
| ``` | ||
|
|
||
| Type scales include: UI, Body, Heading, Title, Detail, and Code. Each scale has a default and additional t-shirt sizes (e.g., `ui-sm`, `heading-2xl`, `code-xl`). | ||
|
|
||
| <S2Typography /> | ||
|
|
||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('text')} /> | ||
|
|
||
|
|
||
| ## Effects | ||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('effects')} /> | ||
|
|
||
| ## Layout | ||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('layout')} /> | ||
|
|
||
| ## Misc | ||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('misc')} /> | ||
|
|
||
| ## Shorthands | ||
|
|
||
| Shorthands apply their provided value to commonly grouped properties. | ||
|
|
||
| <StyleMacroProperties properties={getShorthandDefinitions('shorthand')} /> | ||
|
|
||
| ## Conditions | ||
|
|
||
| <StyleMacroProperties properties={getPropertyDefinitions('conditions')} /> | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little out of place here. External folks might be confused to see this here especially since we aren't really pushing style macros externally yet. Do you think this should be under RAC or should we have a section on the RSP side that shows how to use style macros with RAC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a fair point, I'm fine moving this section to the S2 styling docs side