-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reintroduce the backgrounds addon (#229)
* feat: Reintroduce the backgrounds addon as a part of completing #200 . Includes both storiesOf and CSF examples of usage. NOTE: Reloading the app (e.g. via the emulator or due to making changes) causes the controls in "Addons => Backgrounds" to disappear on iOS. It works correctly on Android. Don't know what is causing this. * docs: Updated the README documentation for the backgrounds addon * feat: Reintroduce the backgrounds addon. Fix issue with reloading on iOS causing the "Backgrounds" section in addons to render nothing. Fixed this by switched to using the same approach that ondevice-controls seems to use. * Code review comments: - Add dependency to @storybook/addon-ondevice-backgrounds in the examples/native package.json - Add the withBackgrounds decorator to all stories in examples/native via preview.js * fix: text now shows without dimenions.get(window) * fix: update code sample Co-authored-by: Daniel Williams <[email protected]>
- Loading branch information
1 parent
9346732
commit a1c0efd
Showing
7 changed files
with
103 additions
and
65 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
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,16 +1,24 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
// import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; | ||
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; | ||
|
||
export const decorators = [ | ||
(StoryFn) => ( | ||
<View style={styles.container}> | ||
<StoryFn /> | ||
</View> | ||
), | ||
withBackgrounds, | ||
]; | ||
export const parameters = { my_param: 'anything' }; | ||
export const parameters = { | ||
my_param: 'anything', | ||
backgrounds: [ | ||
{ name: 'plain', value: 'white', default: true }, | ||
{ name: 'warm', value: 'hotpink' }, | ||
{ name: 'cool', value: 'deepskyblue' }, | ||
], | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { padding: 8 }, | ||
container: { padding: 8, flex: 1 }, | ||
}); |
16 changes: 16 additions & 0 deletions
16
examples/native/components/BackgroundExample/Background.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { addDecorator, storiesOf } from '@storybook/react-native'; | ||
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; | ||
import { Text } from 'react-native'; | ||
|
||
// Remember to also include '@storybook/addon-ondevice-backgrounds' in your addons config: see /examples/native/.storybook/main.js | ||
addDecorator(withBackgrounds); | ||
|
||
storiesOf('Background StoriesOf', module) | ||
.addParameters({ | ||
backgrounds: [ | ||
{ name: 'warm', value: 'hotpink', default: true }, | ||
{ name: 'cool', value: 'deepskyblue' }, | ||
], | ||
}) | ||
.add('Basic', () => <Text>Change background color via Addons -> Background</Text>); |
30 changes: 30 additions & 0 deletions
30
examples/native/components/BackgroundExample/BackgroundCsf.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react-native'; | ||
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; | ||
import { Text, StyleSheet } from 'react-native'; | ||
|
||
const Background = () => ( | ||
<Text style={styles.text}>Change background color via Addons -> Background</Text> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
text: { color: 'black' }, | ||
}); | ||
|
||
const BackgroundMeta: ComponentMeta<typeof Background> = { | ||
title: 'Background CSF', | ||
component: Background, | ||
decorators: [withBackgrounds], | ||
parameters: { | ||
backgrounds: [ | ||
{ name: 'warm', value: 'hotpink', default: true }, | ||
{ name: 'cool', value: 'deepskyblue' }, | ||
], | ||
}, | ||
}; | ||
|
||
export default BackgroundMeta; | ||
|
||
type BackgroundStory = ComponentStory<typeof Background>; | ||
|
||
export const Basic: BackgroundStory = () => <Background />; |
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