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

Allow specifying defaults for visible themes and widths #305

Merged
merged 8 commits into from
Feb 13, 2024
Merged
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
20 changes: 20 additions & 0 deletions .changeset/itchy-taxis-rhyme.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading