-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs: add S2 provider docs #9140
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
Merged
+96
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import {Layout} from '../../src/Layout'; | ||
| import {InstallCommand} from '../../src/InstallCommand'; | ||
| import {BundlerSwitcher, BundlerSwitcherItem} from '../../src/BundlerSwitcher'; | ||
| export default Layout; | ||
| import {SegmentedControl, SegmentedControlItem} from '@react-spectrum/s2'; | ||
|
|
||
| export const section = 'Getting started'; | ||
| export const description = 'Getting started with React Spectrum'; | ||
| import docs from 'docs:@react-spectrum/s2'; | ||
|
|
||
| # Provider | ||
|
|
||
| <PageDescription>{docs.exports.Provider.description}</PageDescription> | ||
|
|
||
| ## Example | ||
|
|
||
| ```tsx render | ||
| 'use client'; | ||
| import {Provider} from '@react-spectrum/s2'; | ||
| import {Button} from '@react-spectrum/s2'; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <Provider background='base'> | ||
| <Button variant="accent"> | ||
| Hello React Spectrum! | ||
| </Button> | ||
| </Provider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Color Schemes | ||
| By default, React Spectrum follows the operating system color scheme setting, supporting both light and dark mode. The colorScheme prop can be set on `<Provider>` to force the app to always render in a certain color scheme. | ||
|
|
||
| ```tsx render | ||
| 'use client'; | ||
| import {Provider} from '@react-spectrum/s2'; | ||
| import {ActionButton} from '@react-spectrum/s2'; | ||
| import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; | ||
|
|
||
| <div className={style({display: 'flex', gap: 12})}> | ||
| <Provider colorScheme="light"> | ||
| <div className={style({backgroundColor: 'base', padding: 12})}> | ||
| <ActionButton>I'm a light button</ActionButton> | ||
| </div> | ||
| </Provider> | ||
| <Provider colorScheme="dark"> | ||
| <div className={style({backgroundColor: 'elevated', padding: 12})}> | ||
| <ActionButton>I'm a dark button</ActionButton> | ||
| </div> | ||
| </Provider> | ||
| </div> | ||
| ``` | ||
|
|
||
| ## Locales | ||
| By default, React Spectrum chooses the locale matching the user’s browser/operating system language, but this can be overridden with the locale prop if you have an application specific setting. This prop accepts a [BCP 47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code. A list of supported locales is available [here](Concepts.html#supported-locales) | ||
|
|
||
| ```tsx | ||
| <Provider locale="en-US"> | ||
| <YourApp /> | ||
| </Provider> | ||
| ``` | ||
|
|
||
| {/* ### Breakpoints */} | ||
| {/* TODO: Link to style macro docs about breakpoints */} | ||
|
|
||
| ## Client side routing | ||
|
|
||
| The Provider component accepts an optional `router` prop. This enables React Spectrum components that render links to perform client side navigation using your application or framework's client side router. See the client side routing guide for details on how to set this up. | ||
|
|
||
| ```tsx | ||
| let navigate = useNavigateFromYourRouter(); | ||
|
|
||
| <Provider router={{navigate}}> | ||
| <YourApp /> | ||
| </Provider> | ||
| ``` | ||
|
|
||
| ## Server side rendering | ||
|
|
||
| When using SSR, the `<Provider>` component can be rendered as the root `<html>` element. The `locale` prop should always be specified to avoid hydration errors. | ||
|
|
||
| ```tsx | ||
| <Provider elementType="html" locale="en-US"> | ||
| <YourApp /> | ||
| </Provider> | ||
| ``` | ||
|
|
||
| ## Props | ||
|
|
||
| <PropTable component={docs.exports.Provider} links={docs.links} /> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we wanting to include this?
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.
im fine to leave it out since it's covered by the styles guide but since we had a breakpoints section in the previous provider page for v3, people might be expecting it?
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.
I think we can include it in the Migration guide and it should be covered by the style macros page as well