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

Build: Generic stories for addon-controls #19149

Merged
merged 2 commits into from
Sep 10, 2022
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
83 changes: 83 additions & 0 deletions code/addons/controls/template/stories/basics.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import globalThis from 'global';
import { PartialStoryFn, StoryContext } from '@storybook/csf';

export default {
component: null,
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ component: globalThis.Components.Pre, args: { object: context.args } }),
],
argTypes: {
boolean: { control: 'boolean' },
color: { control: 'color' },
colorWithPresets: {
control: {
type: 'color',
presetColors: ['#ff0', 'pink', { color: '#00f', title: 'mystery' }],
},
},
colorStartOpen: { control: { type: 'color', startOpen: true } },
date: { control: 'date' },
file: { control: { type: 'file', accept: '.png' }, name: 'Image Urls' },
number: { control: 'number' },
object: { control: 'object' },
radio: { control: { type: 'radio', options: ['a', 'b', 'c'] } },
radioWithLabels: {
control: { type: 'radio', options: ['a', 'b', 'c'], labels: ['alpha', 'beta', 'gamma'] },
},
inlineRadio: { control: { type: 'inline-radio', options: ['a', 'b', 'c'] } },
select: { control: { type: 'select', options: ['a', 'b', 'c'] } },
multiSelect: { control: { type: 'multi-select', options: ['a', 'b', 'c'] } },
range: { control: 'range' },
rangeCustom: { control: { type: 'range', min: 0, max: 1000, step: 100 } },
text: { control: 'text' },
},
};

export const Undefined = {
args: {},
};

const DEFAULT_NESTED_OBJECT = {
text: 'Hello world',
boolean: true,
array: ['One', 'Two', 'Three'],
object: { a: 1, b: 2, c: 3 },
};
export const Defined = {
args: {
boolean: true,
color: '#ff0',
colorWithPresets: 'pink',
colorStartOpen: 'orange',
date: new Date(2010, 1, 1),
file: ['https://storybook.js.org/images/placeholders/350x150.png'],
number: 10,
object: DEFAULT_NESTED_OBJECT,
radio: 'a',
radioWithLabels: 'b',
inlineRadio: 'c',
select: 'b',
multiSelect: ['a'],
range: 15,
rangeCustom: 10,
text: 'hello',
},
};

// export const ImageFileControl = (args) => <img src={args.imageUrls[0]} alt="Your Example Story" />;
// ImageFileControl.args = {
// imageUrls: ['https://storybook.js.org/images/placeholders/350x150.png'],
// };

// const hasCycle: any = {};
// hasCycle.cycle = hasCycle;

// export const CyclicArgs = {
// args: process.env.NODE_ENV !== 'test' ? { object: hasCycle } : {},
// parameters: {
// docs: { disable: true },
// chromatic: { disable: true },
// storyshots: { disable: true },
// },
// };
62 changes: 62 additions & 0 deletions code/addons/controls/template/stories/conditional.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import globalThis from 'global';
import { PartialStoryFn, StoryContext } from '@storybook/csf';

export default {
component: null,
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ component: globalThis.Components.Pre, args: { object: context.args } }),
],
};

export const MutuallyExclusiveModes = {
argTypes: {
mutuallyExclusiveA: { control: 'text', if: { arg: 'mutuallyExclusiveB', truthy: false } },
mutuallyExclusiveB: { control: 'text', if: { arg: 'mutuallyExclusiveA', truthy: false } },
},
};

export const ToggleControl = {
argTypes: {
colorMode: {
control: 'boolean',
},
dynamicText: {
if: { arg: 'colorMode', truthy: false },
control: 'text',
},
dynamicColor: {
if: { arg: 'colorMode' },
control: 'color',
},
},
};

export const ToggleExpandCollapse = {
argTypes: {
advanced: {
control: 'boolean',
},
margin: {
control: 'number',
if: { arg: 'advanced' },
},
padding: {
control: 'number',
if: { arg: 'advanced' },
},
cornerRadius: {
control: 'number',
if: { arg: 'advanced' },
},
},
};

export const GlobalBased = {
argTypes: {
ifThemeExists: { control: 'text', if: { global: 'theme' } },
ifThemeNotExists: { control: 'text', if: { global: 'theme', exists: false } },
ifLightTheme: { control: 'text', if: { global: 'theme', eq: 'light' } },
ifNotLightTheme: { control: 'text', if: { global: 'theme', neq: 'light' } },
},
};
22 changes: 22 additions & 0 deletions code/addons/controls/template/stories/disable.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import globalThis from 'global';
import { PartialStoryFn, StoryContext } from '@storybook/csf';

export default {
component: null,
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ component: globalThis.Components.Pre, args: { object: context.args } }),
],
};

export const DisableTable = {
args: { a: 'a', b: 'b' },
argTypes: {
b: { table: { disable: true } },
},
};

export const DisableControl = {
args: { a: 'a', b: 'b' },
b: { control: { disable: true } },
};
47 changes: 47 additions & 0 deletions code/addons/controls/template/stories/filters.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import globalThis from 'global';
import { PartialStoryFn, StoryContext } from '@storybook/csf';

export default {
component: null,
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ component: globalThis.Components.Pre, args: { object: context.args } }),
],
args: {
helloWorld: 1,
helloPlanet: 1,
byeWorld: 1,
},
};

export const IncludeList = {
parameters: {
controls: {
include: ['helloWorld'],
},
},
};

export const IncludeRegex = {
parameters: {
controls: {
include: /hello*/,
},
},
};

export const ExcludeList = {
parameters: {
controls: {
exclude: ['helloPlanet', 'helloWorld'],
},
},
};

export const ExcludeRegex = {
parameters: {
controls: {
exclude: /hello*/,
},
},
};
16 changes: 16 additions & 0 deletions code/addons/controls/template/stories/issues.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import globalThis from 'global';
import { PartialStoryFn, StoryContext } from '@storybook/csf';

export default {
component: null,
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ component: globalThis.Components.Pre, args: { object: context.args } }),
],
};

// https://github.com/storybookjs/storybook/issues/14752
export const MissingRadioOptions = {
argTypes: { invalidRadio: { control: 'radio' } },
args: { invalidRadio: 'someValue' },
};
39 changes: 39 additions & 0 deletions code/addons/controls/template/stories/matchers.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import globalThis from 'global';
import { PartialStoryFn, StoryContext } from '@storybook/csf';

export default {
component: null,
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ component: globalThis.Components.Pre, args: { object: context.args } }),
],
};

export const CustomMatchers = {
parameters: {
controls: {
matchers: {
date: /whateverIwant/,
},
},
docs: { source: { state: 'open' } },
},
args: {
whateverIwant: '10/10/2020',
},
};

export const DisabledMatchers = {
parameters: {
controls: {
matchers: {
date: null,
color: null,
},
},
},
args: {
purchaseDate: '10/10/2020',
backgroundColor: '#BADA55',
},
};

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions code/examples/ember-cli/stories/addon-controls.stories.js

This file was deleted.

Loading