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: simplify Select stories #1867

Merged
merged 1 commit into from
Jul 7, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,91 @@ import { Meta, StoryObj } from "@storybook/react";
import { Select, SelectProps } from "@okta/odyssey-react-mui";
import { MuiThemeDecorator } from "../../../../.storybook/components";

const optionsArray: SelectProps["options"] = [
"Earth",
"Mars",
"Ceres",
"Eros",
"Tycho Station",
"Phoebe",
"Ganymede",
];

const optionsObject: SelectProps["options"] = [
{
text: "Earth",
value: "earth",
},
{
text: "Mars",
value: "mars",
},
{
text: "Ceres",
value: "ceres",
},
{
text: "Eros",
value: "eros",
},
{
text: "Tycho Station",
value: "tycho-station",
},
{
text: "Phoebe",
value: "phoebe",
},
{
text: "Ganymede",
value: "ganymede",
},
];

const optionsGrouped: SelectProps["options"] = [
{
text: "Sol System",
type: "heading",
},
{
text: "Earth",
value: "earth",
},
{
text: "Mars",
value: "mars",
},
{
text: "Ceres",
value: "ceres",
},
{
text: "Eros",
value: "eros",
},
{
text: "Tycho Station",
value: "tycho-station",
},
{
text: "Phoebe",
value: "phoebe",
},
{
text: "Ganymede",
value: "ganymede",
},
{
text: "Extrasolar",
type: "heading",
},
"Auberon",
"Al-Halub",
"Freehold",
"Laconia",
"New Terra",
];

const storybookMeta: Meta<SelectProps> = {
title: "MUI Components/Forms/Select",
component: Select,
Expand Down Expand Up @@ -134,98 +219,14 @@ const storybookMeta: Meta<SelectProps> = {
args: {
hint: "Select your destination in the Sol system.",
label: "Destination",
options: optionsArray,
},
decorators: [MuiThemeDecorator],
tags: ["autodocs"],
};

export default storybookMeta;

const optionsArray: SelectProps["options"] = [
"Earth",
"Mars",
"Ceres",
"Eros",
"Tycho Station",
"Phoebe",
"Ganymede",
];

const optionsObject: SelectProps["options"] = [
{
text: "Earth",
value: "earth",
},
{
text: "Mars",
value: "mars",
},
{
text: "Ceres",
value: "ceres",
},
{
text: "Eros",
value: "eros",
},
{
text: "Tycho Station",
value: "tycho-station",
},
{
text: "Phoebe",
value: "phoebe",
},
{
text: "Ganymede",
value: "ganymede",
},
];

const optionsGrouped: SelectProps["options"] = [
{
text: "Sol System",
type: "heading",
},
{
text: "Earth",
value: "earth",
},
{
text: "Mars",
value: "mars",
},
{
text: "Ceres",
value: "ceres",
},
{
text: "Eros",
value: "eros",
},
{
text: "Tycho Station",
value: "tycho-station",
},
{
text: "Phoebe",
value: "phoebe",
},
{
text: "Ganymede",
value: "ganymede",
},
{
text: "Extrasolar",
type: "heading",
},
"Auberon",
"Al-Halub",
"Freehold",
"Laconia",
"New Terra",
];

const Template: StoryObj<SelectProps> = {
render: function C(args) {
return (
Expand All @@ -236,42 +237,7 @@ const Template: StoryObj<SelectProps> = {
isDisabled={args.isDisabled}
isMultiSelect={args.isMultiSelect}
isOptional={args.isOptional}
options={optionsArray}
/>
);
},
};

const ObjectTemplate: StoryObj<SelectProps> = {
render: function C(args) {
return (
<Select
label={args.label}
hint={args.hint}
errorMessage={args.errorMessage}
isDisabled={args.isDisabled}
isMultiSelect={args.isMultiSelect}
isOptional={args.isOptional}
options={optionsObject}
/>
);
},
args: {
hint: "Select your destination in the Sol system.",
},
};

const GroupTemplate: StoryObj<SelectProps> = {
render: function C(args) {
return (
<Select
label={args.label}
hint={args.hint}
errorMessage={args.errorMessage}
isDisabled={args.isDisabled}
isMultiSelect={args.isMultiSelect}
isOptional={args.isOptional}
options={optionsGrouped}
options={args.options}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't even need this template. CSF 3 format for Storybook does this for us. Just remove it completely, and we're good!

/>
);
},
Expand All @@ -297,7 +263,10 @@ export const Error: StoryObj<SelectProps> = {
};

export const OptionsObject: StoryObj<SelectProps> = {
...ObjectTemplate,
...Template,
args: {
options: optionsObject,
},
parameters: {
docs: {
description: {
Expand All @@ -309,7 +278,10 @@ export const OptionsObject: StoryObj<SelectProps> = {
};

export const OptionsGrouped: StoryObj<SelectProps> = {
...GroupTemplate,
...Template,
args: {
options: optionsGrouped,
},
parameters: {
docs: {
description: {
Expand Down