This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2453 from bbc/build-rtl-variant-changes
Ability to create RTL variants of specific/all stories of a kind as substories
- Loading branch information
Showing
7 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/utilities/psammead-storybook-helpers/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 28 additions & 7 deletions
35
packages/utilities/psammead-storybook-helpers/src/buildRTLSubstories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import { getStorybook, storiesOf } from '@storybook/react'; | ||
import withServicesKnob from './withServicesKnob'; | ||
|
||
export default () => { | ||
getStorybook().forEach(({ kind, stories }) => { | ||
stories.forEach(({ name, render }) => { | ||
storiesOf(`${kind}/RTL`, module) | ||
.addDecorator(withServicesKnob({ defaultService: 'arabic' })) | ||
.add(`RTL - ${name}`, render); | ||
}); | ||
const matchesStoryKind = kind => story => story.kind === kind; | ||
|
||
const matchesStoryName = name => story => story.name === name; | ||
|
||
const buildRTLSubstory = (kind, name, storyFn) => { | ||
const rtlServiceDecorator = withServicesKnob({ | ||
defaultService: 'arabic', | ||
services: ['arabic', 'persian', 'urdu', 'pashto'], | ||
}); | ||
storiesOf(`${kind}/RTL`, module).add(`RTL - ${name}`, () => | ||
rtlServiceDecorator(storyFn), | ||
); | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const buildRTLSubstories = (storyKind = '', { include = [] } = {}) => { | ||
const allStories = getStorybook(); | ||
const { stories } = allStories.find(matchesStoryKind(storyKind)); | ||
|
||
if (include.length) { | ||
include.forEach(name => { | ||
const { render } = stories.find(matchesStoryName(name)); | ||
buildRTLSubstory(storyKind, name, render); | ||
}); | ||
} else { | ||
stories.forEach(({ name, render }) => | ||
buildRTLSubstory(storyKind, name, render), | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import withServicesKnob from './withServicesKnob'; | ||
import buildRTLSubstories from './buildRTLSubstories'; | ||
import { buildRTLSubstories } from './buildRTLSubstories'; | ||
import LANGUAGE_VARIANTS from './text-variants'; | ||
|
||
export { LANGUAGE_VARIANTS, withServicesKnob, buildRTLSubstories }; |