-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore(S2): audit style macro utilities #9544
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
base: main
Are you sure you want to change the base?
Changes from all commits
ced7ad2
418056f
2ccfd61
fe2bc92
4e620c3
0cf5ad7
acf0f38
9f6eb4e
2034cc0
68a080f
ef9ab31
afcd187
c8be472
efcd314
3003c94
c6e6cde
15afa36
302c704
8ef8ff0
8cc7ebf
4113557
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,18 +15,63 @@ import {Inset, fontRelative as internalFontRelative, space as internalSpace, Spa | |||||||
| import type {MacroContext} from '@parcel/macros'; | ||||||||
| import {StyleString} from './types'; | ||||||||
|
|
||||||||
| export {baseColor, color, lightDark, colorMix, size, style} from './spectrum-theme'; | ||||||||
| export {baseColor, color, lightDark, colorMix, linearGradient, size, style} from './spectrum-theme'; | ||||||||
| export {raw, keyframes} from './style-macro'; | ||||||||
| export type {StyleString} from './types'; | ||||||||
|
|
||||||||
| // Wrap these functions in arbitrary value syntax when called from the outside. | ||||||||
| /** | ||||||||
| * Converts a pixel value to a Spectrum spacing token in `rem` units. | ||||||||
| * | ||||||||
| * @param px - The spacing in pixels. | ||||||||
| * @returns A `rem` value wrapped as an arbitrary style value. | ||||||||
| * | ||||||||
| * @example | ||||||||
| * ```tsx | ||||||||
| * import {space} from '@react-spectrum/s2/style' with {type: 'macro'}; | ||||||||
| * | ||||||||
| * const styles = style({ | ||||||||
| * gap: space(12) // 12/16 = 0.75rem | ||||||||
| * }); | ||||||||
| * ``` | ||||||||
| */ | ||||||||
| export function space(px: number): `[${string}]` { | ||||||||
| return `[${internalSpace(px)}]`; | ||||||||
| } | ||||||||
|
|
||||||||
| export function fontRelative(base: number, baseFontSize?: number): `[${string}]` { | ||||||||
| /** | ||||||||
| * Converts a pixel value to a font-relative `em` length. Useful for sizing elements | ||||||||
| * relative to the current font size. Defaults to a 14px base. | ||||||||
| * | ||||||||
| * @param base - The pixel value to convert. | ||||||||
| * @param baseFontSize - The base font size in pixels to divide by. Defaults to `14`. | ||||||||
reidbarber marked this conversation as resolved.
Show resolved
Hide resolved
reidbarber marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| * @returns A CSS `em` value wrapped as an arbitrary style value. | ||||||||
| * | ||||||||
| * @example | ||||||||
| * ```tsx | ||||||||
| * import {fontRelative} from '@react-spectrum/s2/style' with {type: 'macro'}; | ||||||||
| * | ||||||||
| * const styles = style({ | ||||||||
| * gap: fontRelative(2) // 2/14 = ~0.143em | ||||||||
reidbarber marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| * }); | ||||||||
| * ``` | ||||||||
| */ | ||||||||
| export function fontRelative(base: number, baseFontSize = 14): `[${string}]` { | ||||||||
| return `[${internalFontRelative(base, baseFontSize)}]`; | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Returns consistent Spectrum focus ring outline styles for interactive components. | ||||||||
|
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. we override the results of this one a *lot a handful of examples:
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. just realised, we already export this don't we... womp womp, we should probably build that wrapper around it for ourselves |
||||||||
| * | ||||||||
| * @example | ||||||||
| * ```tsx | ||||||||
| * import {focusRing, style} from '@react-spectrum/s2/style' with {type: 'macro'}; | ||||||||
| * | ||||||||
| * const styles = style({ | ||||||||
| * ...focusRing(), | ||||||||
| * borderRadius: 'lg' | ||||||||
| * }); | ||||||||
| * ``` | ||||||||
| */ | ||||||||
| export const focusRing = () => ({ | ||||||||
| outlineStyle: { | ||||||||
| default: 'none', | ||||||||
|
|
@@ -78,6 +123,21 @@ const iconSizes = { | |||||||
| XL: 26 | ||||||||
| } as const; | ||||||||
|
|
||||||||
| /** | ||||||||
| * Generates styles for an icon element with the given size, color, and layout options. | ||||||||
| * Must be imported with `{type: 'macro'}`. | ||||||||
reidbarber marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| * | ||||||||
| * @param options - Icon styling options including `size` (XS–XL), `color`, and layout properties. | ||||||||
| * @returns A `StyleString` that can be applied to an icon element. | ||||||||
| * | ||||||||
| * @example | ||||||||
| * ```tsx | ||||||||
| * import {iconStyle} from '@react-spectrum/s2/style' with {type: 'macro'}; | ||||||||
| * import Edit from '@react-spectrum/s2/icons/Edit'; | ||||||||
| * | ||||||||
| * <Edit styles={iconStyle({size: 'XL', color: 'positive'})} /> | ||||||||
| * ``` | ||||||||
| */ | ||||||||
| export function iconStyle(this: MacroContext | void, options: IconStyle): StyleString<Exclude<keyof IconStyle, 'color' | 'size'>> { | ||||||||
| let {size = 'M', color, ...styles} = options; | ||||||||
|
|
||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.