Skip to content
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
5 changes: 4 additions & 1 deletion .storybook/polaris-readme-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ module.exports = function loader(source) {
return `
const ${example.storyName}Component = (${example.code})();
export function ${example.storyName}() {
return <${example.storyName}Component key="${readme.name}"/>;
return <div data-omit-app-provider="${readme.omitAppProvider}"><${
example.storyName
}Component /></div>;
}
${example.storyName}.story = {
name: ${JSON.stringify(example.name)},
Expand Down Expand Up @@ -281,6 +283,7 @@ function parseCodeExamples(data) {
name: matter.data.name,
category: matter.data.category,
examples: generateExamples(matter),
omitAppProvider: matter.data.omitAppProvider || false,
};
}

Expand Down
15 changes: 4 additions & 11 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,16 @@ function StrictModeToggle({isStrict = false, children}) {
return <Wrapper>{children}</Wrapper>;
}

const COMPONENTS_TO_OMIT_APP_PROVIDER = [
'Top bar',
'App provider',
'Contextual save bar',
'Frame',
];

function AppProviderWithKnobs({newDesignLanguage, colorScheme, children}) {
const componentName = (() => {
const omitAppProvider = (() => {
try {
return children.props.children.key;
return children.props.children.props['data-omit-app-provider'];
} catch (e) {
return undefined;
return null;
}
})();

if (COMPONENTS_TO_OMIT_APP_PROVIDER.includes(componentName)) return children;
if (omitAppProvider === 'true') return children;

const colors = Object.entries(DefaultThemeColors).reduce(
(accumulator, [key, value]) => ({
Expand Down
3 changes: 2 additions & 1 deletion UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

- Added `check:custom-property` job in travis ([#2778](https://github.com/Shopify/polaris-react/pull/2778))
- Exported missing OptionListProps ([#2777](https://github.com/Shopify/polaris-react/pull/2777))
- Omitted the Storybook `AppProvider` decorator for examples which already contain an `AppProvider` ([#2807](https://github.com/Shopify/polaris-react/pull/2807))
- Omitted the Storybook `AppProvider` decorator for component examples which already contain an `AppProvider` ([#2807](https://github.com/Shopify/polaris-react/pull/2807))
- Added an `omitAppProvider` front matter concept to prevent automatic wrapping of component examples with an `AppProvider` ([#2815](https://github.com/Shopify/polaris-react/pull/2815))

### Dependency upgrades

Expand Down
3 changes: 3 additions & 0 deletions documentation/Component READMEs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ keywords:
# Indicates the component takes over the entire viewport
fullSizeExamples: false # Optional, default: false

# Prevents automatic wrapping of examples with an AppProvider
omitAppProvider: false # Optional, default: false

# Hides the playground, mostly useful for components which only render in an embedded app context
# that don’t have a matching React source
hidePlayground: false # Optional, default: false
Expand Down
1 change: 1 addition & 0 deletions src/components/AppProvider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ keywords:
- shopify app bridge
- embedded app sdk
- sdk
omitAppProvider: true
---

# App provider
Expand Down
1 change: 1 addition & 0 deletions src/components/ContextualSaveBar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords:
- save
- cancel
- logo
omitAppProvider: true
---

# Contextual Save Bar
Expand Down
1 change: 1 addition & 0 deletions src/components/Frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ keywords:
- menu
- toast
fullSizeExamples: true
omitAppProvider: true
---

# Frame
Expand Down
1 change: 1 addition & 0 deletions src/components/TopBar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ keywords:
- user
- menu
- logo
omitAppProvider: true
---

# Top bar
Expand Down