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

DBZ-6868: Storybook init #805

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14,054 changes: 11,270 additions & 2,784 deletions ui/package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions ui/packages/ui/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"sourceType": "unambiguous",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": 100,
"safari": 15,
"firefox": 91
}
}
],
"@babel/preset-react"
],
"plugins": []
}
3 changes: 2 additions & 1 deletion ui/packages/ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:react/recommended",
"prettier"
"prettier",
"plugin:storybook/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand Down
28 changes: 28 additions & 0 deletions ui/packages/ui/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { join, dirname } from 'path';

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}

/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-interactions'),
],
framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},
docs: {
autodocs: 'tag',
},
};
export default config;
14 changes: 14 additions & 0 deletions ui/packages/ui/.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$/,
},
},
},
};

export default preview;
25 changes: 21 additions & 4 deletions ui/packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"clean": "rimraf dist",
"test": "jest",
"i18n": "i18next 'src/**/**/*.{ts,tsx}' [-oc] -c './i18next-parser.config.js' -o './src/locales/$LOCALE/$NAMESPACE.json'",
"lint-staged": "npm run lint:fix && npm run format:fix"
"lint-staged": "npm run lint:fix && npm run format:fix",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"peerDependencies": {
"@patternfly/patternfly": "^4.115.2",
Expand All @@ -43,10 +45,25 @@
"eslint-config-prettier": "8.10.0",
"eslint-plugin-prettier": "4.2.1",
"prettier": "2.8.8",
"tslib": "2.6.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-i18next": "12.3.1",
"react-router-dom": "5.3.0"
"react-router-dom": "5.3.0",
"tslib": "2.6.2"
},
"devDependencies": {
"@babel/preset-env": "^7.22.15",
"@babel/preset-react": "^7.22.15",
"@storybook/addon-essentials": "^7.4.0",
"@storybook/addon-interactions": "^7.4.0",
"@storybook/addon-links": "^7.4.0",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/blocks": "^7.4.0",
"@storybook/react": "^7.4.0",
"@storybook/react-webpack5": "^7.4.0",
"@storybook/testing-library": "^0.2.0",
"eslint-plugin-storybook": "^0.6.13",
"prop-types": "^15.8.1",
"storybook": "^7.4.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export const CustomPropertiesStep: React.FunctionComponent<
properties.get(key)!.key
)
? 'Saved'
: 'Either key or value is empty'
: 'Not saved: either key or value is missing'
}
>
<Alert
Expand All @@ -310,11 +310,18 @@ export const CustomPropertiesStep: React.FunctionComponent<
</Tooltip>
</LevelItem>
<LevelItem>
<Button
<Tooltip
position="top"
content={
'Remove'
}
>
<Button
variant="link"
icon={<MinusCircleIcon />}
onClick={() => deleteProperty(key)}
/>
</Tooltip>
</LevelItem>
</Level>
</GridItem>
Expand Down
50 changes: 50 additions & 0 deletions ui/packages/ui/src/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,
};
45 changes: 45 additions & 0 deletions ui/packages/ui/src/stories/Button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Button } from './Button';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#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/react/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
},
};

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Primary = {
args: {
primary: true,
label: 'Button',
},
};

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

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

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