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

Modernize Perseus' components folder stories #1802

Merged
merged 17 commits into from
Oct 31, 2024
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
6 changes: 6 additions & 0 deletions .changeset/old-lamps-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/math-input": patch
"@khanacademy/perseus": patch
---

Improve prop types for various components
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ MafsWithLockedFiguresCurrent.parameters = {
chromatic: {
// Disabling because this isn't visually testing anything on the
// initial load of the editor page.
disable: true,
disableSnapshot: true,
},
};

Expand Down Expand Up @@ -413,7 +413,7 @@ WithSaveWarnings.parameters = {
// Disabling because this isn't testing anything visually on the
// editor page. It's testing the error message, which don't
// even show up on the initial load.
disable: true,
disableSnapshot: true,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Controlled.parameters = {
chromatic: {
// Disable the snapshot for this story because it's testing
// behavior, not visuals.
disable: true,
disableSnapshot: true,
},
};

Expand Down Expand Up @@ -77,6 +77,6 @@ LongPageScroll.parameters = {
chromatic: {
// Disable the snapshot for this story because it's testing
// behavior, not visuals.
disable: true,
disableSnapshot: true,
},
};
27 changes: 11 additions & 16 deletions packages/perseus/src/components/__stories__/graph.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import * as React from "react";

import Graph from "../graph";

import type {StoryObj, Meta} from "@storybook/react";

type StoryArgs = StoryObj<Graph>;

type Story = Meta<Graph>;
type Story = StoryObj<typeof Graph>;

const size = 200;

export default {
const meta: Meta = {
title: "Perseus/Components/Graph",
} as Story;

export const SquareBoxSizeAndOtherwiseEmpty = (
args: StoryArgs,
): React.ReactElement => {
return <Graph box={[size, size]} />;
component: Graph,
args: {
box: [size, size],
jeremywiebe marked this conversation as resolved.
Show resolved Hide resolved
},
};
export default meta;

export const SquareBoxSizeAndOtherwiseEmpty: Story = {};

export const LabeledSquaredBox = (args: StoryArgs): React.ReactElement => {
return (
<Graph box={[size, size]} labels={["First label", "Second label"]} />
);
export const LabeledSquaredBox: Story = {
args: {labels: ["First label", "Second label"]},
};
33 changes: 16 additions & 17 deletions packages/perseus/src/components/__stories__/graphie.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ import Graphie from "../graphie";

import type {StoryObj, Meta} from "@storybook/react";

type StoryArgs = StoryObj<Graphie>;

type Story = Meta<Graphie>;
type Story = StoryObj<typeof Graphie>;

const size = 200;

export default {
const meta: Meta = {
title: "Perseus/Components/Graphie",
} as Story;

export const SquareBoxSizeAndOtherwiseEmpty = (
args: StoryArgs,
): React.ReactElement => {
return (
<Graphie
box={[size, size]}
setDrawingAreaAvailable={() => {}}
setup={() => {}}
/>
);
component: Graphie,
args: {
box: [size, size],
setup: () => {},
setDrawingAreaAvailable: () => {},
},
};
export default meta;

export const SquareBoxSizeAndOtherwiseEmpty: Story = {};

export const PieChartGraphieLabels = (args: StoryArgs): React.ReactElement => {
/**
* A demonstration of a Graphie rendered using the Perseus `Renderer` complete
* with overlaid labels and an image caption below.
*/
export const PieChartGraphieLabels = () => {
return <ServerItemRendererWithDebugUI item={itemWithPieChart} />;
};
nishasy marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 12 additions & 26 deletions packages/perseus/src/components/__stories__/hud.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
import * as React from "react";
import {action} from "@storybook/addon-actions";

import Hud from "../hud";

import type {StoryObj, Meta} from "@storybook/react";

type StoryArgs = StoryObj<typeof Hud>;
type Story = StoryObj<typeof Hud>;

type Story = Meta<typeof Hud>;

export default {
const meta: Meta = {
title: "Perseus/Components/HUD",
} as Story;

export const TestMessageDisabled = (args: StoryArgs): React.ReactElement => {
return (
<Hud
fixedPosition={false}
message="Test message"
enabled={false}
onClick={() => {}}
/>
);
component: Hud,
args: {
enabled: true,
fixedPosition: false,
message: "Test message",
onClick: action("onClick"),
},
};
export default meta;

export const TestMessageEnabled = (args: StoryArgs): React.ReactElement => {
return (
<Hud
fixedPosition={false}
message="Test message"
enabled={true}
onClick={() => {}}
/>
);
};
export const Default: Story = {};
27 changes: 12 additions & 15 deletions packages/perseus/src/components/__stories__/icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import * as React from "react";

import * as IconPaths from "../../icon-paths";
import IconComponent from "../icon";

import type {StoryObj, Meta} from "@storybook/react";

type StoryArgs = StoryObj<IconComponent>;

type Story = Meta<IconComponent>;
type Story = StoryObj<typeof IconComponent>;

export default {
title: "Perseus/Components",
const meta: Meta = {
title: "Perseus/Components/Icon",
jeremywiebe marked this conversation as resolved.
Show resolved Hide resolved
component: IconComponent,
args: {
color: "#808",
size: 25,
Expand All @@ -27,12 +24,12 @@ export default {
control: "select",
},
},
} as Story;
};
export default meta;

export const Icon = (args: StoryArgs): React.ReactElement => (
<IconComponent
style={{display: "block"}}
icon={IconPaths.iconCheck}
{...args}
/>
);
export const Icon: Story = {
args: {
style: {display: "block"},
icon: IconPaths.iconCheck,
},
};
Original file line number Diff line number Diff line change
@@ -1,60 +1,48 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
import * as React from "react";

type StoryArgs = Record<any, any>;

type Story = {
title: string;
};

import ImageLoader from "../image-loader";

import type {Meta, StoryObj} from "@storybook/react";

const svgUrl = "http://www.khanacademy.org/images/ohnoes-concerned.svg";
const imgUrl = "https://www.khanacademy.org/images/hand-tree.new.png";

export default {
const meta: Meta = {
title: "Perseus/Components/Image Loader",
} as Story;

export const SvgImage = (args: StoryArgs): React.ReactElement => {
return (
<ImageLoader
src={svgUrl}
preloader={null}
imgProps={{
alt: "ALT",
}}
onUpdate={() => {}}
/>
);
component: ImageLoader,
args: {
preloader: null,
imgProps: {
alt: "ALT",
},
onUpdate: () => {},
},
parameters: {
chromatic: {
// This component only deals with loading images and providing a
// fallback if it fails. This is not very useful to snapshot so
// we're disabling it.
disableSnapshot: true,
},
},
};
export default meta;

type Story = StoryObj<typeof ImageLoader>;

export const SvgImage: Story = {
args: {
src: svgUrl,
},
jeremywiebe marked this conversation as resolved.
Show resolved Hide resolved
};

export const PngImage = (args: StoryArgs): React.ReactElement => {
return (
<ImageLoader
src={imgUrl}
preloader={null}
imgProps={{
alt: "ALT",
}}
onUpdate={() => {}}
/>
);
export const PngImage: Story = {
args: {src: imgUrl},
};

export const InvalidImageWithChildrenForFailedLoading = (
args: StoryArgs,
): React.ReactElement => {
return (
<ImageLoader
src="http://abcdefiahofshiaof.noway.badimage.com"
preloader={null}
imgProps={{
alt: "ALT",
}}
onUpdate={() => {}}
>
<span>You can see me! The image failed to load.</span>
</ImageLoader>
);
export const InvalidImageWithChildrenForFailedLoading: Story = {
args: {
src: "http://abcdefiahofshiaof.noway.badimage.com",
children: <span>You can see me! The image failed to load.</span>,
},
};
50 changes: 28 additions & 22 deletions packages/perseus/src/components/__stories__/info-tip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ import * as React from "react";

import InfoTip from "../info-tip";

type StoryArgs = Record<any, any>;
import type {Meta, StoryObj} from "@storybook/react";

type Story = {
title: string;
const meta: Meta = {
title: "Perseus/Components/Info Tip",
component: InfoTip,
};
export default meta;

export default {
title: "Perseus/Components/Info Tip",
} as Story;
type Story = StoryObj<typeof InfoTip>;

export const TextOnMouseover = (args: StoryArgs): React.ReactElement => {
return <InfoTip>Sample text</InfoTip>;
export const TextOnMouseover: Story = {
args: {
children: "Sample text",
},
};

export const CodeInText = (args: StoryArgs): React.ReactElement => {
return (
<InfoTip>
Settings that you add here are available to the program as an object
returned by <code>Program.settings()</code>
</InfoTip>
);
export const CodeInText: Story = {
args: {
children: (
<>
Settings that you add here are available to the program as an
object returned by <code>Program.settings()</code>
</>
),
},
};

export const MultipleElements = (args: StoryArgs): React.ReactElement => {
return (
<InfoTip>
<p>First paragraph</p>
<p>Second paragraph</p>
</InfoTip>
);
export const MultipleElements: Story = {
args: {
children: (
<>
<p>First paragraph</p>
<p>Second paragraph</p>
</>
),
},
};
Loading