Skip to content
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

Global Styles: Expose the provider and the reset hook #42824

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions packages/edit-site/src/components/global-styles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { useGlobalStylesReset } from './global-styles';
function MyComponent() {
const [ canReset, reset ] = useGlobalStylesReset();

return canReset
? <Button onClick={ () => reset() }>Reset</Button>
return canReset
? <Button onClick={ () => reset() }>Reset</Button>
: null;
}
```
Expand Down Expand Up @@ -61,10 +61,10 @@ import { useStyle } from './global-styles';

function MyComponent() {
// Text color for the site root.
const [ color, setColor ] = useStyle( 'color.text' );
const [ color, setColor ] = useStyle( 'color.text' );

// The user modified color for the core paragraph block.
const [ pColor, setPColor ] = useStyle( 'color.text', 'core/paragraph', 'user' );
const [ pColor, setPColor ] = useStyle( 'color.text', 'core/paragraph', 'user' );

return "Something";
}
Expand All @@ -79,13 +79,31 @@ import { useSetting } from './global-styles';

function MyComponent() {
// The default color palette.
const [ colorPalette, setColorPalette ] = useSetting( 'color.palette' );
const [ colorPalette, setColorPalette ] = useSetting( 'color.palette' );

// The base (theme + core) color palette for the paragraph block,
// ignoring user provided palette.
// If the palette is not defined for the paragraph block, the root one is returned.
const [ pColor, setPColor ] = useSetting( 'color.palette', 'core/paragraph', 'base' );
const [ pColor, setPColor ] = useSetting( 'color.palette', 'core/paragraph', 'base' );

return "Something";
}
```

## GlobalStylesProvider

Provides access to the Global Styles store. If you want to interact with Global Styles data in a UI then you can wrap your controls in this component to give you access to the store:

```js
import { GlobalStylesProvider } from './global-styles';

function MyComponent() {
return (
<GlobalStylesProvider>
<MyUIControls />
</GlobalStylesProvider>
);
}
```

The `MyUIControls` component will now have access to the Global Styles store.
1 change: 1 addition & 0 deletions packages/edit-site/src/components/global-styles/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as GlobalStylesUI } from './ui';
export { useGlobalStylesReset, useStyle, useSetting } from './hooks';
export { useGlobalStylesOutput } from './use-global-styles-output';
export { GlobalStylesProvider } from './global-styles-provider';
4 changes: 4 additions & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,7 @@ export { default as __experimentalNavigationToggle } from './components/navigati
export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';
export { default as PluginMoreMenuItem } from './components/header/plugin-more-menu-item';
export {
useGlobalStylesReset,
GlobalStylesProvider,
} from './components/global-styles';