diff --git a/.storybook-s2/docs/Icons.jsx b/.storybook-s2/docs/Icons.jsx index af7554dc0cc..d16eec4f0c6 100644 --- a/.storybook-s2/docs/Icons.jsx +++ b/.storybook-s2/docs/Icons.jsx @@ -6,7 +6,7 @@ import {highlight} from './highlight' with {type: 'macro'}; export function Icons() { return ( -
+

Workflow icons diff --git a/.storybook-s2/docs/Illustrations.jsx b/.storybook-s2/docs/Illustrations.jsx index 506c1ddcc01..9acd33ca2f1 100644 --- a/.storybook-s2/docs/Illustrations.jsx +++ b/.storybook-s2/docs/Illustrations.jsx @@ -11,7 +11,7 @@ import { useState } from 'react'; export function Illustrations() { let [gradientStyle, setStyle] = useState('generic1'); return ( -
+

Illustrations diff --git a/.storybook-s2/docs/Intro.jsx b/.storybook-s2/docs/Intro.jsx index 21ee083c1bd..dddcc9e2fae 100644 --- a/.storybook-s2/docs/Intro.jsx +++ b/.storybook-s2/docs/Intro.jsx @@ -13,7 +13,7 @@ import {H2, H3, H4, P, Pre, Code, Strong, Link} from './typography'; export function Docs() { return ( -
+

UNSAFE Style Overrides

We highly discourage overriding the styles of React Spectrum components because it may break at any time when we change our implementation, making it difficult for you to update in the future. Consider using React Aria Components with our style macro to build a custom component with Spectrum styles instead.

-

That said, just like in React Spectrum v3, the UNSAFE_className and UNSAFE_style props are supported on Spectrum 2 components as last-resort escape hatches. However, unlike in v3, UNSAFE_classNames must be placed in a special UNSAFE_overrides CSS cascade layer. This guarentees that your overrides will always win over other styles on the page, no matter the order or specificity of the selector.

+

That said, just like in React Spectrum v3, the UNSAFE_className and UNSAFE_style props are supported on Spectrum 2 components as last-resort escape hatches.

{highlight(`/* YourComponent.tsx */
 import {Button} from '@react-spectrum/s2';
 import './YourComponent.css';
@@ -237,12 +237,10 @@ function YourComponent() {
   return ;
 }`)}
{highlight(`/* YourComponent.css */
-@layer UNSAFE_overrides {
-  /* Wrap all UNSAFE_className rules in this layer. */
-  .your-unsafe-class {
-    background: red;
-  }
-}`, 'CSS')}
+.your-unsafe-class { + background: red; +} +`, 'CSS')}
) diff --git a/.storybook-s2/docs/MDXLayout.jsx b/.storybook-s2/docs/MDXLayout.jsx index 79c47bd8322..cf1bf504eef 100644 --- a/.storybook-s2/docs/MDXLayout.jsx +++ b/.storybook-s2/docs/MDXLayout.jsx @@ -19,7 +19,7 @@ const mdxComponents = { export function MDXLayout({children}) { return ( -
+
{children} diff --git a/.storybook-s2/docs/Migrating.jsx b/.storybook-s2/docs/Migrating.jsx index 67eeb348ce2..f4861be1bd7 100644 --- a/.storybook-s2/docs/Migrating.jsx +++ b/.storybook-s2/docs/Migrating.jsx @@ -3,7 +3,7 @@ import {P, Code, Pre, H3, H2, Link} from './typography'; export function Migrating() { return ( -
+

Migrating to Spectrum 2 diff --git a/.storybook-s2/docs/StyleMacro.jsx b/.storybook-s2/docs/StyleMacro.jsx index 8501852a82b..9e242ad6f79 100644 --- a/.storybook-s2/docs/StyleMacro.jsx +++ b/.storybook-s2/docs/StyleMacro.jsx @@ -6,7 +6,7 @@ import {Colors} from './Colors'; export function StyleMacro() { return ( -
+
{ return (
- Global unsafe does not apply - @layer UNSAFE_overrides works + UNSAFE_className works
); }, diff --git a/packages/@react-spectrum/s2/stories/unsafe.css b/packages/@react-spectrum/s2/stories/unsafe.css index c7673082a12..7e17db078cc 100644 --- a/packages/@react-spectrum/s2/stories/unsafe.css +++ b/packages/@react-spectrum/s2/stories/unsafe.css @@ -10,19 +10,7 @@ * governing permissions and limitations under the License. */ -button { - /* This should not apply */ - background: red; -} - -html body .unsafe1 { - /* This should not apply */ - background: red; -} - -@layer UNSAFE_overrides { - .unsafe2 { - /* This one should work */ - background: hotpink; - } +.unsafe2 { + /* This one should work */ + background: hotpink; } diff --git a/packages/@react-spectrum/s2/style/__tests__/style-macro.test.js b/packages/@react-spectrum/s2/style/__tests__/style-macro.test.js index e3541d10c02..d5d1336adc5 100644 --- a/packages/@react-spectrum/s2/style/__tests__/style-macro.test.js +++ b/packages/@react-spectrum/s2/style/__tests__/style-macro.test.js @@ -37,9 +37,7 @@ describe('style-macro', () => { }); expect(css).toMatchInlineSnapshot(` - ".\\.:not(#a#b) { all: revert-layer } - - @layer _.a, _.b, _.c, UNSAFE_overrides; + "@layer _.a, _.b, _.c; @layer _.b { .A-13alit4c { @@ -72,9 +70,7 @@ describe('style-macro', () => { }); expect(css).toMatchInlineSnapshot(` - ".\\.:not(#a#b) { all: revert-layer } - - @layer _.a, _.b, UNSAFE_overrides; + "@layer _.a, _.b; @layer _.a { .uc { diff --git a/packages/@react-spectrum/s2/style/style-macro.ts b/packages/@react-spectrum/s2/style/style-macro.ts index 25d6f2e345a..a871a80afa4 100644 --- a/packages/@react-spectrum/s2/style/style-macro.ts +++ b/packages/@react-spectrum/s2/style/style-macro.ts @@ -222,7 +222,7 @@ export function createTheme(theme: T): StyleFunction(theme: T): StyleFunction