Skip to content

Commit 902a1fc

Browse files
LFDanLudevongovett
andauthored
useProvider docs (#2847)
* useProvider docs * forgot to remove extraneous section * adding margin and renaming component * fixing some of the langauge * updating useProvider example * a little more complex example * update copy a bit * forgot to use spectrum var here * ugh tabbing fixes and small adjustments to positioning * Update docs Co-authored-by: Devon Govett <[email protected]>
1 parent 05870c5 commit 902a1fc

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

packages/@react-spectrum/provider/docs/Provider.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Layout} from '@react-spectrum/docs';
22
export default Layout;
33

44
import docs from 'docs:@react-spectrum/provider';
5-
import {HeaderInfo, PropTable, PageDescription} from '@react-spectrum/docs';
5+
import {HeaderInfo, PropTable, PageDescription, TypeLink} from '@react-spectrum/docs';
66
import packageData from '@react-spectrum/provider/package.json';
77

88
```jsx import
@@ -27,7 +27,7 @@ keywords: [theme, locale, application, colorstop]
2727

2828
<HeaderInfo
2929
packageData={packageData}
30-
componentNames={['Provider']} />
30+
componentNames={['Provider', 'useProvider']} />
3131

3232
## Example
3333

@@ -149,3 +149,24 @@ function Register() {
149149
## Props
150150

151151
<PropTable component={docs.exports.Provider} links={docs.links} />
152+
153+
## useProvider
154+
The <TypeLink links={docs.links} type={docs.exports.useProvider} /> hook can be used to access the various properties applied by the nearest parent Provider. This can be useful for adapting a custom component to the current color scheme or scale.
155+
156+
The example below uses the `colorScheme` returned from `useProvider` to display either a moon or sun icon depending on the current color scheme. Toggle the theme using the switcher in the top right corner of the page to see the icon change.
157+
158+
```tsx example
159+
import Light from '@spectrum-icons/workflow/Light';
160+
import Moon from '@spectrum-icons/workflow/Moon';
161+
import {useProvider} from '@react-spectrum/provider';
162+
163+
function Example() {
164+
let {colorScheme} = useProvider();
165+
166+
return colorScheme === 'dark'
167+
? <Moon aria-label="In dark theme" />
168+
: <Light aria-label="In light theme" />
169+
}
170+
171+
<Example />
172+
```

0 commit comments

Comments
 (0)