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

refactor: Convert Overlay story to csf format #7412

Merged
merged 3 commits into from
Oct 25, 2023
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
1 change: 1 addition & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
stories: [
'../app/component-library/components/Cards/Card/**/*.stories.?(ts|tsx|js|jsx)',
'../app/component-library/components/Banners/Banner/variants/BannerAlert/**/*.stories.?(ts|tsx|js|jsx)',
'../app/component-library/components/Overlay/**/*.stories.?(ts|tsx|js|jsx)',
'../app/component-library/components/Icons/**/*.stories.?(ts|tsx|js|jsx)',
'../app/component-library/components/Checkbox/**/*.stories.?(ts|tsx|js|jsx)',
],
Expand Down
58 changes: 33 additions & 25 deletions .storybook/storybook.requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,56 @@ import {
addParameters,
addArgsEnhancer,
clearDecorators,
} from "@storybook/react-native";
} from '@storybook/react-native';

global.STORIES = [
{
titlePrefix: "",
directory: "./app/component-library/components/Cards/Card",
files: "**/*.stories.?(ts|tsx|js|jsx)",
titlePrefix: '',
directory: './app/component-library/components/Cards/Card',
files: '**/*.stories.?(ts|tsx|js|jsx)',
importPathMatcher:
"^\\.[\\\\/](?:app\\/component-library\\/components\\/Cards\\/Card(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$",
'^\\.[\\\\/](?:app\\/component-library\\/components\\/Cards\\/Card(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$',
},
{
titlePrefix: "",
titlePrefix: '',
directory:
"./app/component-library/components/Banners/Banner/variants/BannerAlert",
files: "**/*.stories.?(ts|tsx|js|jsx)",
'./app/component-library/components/Banners/Banner/variants/BannerAlert',
files: '**/*.stories.?(ts|tsx|js|jsx)',
importPathMatcher:
"^\\.[\\\\/](?:app\\/component-library\\/components\\/Banners\\/Banner\\/variants\\/BannerAlert(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$",
'^\\.[\\\\/](?:app\\/component-library\\/components\\/Banners\\/Banner\\/variants\\/BannerAlert(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$',
},
{
titlePrefix: "",
directory: "./app/component-library/components/Icons",
files: "**/*.stories.?(ts|tsx|js|jsx)",
titlePrefix: '',
directory: './app/component-library/components/Overlay',
files: '**/*.stories.?(ts|tsx|js|jsx)',
importPathMatcher:
"^\\.[\\\\/](?:app\\/component-library\\/components\\/Icons(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$",
'^\\.[\\\\/](?:app\\/component-library\\/components\\/Overlay(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$',
},
{
titlePrefix: "",
directory: "./app/component-library/components/Checkbox",
files: "**/*.stories.?(ts|tsx|js|jsx)",
titlePrefix: '',
directory: './app/component-library/components/Icons',
files: '**/*.stories.?(ts|tsx|js|jsx)',
importPathMatcher:
"^\\.[\\\\/](?:app\\/component-library\\/components\\/Checkbox(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$",
'^\\.[\\\\/](?:app\\/component-library\\/components\\/Icons(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$',
},
{
titlePrefix: '',
directory: './app/component-library/components/Checkbox',
files: '**/*.stories.?(ts|tsx|js|jsx)',
importPathMatcher:
'^\\.[\\\\/](?:app\\/component-library\\/components\\/Checkbox(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx|js|jsx)?)$',
},
];

import "@storybook/addon-ondevice-controls/register";
import '@storybook/addon-ondevice-controls/register';

import { decorators, parameters } from "./preview";
import { decorators, parameters } from './preview';

if (decorators) {
if (__DEV__) {
// stops the warning from showing on every HMR
require("react-native").LogBox.ignoreLogs([
"`clearDecorators` is deprecated and will be removed in Storybook 7.0",
require('react-native').LogBox.ignoreLogs([
'`clearDecorators` is deprecated and will be removed in Storybook 7.0',
]);
}
// workaround for global decorators getting infinitely applied on HMR, see https://github.com/storybookjs/react-native/issues/185
Expand All @@ -62,10 +69,11 @@ if (parameters) {

const getStories = () => {
return {
"./app/component-library/components/Cards/Card/Card.stories.tsx": require("../app/component-library/components/Cards/Card/Card.stories.tsx"),
"./app/component-library/components/Banners/Banner/variants/BannerAlert/BannerAlert.stories.tsx": require("../app/component-library/components/Banners/Banner/variants/BannerAlert/BannerAlert.stories.tsx"),
"./app/component-library/components/Icons/Icon/Icon.stories.tsx": require("../app/component-library/components/Icons/Icon/Icon.stories.tsx"),
"./app/component-library/components/Checkbox/Checkbox.stories.tsx": require("../app/component-library/components/Checkbox/Checkbox.stories.tsx"),
'./app/component-library/components/Cards/Card/Card.stories.tsx': require('../app/component-library/components/Cards/Card/Card.stories.tsx'),
'./app/component-library/components/Banners/Banner/variants/BannerAlert/BannerAlert.stories.tsx': require('../app/component-library/components/Banners/Banner/variants/BannerAlert/BannerAlert.stories.tsx'),
'./app/component-library/components/Overlay/Overlay.stories.tsx': require('../app/component-library/components/Overlay/Overlay.stories.tsx'),
'./app/component-library/components/Icons/Icon/Icon.stories.tsx': require('../app/component-library/components/Icons/Icon/Icon.stories.tsx'),
'./app/component-library/components/Checkbox/Checkbox.stories.tsx': require('../app/component-library/components/Checkbox/Checkbox.stories.tsx'),
};
};

Expand Down
43 changes: 19 additions & 24 deletions app/component-library/components/Overlay/Overlay.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
/* eslint-disable no-console, react-native/no-inline-styles */

/* eslint-disable react/display-name */
/* eslint-disable no-console */
// Third party dependencies.
import React from 'react';
import { color } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react-native';

// External dependencies.
import { mockTheme } from '../../../util/theme';
import { storybookPropsGroupID } from '../../constants/storybook.constants';

// Internal dependencies.
import Overlay from './Overlay';
import { OverlayProps } from './Overlay.types';

export const getOverlayStoryProps = (): OverlayProps => {
const colorSelector = color(
'color',
mockTheme.colors.overlay.default,
storybookPropsGroupID,
);

return {
color: colorSelector,
onPress: () => console.log("I'm clicked!"),
};
import { default as OverlayComponent } from './Overlay';

const OverlayMeta = {
title: 'Component Library / Overlay',
component: OverlayComponent,
argTypes: {
color: {
control: { type: 'color' },
defaultValue: mockTheme.colors.overlay.default,
georgewrmarshall marked this conversation as resolved.
Show resolved Hide resolved
},
},
};
export default OverlayMeta;

const OverlayStory = () => <Overlay {...getOverlayStoryProps()} />;

storiesOf('Component Library / Overlay', module).add('Overlay', OverlayStory);

export default OverlayStory;
export const Overlay = {
render: (args: any) => (
<OverlayComponent {...args} onPress={() => console.log("I'm clicked!")} />
),
};
Loading