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

add storybook with buttons #3792

Merged
merged 2 commits into from
Dec 9, 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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"react/sort-comp": 1,
"space-before-function-paren": [1, {"anonymous": "always", "named": "always"}],
"space-in-parens": [1],
"template-curly-spacing": ["warn", "never"]
"template-curly-spacing": ["warn", "never"],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
},
"plugins": [
"react",
Expand Down
22 changes: 22 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-webpack5",
options: {
builder: {
useSWC: true,
},
},
},
docs: {
autodocs: "tag",
},
};
export default config;
14 changes: 14 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type { import('@storybook/react').Preview } */
const preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
44,602 changes: 29,050 additions & 15,552 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,30 @@
"readyTest-Browser": "./node_modules/.bin/wdio ./tests/browserstack/wdio.config.js",
"autoTest": " mocha --require @babel/register --require tests/component/index.js \"./tests/component/tests.js\" && npm run lint",
"snyk-protect": "snyk-protect",
"prepare": "npm run snyk-protect"
"prepare": "npm run snyk-protect",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@babel/plugin-proposal-class-properties": "^7.12.13",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.13.6",
"@babel/preset-env": "^7.13.15",
"@babel/preset-react": "^7.12.1",
"@babel/register": "^7.13.16",
"@snyk/protect": "^1.657.0",
"@storybook/addon-essentials": "^7.6.3",
"@storybook/addon-interactions": "^7.6.3",
"@storybook/addon-links": "^7.6.3",
"@storybook/addon-onboarding": "^1.0.9",
"@storybook/blocks": "^7.6.3",
"@storybook/react": "^7.6.3",
"@storybook/react-webpack5": "^7.6.3",
"@storybook/test": "^7.6.3",
"@wdio/browserstack-service": "^8.15.10",
"@wdio/cli": "^8.15.10",
"@wdio/config": "^8.15.10",
Expand All @@ -69,6 +81,7 @@
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-storybook": "^0.6.15",
"eslint-plugin-wdio": "^8.8.7",
"eslint-webpack-plugin": "^2.4.3",
"express": "^4.17.1",
Expand All @@ -82,6 +95,7 @@
"pre-commit": "^1.2.2",
"react-hot-loader": "^4.13.1",
"remove-files-webpack-plugin": "^1.5.0",
"storybook": "^7.6.3",
"terser-webpack-plugin": "^5.1.2",
"unused-webpack-plugin": "^2.4.0",
"webdriver": "^8.15.10",
Expand Down Expand Up @@ -147,5 +161,10 @@
"rxjs": "^6.6.7",
"styled-components": "~5.3.11",
"topojson-client": "^3.1.0"
},
"eslintConfig": {
"extends": [
"plugin:storybook/recommended"
]
}
}
12 changes: 12 additions & 0 deletions src/js/common/components/Style/Colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const colors = {
primary: '#0834CD',
primaryHover: '#09288A',
secondaryHover: '#F5F7FD',
darkGrey: '#454F69',
middleGrey: '#8C92A2',
grey: '#AEB2BE',
lightGrey: '#E5E6EA',
white: '#ffffff',
};

export default colors;
50 changes: 50 additions & 0 deletions src/js/common/stories/Button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// import React from 'react';
// import PropTypes from 'prop-types';
// import './button.css';

// /**
// * Primary UI component for user interaction
// */
// export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
// const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
// return (
// <button
// type="button"
// className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
// style={backgroundColor && { backgroundColor }}
// {...props}
// >
// {label}
// </button>
// );
// };

// Button.propTypes = {
// /**
// * Is this the principal call to action on the page?
// */
// primary: PropTypes.bool,
// /**
// * What background color to use
// */
// backgroundColor: PropTypes.string,
// /**
// * How large should the button be?
// */
// size: PropTypes.oneOf(['small', 'medium', 'large']),
// /**
// * Button contents
// */
// label: PropTypes.string.isRequired,
// /**
// * Optional click handler
// */
// onClick: PropTypes.func,
// };

// Button.defaultProps = {
// backgroundColor: null,
// primary: false,
// size: 'medium',
// onClick: undefined,
// };
88 changes: 88 additions & 0 deletions src/js/common/stories/Button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';
import styled from 'styled-components';
import Button from '../../components/Buttons/BaseButton';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
export default {
title: 'Example/Button',
component: Button,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
// argTypes: {
// backgroundColor: { control: 'color' },
// },
args: {
primary: true,
},
};

export const Primary = {
args: {
primary: true,
label: 'Button',
},
};

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const AllButtons = (args) => (
<ButtonContainer>
<Button {...Primary.args} primary size="large" label="Primary Large Disabled Button" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<Button {...Primary.args} primary={false} size="large" label="PrimaryLarge Disabled Button" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<Button {...Primary.args} primary label="Primary Medium Button" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<Button {...PrimaryDisabled.args} primary={false} label="Primary Medium Disabled Button" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<Button {...Primary.args} primary size="small" label="Primary Small Button" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<Button {...PrimaryDisabled.args} primary={false} size="small" label="Primary Small Disabled" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<Button {...Secondary.args} secondary label="Secondary Button" />
</ButtonContainer>
);

export const PrimaryDisabled = {
args: {
primary: false,
label: 'Button',
},
};

export const Secondary = {
args: {
secondary: true,
label: 'Button',
},
};

export const Large = {
args: {
primary: true,
size: 'large',
label: 'Button',
},
};

export const Medium = {
args: {
primary: true,
size: 'medium',
label: 'Button',
},
};

export const Small = {
args: {
primary: true,
size: 'small',
label: 'Button',
},
};

const ButtonContainer = styled.div`
display: flex;
align-items: center;
justify-content: center;
gap: 34px;
flex-direction: column;
`;
Loading