Skip to content

Commit

Permalink
Merge pull request #5414 from JedWatson/luke/more-stories
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebennett88 authored Oct 24, 2022
2 parents 996d33b + c951910 commit f9219c7
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 124 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
"url": "https://github.com/JedWatson/react-select.git"
},
"dependencies": {
"@babel/core": "^7.12.0",
"@babel/core": "^7.19.6",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-private-methods": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.12.0",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.12.0",
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.12.1",
"@babel/preset-typescript": "^7.12.7",
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.12.0",
"@changesets/cli": "^2.17.0",
"@changesets/get-github-info": "^0.5.0",
"@emotion/babel-plugin": "^11.0.0",
"@emotion/babel-plugin": "^11.10.2",
"@emotion/jest": "^11.1.0",
"@manypkg/cli": "^0.19.2",
"@preconstruct/cli": "^1.0.0",
Expand All @@ -42,7 +42,7 @@
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.0",
"babel-loader": "^8.2.5",
"concurrently": "^3.5.1",
"copy-webpack-plugin": "^5.0.3",
"coveralls": "^2.11.12",
Expand Down
1 change: 1 addition & 0 deletions storybook/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config: StorybookConfig = {
builder: 'webpack4',
},
features: {
postcss: false,
/**
* Enable code splitting
* @see https://storybook.js.org/docs/react/builders/webpack#code-splitting
Expand Down
5 changes: 4 additions & 1 deletion storybook/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export const parameters = {
options: {
storySort: {
order: ['Select', ['Basic', 'Animated']],
order: [
'Select',
['BasicSingle', 'BasicMulti', 'AnimatedMulti', 'Grouped', 'Creatable'],
],
},
},
};
44 changes: 44 additions & 0 deletions storybook/components/field.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as React from 'react';

type FieldProps = {
label?: string;
secondaryLabel?: string;
children: React.ReactNode;
htmlFor: string;
};

export function Field({
children,
htmlFor,
label = 'Select',
secondaryLabel,
}: FieldProps) {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
fontFamily: 'system-ui',
gap: '0.5rem',
}}
>
<label
htmlFor={htmlFor}
style={{
fontWeight: 500,
display: 'flex',
flexDirection: 'column',
gap: '0.5rem',
}}
>
<span>{label}</span>
{secondaryLabel && (
<span style={{ fontWeight: 400, opacity: 0.7 }}>
{secondaryLabel}
</span>
)}
</label>
{children}
</div>
);
}
131 changes: 128 additions & 3 deletions storybook/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export const colourOptions = [
export type ColourOption = {
readonly value: string;
readonly label: string;
readonly color: string;
readonly isFixed?: boolean;
readonly isDisabled?: boolean;
};

export const colourOptions: readonly ColourOption[] = [
{ value: 'ocean', label: 'Ocean', color: '#00B8D9', isFixed: true },
{ value: 'blue', label: 'Blue', color: '#0052CC', isDisabled: true },
{ value: 'purple', label: 'Purple', color: '#5243AA' },
Expand All @@ -9,13 +17,130 @@ export const colourOptions = [
{ value: 'forest', label: 'Forest', color: '#00875A' },
{ value: 'slate', label: 'Slate', color: '#253858' },
{ value: 'silver', label: 'Silver', color: '#666666' },
] as const;
];

export type FlavourOption = {
readonly value: string;
readonly label: string;
readonly rating: string;
};

export const flavourOptions: readonly FlavourOption[] = [
{ value: 'vanilla', label: 'Vanilla', rating: 'safe' },
{ value: 'chocolate', label: 'Chocolate', rating: 'good' },
{ value: 'strawberry', label: 'Strawberry', rating: 'wild' },
{ value: 'salted-caramel', label: 'Salted Caramel', rating: 'crazy' },
];

export type StateOption = {
readonly value: string;
readonly label: string;
};

export const stateOptions: readonly StateOption[] = [
{ value: 'AL', label: 'Alabama' },
{ value: 'AK', label: 'Alaska' },
{ value: 'AS', label: 'American Samoa' },
{ value: 'AZ', label: 'Arizona' },
{ value: 'AR', label: 'Arkansas' },
{ value: 'CA', label: 'California' },
{ value: 'CO', label: 'Colorado' },
{ value: 'CT', label: 'Connecticut' },
{ value: 'DE', label: 'Delaware' },
{ value: 'DC', label: 'District Of Columbia' },
{ value: 'FM', label: 'Federated States Of Micronesia' },
{ value: 'FL', label: 'Florida' },
{ value: 'GA', label: 'Georgia' },
{ value: 'GU', label: 'Guam' },
{ value: 'HI', label: 'Hawaii' },
{ value: 'ID', label: 'Idaho' },
{ value: 'IL', label: 'Illinois' },
{ value: 'IN', label: 'Indiana' },
{ value: 'IA', label: 'Iowa' },
{ value: 'KS', label: 'Kansas' },
{ value: 'KY', label: 'Kentucky' },
{ value: 'LA', label: 'Louisiana' },
{ value: 'ME', label: 'Maine' },
{ value: 'MH', label: 'Marshall Islands' },
{ value: 'MD', label: 'Maryland' },
{ value: 'MA', label: 'Massachusetts' },
{ value: 'MI', label: 'Michigan' },
{ value: 'MN', label: 'Minnesota' },
{ value: 'MS', label: 'Mississippi' },
{ value: 'MO', label: 'Missouri' },
{ value: 'MT', label: 'Montana' },
{ value: 'NE', label: 'Nebraska' },
{ value: 'NV', label: 'Nevada' },
{ value: 'NH', label: 'New Hampshire' },
{ value: 'NJ', label: 'New Jersey' },
{ value: 'NM', label: 'New Mexico' },
{ value: 'NY', label: 'New York' },
{ value: 'NC', label: 'North Carolina' },
{ value: 'ND', label: 'North Dakota' },
{ value: 'MP', label: 'Northern Mariana Islands' },
{ value: 'OH', label: 'Ohio' },
{ value: 'OK', label: 'Oklahoma' },
{ value: 'OR', label: 'Oregon' },
{ value: 'PW', label: 'Palau' },
{ value: 'PA', label: 'Pennsylvania' },
{ value: 'PR', label: 'Puerto Rico' },
{ value: 'RI', label: 'Rhode Island' },
{ value: 'SC', label: 'South Carolina' },
{ value: 'SD', label: 'South Dakota' },
{ value: 'TN', label: 'Tennessee' },
{ value: 'TX', label: 'Texas' },
{ value: 'UT', label: 'Utah' },
{ value: 'VT', label: 'Vermont' },
{ value: 'VI', label: 'Virgin Islands' },
{ value: 'VA', label: 'Virginia' },
{ value: 'WA', label: 'Washington' },
{ value: 'WV', label: 'West Virginia' },
{ value: 'WI', label: 'Wisconsin' },
{ value: 'WY', label: 'Wyoming' },
];

export const optionLength = [
{ value: 1, label: 'general' },
{
value: 2,
label:
'Evil is the moment when I lack the strength to be true to the Good that compels me.',
},
{
value: 3,
label:
"It is now an easy matter to spell out the ethic of a truth: 'Do all that you can to persevere in that which exceeds your perseverance. Persevere in the interruption. Seize in your being that which has seized and broken you.",
},
];

export const dogOptions = [
{ id: 1, label: 'Chihuahua' },
{ id: 2, label: 'Bulldog' },
{ id: 3, label: 'Dachshund' },
{ id: 4, label: 'Akita' },
];

export type GroupedOption = {
readonly label: string;
readonly options: readonly ColourOption[] | readonly FlavourOption[];
};

export const groupedOptions: readonly GroupedOption[] = [
{
label: 'Colours',
options: colourOptions,
},
{
label: 'Flavours',
options: flavourOptions,
},
];

export const defaultArgs = {
defaultMenuIsOpen: false,
defaultValue: undefined,
inputId: 'react-select-id',
isClearable: false,
isClearable: true,
isDisabled: false,
isLoading: false,
isMulti: false,
Expand Down
15 changes: 8 additions & 7 deletions storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"dev": "start-storybook -p 6006"
},
"dependencies": {
"@babel/core": "^7.12.0",
"@babel/preset-env": "^7.12.0",
"@babel/preset-typescript": "^7.12.7",
"@emotion/babel-plugin": "^11.0.0",
"@emotion/babel-preset-css-prop": "^10.0.0",
"babel-loader": "^8.0.0",
"@babel/core": "^7.19.6",
"@babel/preset-env": "^7.19.4",
"@babel/preset-typescript": "^7.18.6",
"@emotion/babel-plugin": "^11.10.2",
"@emotion/babel-preset-css-prop": "^11.10.0",
"babel-loader": "^8.2.5",
"react": "^16.13.0",
"react-dom": "^16.13.0"
"react-dom": "^16.13.0",
"webpack": "^4.30.0"
},
"devDependencies": {
"@storybook/addon-a11y": "^6.5.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import * as React from 'react';
import Select from 'react-select';
import makeAnimated from 'react-select/animated';

import { Field } from '../components/field';
import { colourOptions, defaultArgs } from '../data';

export default {
title: 'Select/Animated',
title: 'Select/AnimatedMulti',
component: Select,
} as ComponentMeta<typeof Select>;

Expand All @@ -17,24 +18,18 @@ const Template: ComponentStory<typeof Select> = ({
...props
}) => {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
fontFamily: 'system-ui',
gap: '0.5rem',
}}
<Field
htmlFor={inputId}
label="Animated Multi Select"
secondaryLabel="Removing an item from this list will trigger an exit animation."
>
<label htmlFor={inputId} style={{ fontWeight: 500 }}>
Select
</label>
<Select components={animatedComponents} inputId={inputId} {...props} />
</div>
</Field>
);
};

export const Animated = Template.bind({});
Animated.args = {
export const AnimatedMulti = Template.bind({});
AnimatedMulti.args = {
...defaultArgs,
defaultValue: [colourOptions[0], colourOptions[1], colourOptions[2]],
isMulti: true,
Expand Down
30 changes: 30 additions & 0 deletions storybook/stories/BasicMulti.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import * as React from 'react';
import Select from 'react-select';

import { Field } from '../components/field';
import { colourOptions, defaultArgs } from '../data';

export default {
title: 'Select/BasicMulti',
component: Select,
argTypes: {},
} as ComponentMeta<typeof Select>;

const Template: ComponentStory<typeof Select> = ({
inputId = 'react-select',
...props
}) => {
return (
<Field htmlFor={inputId} label="Basic Multi Select">
<Select inputId={inputId} {...props} />
</Field>
);
};

export const BasicMulti = Template.bind({});
BasicMulti.args = {
...defaultArgs,
defaultValue: [colourOptions[0], colourOptions[1], colourOptions[2]],
isMulti: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { ComponentMeta, ComponentStory } from '@storybook/react';
import * as React from 'react';
import Select from 'react-select';

import { Field } from '../components/field';
import { defaultArgs } from '../data';

/**
* More on default export:
* @see https://storybook.js.org/docs/react/writing-stories/introduction#default-export
*/
export default {
title: 'Select/Basic',
title: 'Select/BasicSingle',
component: Select,
/**
* More on argTypes:
Expand All @@ -27,27 +28,17 @@ const Template: ComponentStory<typeof Select> = ({
...props
}) => {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
fontFamily: 'system-ui',
gap: '0.5rem',
}}
>
<label htmlFor={inputId} style={{ fontWeight: 500 }}>
Select
</label>
<Field htmlFor={inputId}>
<Select inputId={inputId} {...props} />
</div>
</Field>
);
};

export const Basic = Template.bind({});
export const BasicSingle = Template.bind({});
/**
* More on args:
* @see https://storybook.js.org/docs/react/writing-stories/args
*/
Basic.args = {
BasicSingle.args = {
...defaultArgs,
};
Loading

0 comments on commit f9219c7

Please sign in to comment.