Skip to content

Commit

Permalink
Add support for defaulting visible themes and widths (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
nib-bturner committed Feb 13, 2024
1 parent f45dd04 commit ad60e01
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .changeset/itchy-taxis-rhyme.md
@@ -0,0 +1,20 @@
---
'playroom': minor
---

Add support for specifying default subsets of themes and screen widths via the config.

#### Example usage

```js
// playroom.config.js
module.exports = {
...,
defaultVisibleWidths: [
// subset of widths to display on first load
],
defaultVisibleThemes: [
// subset of themes to display on first load
],
}
```
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -80,6 +80,12 @@ module.exports = {
// Custom webpack config goes here...
}),
iframeSandbox: 'allow-scripts',
defaultVisibleWidths: [
// subset of widths to display on first load
],
defaultVisibleThemes: [
// subset of themes to display on first load
],
};
```

Expand Down
10 changes: 8 additions & 2 deletions src/StoreContext/StoreContext.tsx
Expand Up @@ -494,9 +494,15 @@ export const StoreProvider = ({
const editorPosition = storedPosition;
const editorHeight = storedHeight;
const editorWidth = storedWidth;
const visibleWidths = widthsFromQuery || storedVisibleWidths;
const visibleWidths =
widthsFromQuery ||
storedVisibleWidths ||
playroomConfig?.defaultVisibleWidths;
const visibleThemes =
hasThemesConfigured && (themesFromQuery || storedVisibleThemes);
hasThemesConfigured &&
(themesFromQuery ||
storedVisibleThemes ||
playroomConfig?.defaultVisibleThemes);
const colorScheme = storedColorScheme;

dispatch({
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Expand Up @@ -15,6 +15,8 @@ interface PlayroomConfig {
iframeSandbox?: string;
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
reactDocgenTypescriptConfig?: import('react-docgen-typescript').ParserOptions;
defaultVisibleThemes?: string[];
defaultVisibleWidths?: number[];
}

interface InternalPlayroomConfig extends PlayroomConfig {
Expand Down

0 comments on commit ad60e01

Please sign in to comment.