Skip to content

Commit

Permalink
creates separate InputOptionContent.stories
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSonOfThomp committed Jun 3, 2024
1 parent 82055b9 commit 34740be
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 61 deletions.
59 changes: 5 additions & 54 deletions packages/input-option/src/InputOption/InputOption.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
storybookExcludedControlParams,
StoryMetaType,
} from '@lg-tools/storybook-utils';
import { Decorator, StoryFn, StoryObj } from '@storybook/react';
import { StoryFn, StoryObj } from '@storybook/react';

import Icon, { glyphs } from '@leafygreen-ui/icon';

Expand All @@ -16,7 +16,7 @@ import {

import { InputOption, type InputOptionProps } from '.';

const meta: StoryMetaType<typeof InputOption> = {
export default {
title: 'Components/InputOption',
component: InputOption,
parameters: {
Expand Down Expand Up @@ -68,9 +68,7 @@ const meta: StoryMetaType<typeof InputOption> = {
},
as: storybookArgTypes.as,
},
};

export default meta;
} satisfies StoryMetaType<typeof InputOption>;

export const LiveExample: StoryFn<
InputOptionProps & InputOptionContentProps
Expand Down Expand Up @@ -99,57 +97,10 @@ export const Generated = {
parameters: {
generate: {
combineArgs: {
selected: [false, true],
disabled: [false, true],
},
},
},
} satisfies StoryObj<typeof InputOption>;

const _withContentDecorator: Decorator<InputOptionContentProps> = (
Instance,
ctx,
) => {
return (
<Instance>
<InputOptionContent
leftGlyph={ctx.args.leftGlyph}
rightGlyph={ctx.args.rightGlyph}
description={ctx.args.description}
{...ctx.args}
>
{ctx.args.children}
</InputOptionContent>
</Instance>
);
};

export const WithContent = {
render: () => <></>,
parameters: {
generate: {
args: {
showWedge: true,
},
combineArgs: {
description: [undefined, 'Description'],
preserveIconSpace: [false, true],
leftGlyph: [undefined, <Icon glyph="Cloud" />],
rightGlyph: [undefined, <Icon glyph="ChevronDown" />],
highlighted: [false, true],
checked: [false, true],
disabled: [false, true],
},
excludeCombinations: [
{
leftGlyph: undefined,
rightGlyph: <Icon glyph="ChevronDown" />,
},
{
preserveIconSpace: false,
leftGlyph: <Icon glyph="Cloud" />,
},
],
decorator: _withContentDecorator,
},
},
} satisfies StoryObj<typeof InputOptionContent>;
} satisfies StoryObj<typeof InputOption>;
12 changes: 7 additions & 5 deletions packages/input-option/src/InputOption/InputOption.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getInputOptionStyles = ({
checked,
isInteractive,
}: InputOptionStyleArgs) => {
const ixnState = highlighted || checked ? State.Focus : State.Default;
const ixnState = highlighted ? State.Focus : State.Default;
return css`
position: relative;
list-style: none;
Expand Down Expand Up @@ -66,8 +66,6 @@ export const getInputOptionStyles = ({
background-color: ${color[theme].background.primary.hover};
.${leftGlyphClassName} {
export const inputOptionClassName = createUniqueClassName('')
color: ${color[theme].icon.primary.hover};
}
}
Expand All @@ -77,6 +75,11 @@ export const inputOptionClassName = createUniqueClassName('')
outline: none;
border: unset;
}
${checked &&
css`
font-weight: 600;
`}
`}
`;
};
Expand All @@ -90,7 +93,6 @@ export const getInputOptionWedge = ({
theme,
disabled,
highlighted,
checked,
}: InputOptionStyleArgs) => css`
// Left wedge
&:before {
Expand All @@ -108,7 +110,7 @@ export const getInputOptionWedge = ({
transition: ${transitionDuration.default}ms ease-in-out;
transition-property: transform, background-color;
${(highlighted || checked) &&
${highlighted &&
css`
transform: scaleY(1) translateY(-50%);
background-color: ${color[theme].icon.primary.focus};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/* eslint-disable react/jsx-key */
import React from 'react';
import {
InstanceDecorator,
storybookArgTypes,
storybookExcludedControlParams,
StoryMetaType,
} from '@lg-tools/storybook-utils';
import { StoryObj } from '@storybook/react';

import Icon, { glyphs } from '@leafygreen-ui/icon';

import { InputOption } from '../InputOption';

import { InputOptionContent } from '.';

const _withInputOptionDecorator: InstanceDecorator<
typeof InputOption & typeof InputOptionContent
> = (Instance, ctx) => {
const {
args: { darkMode, highlighted, checked, disabled },
} = ctx || { args: {} };
return (
<InputOption
darkMode={darkMode}
highlighted={highlighted}
checked={checked}
disabled={disabled}
>
<Instance />
</InputOption>
);
};

export default {
title: 'Components/InputOption/Content',
component: InputOptionContent,
parameters: {
default: 'Basic',
controls: {
exclude: [...storybookExcludedControlParams],
},
generate: {
storyNames: ['Basic', 'Highlighted', 'Checked', 'Disabled'],
combineArgs: {
darkMode: [false, true],
description: [undefined, 'Description'],
preserveIconSpace: [false, true],
leftGlyph: [undefined, <Icon glyph="Cloud" />],
rightGlyph: [undefined, <Icon glyph="ChevronDown" />],
},
excludeCombinations: [
{
leftGlyph: undefined,
rightGlyph: <Icon glyph="ChevronDown" />,
},
{
preserveIconSpace: false,
leftGlyph: <Icon glyph="Cloud" />,
},
],
decorator: _withInputOptionDecorator,
},
},
args: {
children: 'Some text',
showWedge: true,
},
argTypes: {
disabled: {
control: 'boolean',
},
highlighted: {
control: 'boolean',
},
checked: {
control: 'boolean',
},
showWedge: {
control: 'boolean',
},
leftGlyph: {
options: Object.keys(glyphs),
control: { type: 'select' },
},
rightGlyph: {
options: Object.keys(glyphs),
control: { type: 'select' },
},
description: {
control: { type: 'text' },
},
as: storybookArgTypes.as,
},
} satisfies StoryMetaType<typeof InputOptionContent>;

export const Basic = {
render: () => <></>,
} satisfies StoryObj<typeof InputOptionContent>;

export const Highlighted = {
render: () => <></>,
parameters: {
generate: {
args: {
description: 'Description',
rightGlyph: <Icon glyph="ChevronDown" />,
highlighted: true,
},
},
},
} satisfies StoryObj<typeof InputOptionContent>;

export const Checked = {
render: () => <></>,
parameters: {
generate: {
args: {
description: 'Description',
rightGlyph: <Icon glyph="ChevronDown" />,
checked: true,
},
combineArgs: {
highlighted: [false, true],
},
},
},
} satisfies StoryObj<typeof InputOptionContent>;

export const Disabled = {
render: () => <></>,
parameters: {
generate: {
args: {
disabled: true,
},
},
},
} satisfies StoryObj<typeof InputOptionContent>;
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ export const getLeftGlyphStyles = ({
theme,
disabled,
highlighted,
selected,
}: InputOptionStyleArgs) => {
const variant = disabled ? Variant.Disabled : Variant.Primary;
const ixnState = highlighted || selected ? State.Focus : State.Default;
const ixnState = highlighted ? State.Focus : State.Default;

return css`
grid-area: left-glyph;
Expand Down

0 comments on commit 34740be

Please sign in to comment.