UNPKG

@storybook/addon-ondevice-backgrounds

Version:

A react-native storybook addon to show different backgrounds for your preview

24 lines (23 loc) 1.16 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const react_native_1 = require("react-native"); const constants_1 = __importDefault(require("./constants")); const Container = ({ initialBackground, channel, children }) => { const [background, setBackground] = (0, react_1.useState)(initialBackground || ''); (0, react_1.useEffect)(() => { channel.on(constants_1.default.UPDATE_BACKGROUND, setBackground); return () => { channel.removeListener(constants_1.default.UPDATE_BACKGROUND, setBackground); }; }, [channel]); return ((0, jsx_runtime_1.jsx)(react_native_1.View, { testID: "addon-backgrounds-container", style: [styles.container, background && { backgroundColor: background }], children: children })); }; exports.default = Container; const styles = react_native_1.StyleSheet.create({ container: { flex: 1, backgroundColor: 'transparent' }, });