Skip to content

Commit 1908374

Browse files
authored
feat: Allow arbitrary pixel sizes in S2 style macro (#7385)
* feat: Allow arbitrary pixel sizes in S2 style macro * Fix tests * Fix selector conflict * Update codemod * update unsafe style as well
1 parent 6d6e530 commit 1908374

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+214
-155
lines changed

.storybook-s2/docs/Icons.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {highlight} from './highlight' with {type: 'macro'};
66

77
export function Icons() {
88
return (
9-
<div className={style({maxWidth: 'lg', marginX: 'auto'})}>
9+
<div className={style({marginX: 'auto'})}>
1010
<div className={style({marginX: 48})}>
1111
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
1212
Workflow icons

.storybook-s2/docs/Illustrations.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useState } from 'react';
1111
export function Illustrations() {
1212
let [gradientStyle, setStyle] = useState('generic1');
1313
return (
14-
<div className={style({maxWidth: 'lg', marginX: 'auto'})}>
14+
<div className={style({marginX: 'auto'})}>
1515
<div className={style({marginX: 48})}>
1616
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
1717
Illustrations

.storybook-s2/docs/Intro.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {H2, H3, H4, P, Pre, Code, Strong, Link} from './typography';
1313

1414
export function Docs() {
1515
return (
16-
<div className={style({maxWidth: 'lg', marginX: 'auto', marginY: 48})}>
16+
<div className={style({marginX: 'auto', marginY: 48})}>
1717
<header
1818
style={{
1919
backgroundImage: `url(${new URL('wallpaper_collaborative_S2_desktop.webp', import.meta.url).toString()})`,

.storybook-s2/docs/MDXLayout.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const mdxComponents = {
1919

2020
export function MDXLayout({children}) {
2121
return (
22-
<div className={style({maxWidth: 'lg', marginX: 'auto'})}>
22+
<div className={style({marginX: 'auto'})}>
2323
<main className={style({marginX: 48})}>
2424
<MDXProvider components={mdxComponents}>
2525
{children}

.storybook-s2/docs/Migrating.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {P, Code, Pre, H3, H2, Link} from './typography';
33

44
export function Migrating() {
55
return (
6-
<div className={style({maxWidth: 'lg', marginX: 'auto', fontFamily: 'sans'})}>
6+
<div className={style({marginX: 'auto', fontFamily: 'sans'})}>
77
<div className={style({marginX: 48})}>
88
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
99
Migrating to Spectrum 2

.storybook-s2/docs/StyleMacro.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Colors} from './Colors';
66

77
export function StyleMacro() {
88
return (
9-
<div className={style({maxWidth: 'lg', marginX: 'auto'})}>
9+
<div className={style({marginX: 'auto'})}>
1010
<header
1111
className={style({
1212
paddingX: 48,
@@ -37,9 +37,17 @@ export function StyleMacro() {
3737
<H3>Colors</H3>
3838
<P>The Spectrum 2 color palette is available across all color properties. See the following sections for color values available for each property.</P>
3939
<Colors />
40-
<H3>Spacing and sizing</H3>
41-
<P>Spacing properties such as <Code>margin</Code> and <Code>padding</Code>, and sizing properties such as <Code>width</Code> and <Code>height</Code> support a limited set of values. The API is represented in pixels, however, only values conforming to a 4px grid are allowed. This helps ensure that spacing and sizing are visually consistent.</P>
42-
<P>Internally, spacing and sizing values are converted from pixels to rems, which scale according to the user’s font size preference. In addition, sizing values are multiplied by 1.25x on touch screen devices to help increase the size of hit targets. Spacing values do not scale and remain fixed.</P>
40+
<H3>Spacing</H3>
41+
<P>Spacing properties such as <Code>margin</Code> and <Code>padding</Code> support a limited set of values. The API is represented in pixels, however, only values conforming to a 4px grid are allowed. This helps ensure that spacing and sizing are visually consistent. Spacing values are automatically converted to rems, which scale according to the user’s font size preference.</P>
42+
<P>In addition to numeric values, the following spacing options are available:</P>
43+
<ul className="sb-unstyled">
44+
<li className={style({font: 'body-lg', marginTop: 0, marginBottom: 8})}><Code>text-to-control</Code> – The default horizontal spacing between text and a UI control, for example between a label and input. This value automatically adjusts based on the font size.</li>
45+
<li className={style({font: 'body-lg', marginTop: 0, marginBottom: 8})}><Code>text-to-visual</Code> – The default horizontal spacing between text and a visual element, such as an icon. This value automatically adjusts based on the font size.</li>
46+
<li className={style({font: 'body-lg', marginTop: 0, marginBottom: 8})}><Code>edge-to-text</Code> – The default horizontal spacing between the edge of a UI control and text within it. This value is calculated relative to the height of the control.</li>
47+
<li className={style({font: 'body-lg', marginTop: 0, marginBottom: 8})}><Code>pill</Code> – The default horizontal spacing between the edge of a pill-shaped UI control (e.g. a fully rounded button) and text within it. This value is calculated relative to the height of the control.</li>
48+
</ul>
49+
<H3>Sizing</H3>
50+
<P>Sizing properties such as <Code>width</Code> and <Code>height</Code> accept arbitrary pixel values. Internally, sizes are converted to rems, which scale according to the user’s font size preference. Additionally, size values are multiplied by 1.25x on touch screen devices to help increase the size of hit targets.</P>
4351
<H3>Typography</H3>
4452
<P>Spectrum 2 does not include specific components for typography. Instead, you can use the style macro to apply Spectrum typography to any HTML element or component.</P>
4553
<P>The <Code>font</Code> shorthand applies default values for the <Code>fontFamily</Code>, <Code>fontSize</Code>, <Code>fontWeight</Code>, <Code>lineHeight</Code>, and <Code>color</Code> properties, following Spectrum design pairings. These individual properties can also be set to override the default set by the shorthand.</P>

packages/@react-spectrum/s2/chromatic/ActionButtonGroup.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ export default meta;
3434

3535
let justifiedStyle = style({
3636
width: {
37-
default: '[500px]',
37+
default: 500,
3838
orientation: {
3939
vertical: 'auto'
4040
}
4141
},
4242
height: {
4343
orientation: {
44-
vertical: '[500px]'
44+
vertical: 500
4545
}
4646
}
4747
});

packages/@react-spectrum/s2/chromatic/CardView.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const cardViewStyles = style({
3636
height: {
3737
default: 'screen',
3838
viewMode: {
39-
docs: '[600px]'
39+
docs: 600
4040
}
4141
}
4242
});

packages/@react-spectrum/s2/chromatic/DropZone.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const Example = (args: any) => {
3737
<Draggable />
3838
<DropZone
3939
{...args}
40-
className={style({width: '[320px]', height: '[280px]'})}
40+
className={style({width: 320, height: 280})}
4141
isFilled={isFilled}
4242
onDrop={() => setIsFilled(true)}>
4343
<IllustratedMessage>
@@ -62,7 +62,7 @@ export const ExampleWithFileTrigger = (args: any) => {
6262
<Draggable />
6363
<DropZone
6464
{...args}
65-
className={style({width: '[380px]', height: '[280px]'})}
65+
className={style({width: 380, height: 280})}
6666
isFilled={isFilled}
6767
onDrop={() => setIsFilled(true)}>
6868
<IllustratedMessage>
@@ -94,7 +94,7 @@ export const LongBanner = (args: any) => {
9494
<DropZone
9595
{...args}
9696
replaceMessage="A really long message that will show the text wrapping hopefully"
97-
className={style({width: '[320px]', height: '[280px]'})}
97+
className={style({width: 320, height: 280})}
9898
isFilled={isFilled}
9999
onDrop={() => setIsFilled(true)}>
100100
<IllustratedMessage>
@@ -119,7 +119,7 @@ export const Gradient = (args: any) => {
119119
<Draggable />
120120
<DropZone
121121
{...args}
122-
className={style({width: '[320px]', height: '[280px]'})}
122+
className={style({width: 320, height: 280})}
123123
isFilled={isFilled}
124124
onDrop={() => setIsFilled(true)}>
125125
<IllustratedMessage>

packages/@react-spectrum/s2/chromatic/SegmentedControl.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ OnlyIcons.args = {
6868
};
6969

7070
export const CustomWidthJustified = (args: any) => (
71-
<SegmentedControl {...args} styles={style({width: '[400px]'})}>
71+
<SegmentedControl {...args} styles={style({width: 400})}>
7272
<SegmentedControlItem id="overview">Overview</SegmentedControlItem>
7373
<SegmentedControlItem id="specs">Specs</SegmentedControlItem>
7474
<SegmentedControlItem id="guidelines">Guidelines</SegmentedControlItem>

0 commit comments

Comments
 (0)