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

DetailCell: Add variant stories #2407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
122 changes: 122 additions & 0 deletions __docs__/wonder-blocks-cell/detail-cell-variants.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import * as React from "react";
import {StyleSheet} from "aphrodite";
import type {Meta, StoryObj} from "@storybook/react";

import {PropsFor, View} from "@khanacademy/wonder-blocks-core";
import {spacing} from "@khanacademy/wonder-blocks-tokens";
import {DetailCell} from "@khanacademy/wonder-blocks-cell";
import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon";
import {IconMappings} from "../wonder-blocks-icon/phosphor-icon.argtypes";
import {LabelSmall} from "@khanacademy/wonder-blocks-typography";

/**
* The following stories are used to generate the pseudo states for the
* DetailCell component. This is only used for visual testing in Chromatic.
*/
export default {
title: "Packages / Cell / DetailCell / All Variants",
parameters: {
docs: {
autodocs: false,
},
backgrounds: {
default: "offWhite",
},
},
} as Meta;

type StoryComponentType = StoryObj<typeof DetailCell>;

const states = [
{
label: "Default",
props: {},
},
{
label: "Disabled",
props: {disabled: true},
},
{
label: "Active",
props: {active: true},
},
];

const defaultProps = {
title: "Title for article item",
subtitle1: "Subtitle 1 for article item",
subtitle2: "Subtitle 2 for article item",
leftAccessory: (
<PhosphorIcon icon={IconMappings.playCircle} size="medium" />
),
rightAccessory: <PhosphorIcon icon={IconMappings.caretRight} />,
};

const States = (props: {label: string} & PropsFor<typeof DetailCell>) => {
return (
<View>
<View style={[styles.scenarios]}>
{states.map((scenario) => {
return (
<View style={styles.scenario} key={scenario.label}>
<LabelSmall>
{props.label} ({scenario.label})
</LabelSmall>
<DetailCell {...props} {...scenario.props} />
</View>
);
})}
</View>
</View>
);
};

const AllVariants = () => (
<View style={{gap: spacing.large_24}}>
<States label="Default" {...defaultProps} />
<States label="Clickable" {...defaultProps} onClick={() => {}} />
<States label="Link" {...defaultProps} href="/" />
</View>
);

export const Default: StoryComponentType = {
render: AllVariants,
};

export const Hover: StoryComponentType = {
render: AllVariants,
parameters: {pseudo: {hover: true}},
};

export const Focus: StoryComponentType = {
render: AllVariants,
parameters: {pseudo: {focusVisible: true}},
};

export const HoverFocus: StoryComponentType = {
name: "Hover + Focus",
render: AllVariants,
parameters: {pseudo: {hover: true, focusVisible: true}},
};

export const Active: StoryComponentType = {
render: AllVariants,
parameters: {pseudo: {active: true}},
};

const styles = StyleSheet.create({
statesContainer: {
padding: spacing.medium_16,
},
scenarios: {
display: "flex",
flexDirection: "row",
alignItems: "center",
gap: spacing.xxxLarge_64,
flexWrap: "wrap",
},
scenario: {
gap: spacing.small_12,
overflow: "hidden",
},
});
125 changes: 125 additions & 0 deletions __docs__/wonder-blocks-cell/detail-cell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import packageConfig from "../../packages/wonder-blocks-cell/package.json";
import ComponentInfo from "../../.storybook/components/component-info";
import DetailCellArgTypes from "./detail-cell.argtypes";
import {IconMappings} from "../wonder-blocks-icon/phosphor-icon.argtypes";
import {LabelSmall} from "@khanacademy/wonder-blocks-typography";

export default {
title: "Packages / Cell / DetailCell",
Expand Down Expand Up @@ -344,6 +345,130 @@ export const DetailCellsAsListItems: StoryComponentType = {
},
};

export const Scenarios = () => {
const longText =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ";
const longTextWithNoWordBreak =
"Loremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua";

const defaultProps = {
title: "Title for article item",
subtitle1: "Subtitle 1 for article item",
subtitle2: "Subtitle 2 for article item",
leftAccessory: (
<PhosphorIcon icon={IconMappings.playCircle} size="medium" />
),
rightAccessory: <PhosphorIcon icon={IconMappings.caretRight} />,
};

const scenarios = [
{
label: "Default",
props: defaultProps,
},
{
label: "No Icons",
props: {
...defaultProps,
leftAccessory: undefined,
rightAccessory: undefined,
},
},
{
label: "Left Icon Only",
props: {
...defaultProps,
rightAccessory: undefined,
},
},
{
label: "Right Icon Only",
props: {
...defaultProps,
leftAccessory: undefined,
},
},
{
label: "No Subtitles",
props: {
...defaultProps,
subtitle1: undefined,
subtitle2: undefined,
},
},
{
label: "Subtitle 1 only",
props: {
...defaultProps,
subtitle2: undefined,
},
},
{
label: "Subtitle 2 only",
props: {
...defaultProps,
subtitle1: undefined,
},
},
{
label: "Title only",
props: {
title: defaultProps.title,
},
},
{
label: "Long Text",
props: {
...defaultProps,
title: longText,
subtitle1: longText,
subtitle2: longText,
},
},
{
label: "Long Text No Word Break",
props: {
...defaultProps,
title: longTextWithNoWordBreak,
subtitle1: longTextWithNoWordBreak,
subtitle2: longTextWithNoWordBreak,
},
},
{
label: "Long Text (no icons)",
props: {
...defaultProps,
title: longText,
subtitle1: longText,
subtitle2: longText,
leftAccessory: undefined,
rightAccessory: undefined,
},
},
{
label: "Long Text No Word Break (no icons)",
props: {
...defaultProps,
title: longTextWithNoWordBreak,
subtitle1: longTextWithNoWordBreak,
subtitle2: longTextWithNoWordBreak,
leftAccessory: undefined,
rightAccessory: undefined,
},
},
];
return (
<View style={{gap: spacing.large_24}}>
{scenarios.map((scenario) => (
<>
<LabelSmall>{scenario.label}</LabelSmall>
<DetailCell {...scenario.props} />
</>
))}
</View>
);
};

const styles = StyleSheet.create({
example: {
backgroundColor: color.offWhite,
Expand Down
Loading