You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .storybook-s2/docs/Intro.jsx
+40-17Lines changed: 40 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -140,41 +140,64 @@ export function Docs() {
140
140
<P>You may also need to configure other tools such as TypeScript, Babel, ESLint, and Jest to support parsing import attributes. See <Linkhref="https://parceljs.org/features/macros/#usage-with-other-tools"target="_blank">these docs</Link> for details.</P>
141
141
<P>See the <Linkhref="https://github.com/adobe/react-spectrum/tree/main/examples"target="_blank">examples folder</Link> in our repo for working setups with various build tools. For details on optimizing the output CSS, see the <Linkhref="?path=/docs/style-macro--docs#css-optimization"target="_top">style macro docs</Link>.</P>
142
142
<H2>Setting up your app</H2>
143
-
<P>Unlike React Spectrum v3, a <Code>Provider</Code> is not required. Instead, import <Code>@react-spectrum/s2/page.css</Code> in the entry component of your app to apply the background color and color scheme to the <Code>{'<html>'}</Code> element. This ensures that the entire page has the proper styles even before your JavaScript runs.</P>
<P>Wrap your app in an S2 <Code>{'<Provider>'}</Code> component to load Spectrum 2 fonts for the user's locale and apply the appropriate Spectrum background layer for your app. When using S2 together with other versions of Spectrum, ensure that the S2 provider is the inner-most provider.</P>
144
+
<Pre>{highlight(`import {Provider, Button} from '@react-spectrum/s2';
146
145
147
146
function App() {
148
147
return (
149
-
<Button
150
-
variant="accent"
151
-
onPress={() => alert('Hey there!')}>
152
-
Hello Spectrum 2!
153
-
</Button>
148
+
// Wrap app in a <Provider> to load fonts, set background, set locale, etc.
<P><Strong>Note</Strong>: If you’re embedding Spectrum 2 as a section of a larger page rather than taking over the whole window, follow the <Linkhref="#embedded-sections"target="_self">directions below</Link> instead of using <Code>page.css</Code>.</P>
161
+
<H3>Optimizing full-page apps</H3>
162
+
<P>When building a full page S2 app that's not embedded within a larger page, import <Code>@react-spectrum/s2/page.css</Code> to apply the background color and color scheme to the <Code>{'<html>'}</Code> element instead of the <Code>{'<Provider>'}</Code>. This ensures that the page has styles even before your JavaScript loads. A <Code>{'<Provider>'}</Code> is still necessary in addition to <Code>page.css</Code> in order to include the fonts, set the locale, etc.</P>
163
+
<Pre>{highlight(`// Apply S2 background to the <html> element
164
+
import '@react-spectrum/s2/page.css';
165
+
166
+
function App() {
167
+
return (
168
+
<Provider>
169
+
{/* ... */}
170
+
</Provider>
171
+
);
172
+
}`)}</Pre>
173
+
<P>By default, this uses the <Code>base</Code> background layer. This can be customized by setting the <Code>data-background</Code> attribute on the <Code>{'<html>'}</Code> element.</P>
174
+
<Pre>{highlight(`<html data-background="layer-1">
175
+
<!-- ... -->
176
+
</html>`)}</Pre>
160
177
<H3>Overriding the color scheme</H3>
161
-
<P>By default, the page follows the user’s operating system color scheme setting, supporting both light and dark mode. The page background is set to the <Code>base</Code> Spectrum background layer by default. This can be configured by setting the <Code>data-color-scheme</Code> and <Code>data-background</Code> attributes on the <Code>{'<html>'}</Code> element. For example, to force the application to only render in light mode, set <Code>data-color-scheme="light"</Code>.</P>
178
+
<P>By default, React Spectrum follows the operating system color scheme setting, supporting both light and dark mode. The <Code>colorScheme</Code> prop can be set on <Code>{'<Provider>'}</Code> to force the app to always render in a certain color scheme.</P>
179
+
<Pre>{highlight(`import {Provider} from '@react-spectrum/s2';
180
+
181
+
<Provider colorScheme="light">
182
+
{/* your app */}
183
+
</Provider>`)}</Pre>
184
+
<P>When using <Code>page.css</Code>, set the <Code>data-color-scheme</Code> attribute on the <Code>{'<html>'}</Code> element.</P>
162
185
<Pre>{highlight(`<html data-color-scheme="light">
163
186
<!-- ... -->
164
187
</html>`)}</Pre>
165
188
<H3>Overriding the locale</H3>
166
-
<P>By default, React Spectrum uses the browser/operating system language setting for localized strings, date and number formatting, and to determine the layout direction (left-to-right or right-to-left). This can be overridden by rendering a <Code>{'<Provider>'}</Code>component at the root of your app, and setting the <Code>locale</Code> prop.</P>
189
+
<P>By default, React Spectrum uses the browser/operating system language setting for localized strings, date and number formatting, and to determine the layout direction (left-to-right or right-to-left). This can be overridden by rendering setting the <Code>locale</Code>prop on the <Code>{'<Provider>'}</Code>.</P>
167
190
<Pre>{highlight(`import {Provider} from '@react-spectrum/s2';
168
191
169
192
<Provider locale="en-US">
170
193
{/* your app */}
171
194
</Provider>`)}</Pre>
172
-
<H3>Embedded sections</H3>
173
-
<P>If you’re building an embedded section of a larger page using Spectrum 2, use the <Code>{'<Provider>'}</Code> component to set the background instead of importing <Code>page.css</Code>. The <Code>background</Code> prop should be set to the Spectrum background layer appropriate for your app, and the <Code>colorScheme</Code>can be overridden as well.</P>
174
-
<Pre>{highlight(`import {Provider} from '@react-spectrum/s2';
175
-
176
-
<Provider background="base">
177
-
{/* your app */}
195
+
<H3>Server-side rendering</H3>
196
+
<P>When using SSR, the <Code>{'<Provider>'}</Code> component can be rendered as the root <Code>{'<html>'}</Code> element. The <Code>locale</Code> prop should always be specified to avoid hydration errors. <Code>page.css</Code>is not needed in this case.</P>
0 commit comments