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

Components: Remove PropsTable, clean ArgsTable stories #11105

Merged
merged 7 commits into from
Jun 10, 2020
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
3 changes: 0 additions & 3 deletions addons/docs/src/frameworks/angular/compodoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-underscore-dangle */
/* global window */

import { PropDef } from '@storybook/components';
import { ArgType, ArgTypes } from '@storybook/api';
import { logger } from '@storybook/client-logger';
import {
Expand All @@ -16,8 +15,6 @@ import {
Directive,
} from './types';

type Sections = Record<string, PropDef[]>;

export const isMethod = (methodOrProp: Method | Property): methodOrProp is Method => {
return (methodOrProp as Method).args !== undefined;
};
Expand Down
6 changes: 2 additions & 4 deletions addons/docs/src/frameworks/react/extractArgTypes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { PropDef, PropsTableRowsProps } from '@storybook/components';
import { ArgTypes } from '@storybook/api';
import { ArgTypesExtractor } from '../../lib/docgen';
import { PropDef, ArgTypesExtractor } from '../../lib/docgen';
import { extractProps } from './extractProps';

export const extractArgTypes: ArgTypesExtractor = (component) => {
if (component) {
const props = extractProps(component);
const { rows } = props as PropsTableRowsProps;
const { rows } = extractProps(component);
if (rows) {
return rows.reduce((acc: ArgTypes, row: PropDef) => {
const { type, sbType, defaultValue: defaultSummary, jsDocTags, required } = row;
Expand Down
9 changes: 7 additions & 2 deletions addons/docs/src/frameworks/react/extractProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import PropTypes from 'prop-types';
import { isForwardRef, isMemo } from 'react-is';
import { PropDef } from '@storybook/components';
import { hasDocgen, extractComponentProps, PropsExtractor, TypeSystem } from '../../lib/docgen';
import {
PropDef,
hasDocgen,
extractComponentProps,
PropsExtractor,
TypeSystem,
} from '../../lib/docgen';
import { Component } from '../../blocks/types';
import { enhancePropTypesProps } from './propTypes/handleProp';
import { enhanceTypeScriptProps } from './typeScript/handleProp';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { PropDefaultValue, PropDef } from '@storybook/components';
import { PropDefaultValue } from '@storybook/components';
import isPlainObject from 'lodash/isPlainObject';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
// @ts-ignore
import reactElementToJSXString from 'react-element-to-jsx-string';
import { createSummaryValue, isTooLongForDefaultValueSummary } from '../../../../lib';
import { PropDef } from '../../../../lib/docgen';
import { inspectValue, InspectionFunction } from '../inspection';
import { generateObject } from './generateObject';
import { generateArray } from './generateArray';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable no-underscore-dangle */

import { PropDef } from '@storybook/components';
import PropTypes from 'prop-types';
import React from 'react';
import { Component } from '../../../blocks/types';
import { extractComponentProps, DocgenInfo, DocgenPropDefaultValue } from '../../../lib/docgen';
import {
PropDef,
extractComponentProps,
DocgenInfo,
DocgenPropDefaultValue,
} from '../../../lib/docgen';
import { enhancePropTypesProp, enhancePropTypesProps } from './handleProp';

const DOCGEN_SECTION = 'props';
Expand Down
3 changes: 1 addition & 2 deletions addons/docs/src/frameworks/react/propTypes/handleProp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PropDef } from '@storybook/components';
import { ExtractedProp } from '../../../lib/docgen';
import { PropDef, ExtractedProp } from '../../../lib/docgen';
import { createType } from './createType';
import { createDefaultValue, createDefaultValueFromRawDefaultProp } from '../lib/defaultValues';
import { Component } from '../../../blocks/types';
Expand Down
2 changes: 1 addition & 1 deletion addons/docs/src/frameworks/react/propTypes/sortProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropDef } from '@storybook/components';
import { PropDef } from '../../../lib/docgen';
import { Component } from '../../../blocks/types';

// react-docgen doesn't returned the props in the order they were defined in the "propTypes" object of the component.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-disable no-underscore-dangle */

import { PropDef } from '@storybook/components';
import React from 'react';
import { Component } from '../../../blocks/types';
import { extractComponentProps, DocgenInfo, DocgenPropDefaultValue } from '../../../lib/docgen';
import {
PropDef,
extractComponentProps,
DocgenInfo,
DocgenPropDefaultValue,
} from '../../../lib/docgen';
import { enhanceTypeScriptProp } from './handleProp';

const DOCGEN_SECTION = 'props';
Expand Down
3 changes: 1 addition & 2 deletions addons/docs/src/frameworks/react/typeScript/handleProp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PropDef } from '@storybook/components';
import { ExtractedProp } from '../../../lib/docgen';
import { PropDef, ExtractedProp } from '../../../lib/docgen';
import { createDefaultValue, createDefaultValueFromRawDefaultProp } from '../lib/defaultValues';

export function enhanceTypeScriptProp(extractedProp: ExtractedProp, rawDefaultProp?: any): PropDef {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FIXME: this is legacy code that needs to be updated & simplified with ArgType refactor

export interface JsDocParam {
name: string;
description?: string;
Expand Down
4 changes: 2 additions & 2 deletions addons/docs/src/lib/docgen/createPropDef.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PropDef, PropDefaultValue } from '@storybook/components';
import { TypeSystem, DocgenInfo, DocgenType, DocgenPropDefaultValue } from './types';
import { PropDefaultValue } from '@storybook/components';
import { PropDef, TypeSystem, DocgenInfo, DocgenType, DocgenPropDefaultValue } from './types';
import { JsDocParsingResult } from '../jsdocParser';
import { createSummaryValue } from '../utils';
import { createFlowPropDef } from './flow/createPropDef';
Expand Down
3 changes: 1 addition & 2 deletions addons/docs/src/lib/docgen/extractDocgenProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PropDef } from '@storybook/components';
import { Component } from '../../blocks/types';
import { ExtractedJsDoc, parseJsDoc } from '../jsdocParser';
import { DocgenInfo, TypeSystem } from './types';
import { PropDef, DocgenInfo, TypeSystem } from './types';
import { getDocgenSection, isValidDocgenSection, getDocgenDescription } from './utils';
import { getPropDefFactory, PropDefFactory } from './createPropDef';

Expand Down
6 changes: 4 additions & 2 deletions addons/docs/src/lib/docgen/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PropsTableProps } from '@storybook/components';
import { ArgTypes } from '@storybook/api';
import { PropDef } from './PropDef';
import { Component } from '../../blocks/types';

export type PropsExtractor = (component: Component) => PropsTableProps | null;
export type PropsExtractor = (component: Component) => { rows?: PropDef[] } | null;

export type ArgTypesExtractor = (component: Component) => ArgTypes | null;

Expand Down Expand Up @@ -49,3 +49,5 @@ export enum TypeSystem {
TYPESCRIPT = 'TypeScript',
UNKNOWN = 'Unknown',
}

export { PropDef };
2 changes: 1 addition & 1 deletion lib/api/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '6.0.0-beta.22';
export const version = '6.0.0-beta.23';
30 changes: 15 additions & 15 deletions lib/cli/versions.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"@storybook/angular": "6.0.0-beta.22",
"@storybook/aurelia": "6.0.0-beta.22",
"@storybook/ember": "6.0.0-beta.22",
"@storybook/html": "6.0.0-beta.22",
"@storybook/marionette": "6.0.0-beta.22",
"@storybook/marko": "6.0.0-beta.22",
"@storybook/mithril": "6.0.0-beta.22",
"@storybook/preact": "6.0.0-beta.22",
"@storybook/rax": "6.0.0-beta.22",
"@storybook/react": "6.0.0-beta.22",
"@storybook/riot": "6.0.0-beta.22",
"@storybook/server": "6.0.0-beta.22",
"@storybook/svelte": "6.0.0-beta.22",
"@storybook/vue": "6.0.0-beta.22",
"@storybook/web-components": "6.0.0-beta.22"
"@storybook/angular": "6.0.0-beta.23",
"@storybook/aurelia": "6.0.0-beta.23",
"@storybook/ember": "6.0.0-beta.23",
"@storybook/html": "6.0.0-beta.23",
"@storybook/marionette": "6.0.0-beta.23",
"@storybook/marko": "6.0.0-beta.23",
"@storybook/mithril": "6.0.0-beta.23",
"@storybook/preact": "6.0.0-beta.23",
"@storybook/rax": "6.0.0-beta.23",
"@storybook/react": "6.0.0-beta.23",
"@storybook/riot": "6.0.0-beta.23",
"@storybook/server": "6.0.0-beta.23",
"@storybook/svelte": "6.0.0-beta.23",
"@storybook/vue": "6.0.0-beta.23",
"@storybook/web-components": "6.0.0-beta.23"
}
63 changes: 51 additions & 12 deletions lib/components/src/blocks/ArgsTable/ArgRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,54 @@ const withArgs = {
updateArgs: action('updateArgs'),
};

export const String = () => <ArgRow row={stringType} />;
export const LongName = () => <ArgRow row={longNameType} />;
export const LongDesc = () => <ArgRow row={longDescType} />;
export const Number = () => <ArgRow row={numberType} />;
export const ObjectOf = () => <ArgRow row={objectType} />;
export const ArrayOf = () => <ArgRow row={arrayType} />;
export const ComplexObject = () => <ArgRow row={complexType} />;
export const Func = () => <ArgRow row={funcType} />;
export const Markdown = () => <ArgRow row={markdownType} />;
export const StringCompact = () => <ArgRow compact row={stringType} />;
export const Args = () => <ArgRow row={stringType} {...withArgs} />;
export const ArgsCompact = () => <ArgRow compact row={stringType} {...withArgs} />;
export const String = (args) => <ArgRow {...args} />;
String.args = {
row: stringType,
};
export const LongName = (args) => <ArgRow {...args} />;
LongName.args = {
row: longNameType,
};
export const LongDesc = (args) => <ArgRow {...args} />;
LongDesc.args = {
row: longDescType,
};
export const Number = (args) => <ArgRow {...args} />;
Number.args = {
row: numberType,
};
export const ObjectOf = (args) => <ArgRow {...args} />;
ObjectOf.args = {
row: objectType,
};
export const ArrayOf = (args) => <ArgRow {...args} />;
ArrayOf.args = {
row: arrayType,
};
export const ComplexObject = (args) => <ArgRow {...args} />;
ComplexObject.args = {
row: complexType,
};
export const Func = (args) => <ArgRow {...args} />;
Func.args = {
row: funcType,
};
export const Markdown = (args) => <ArgRow {...args} />;
Markdown.args = {
row: markdownType,
};
export const StringCompact = (args) => <ArgRow {...args} />;
StringCompact.args = {
...String.args,
compact: true,
};
export const Args = (args) => <ArgRow {...args} />;
Args.args = {
...String.args,
...withArgs,
};
export const ArgsCompact = (args) => <ArgRow {...args} />;
ArgsCompact.args = {
...Args.args,
compact: true,
};
38 changes: 31 additions & 7 deletions lib/components/src/blocks/ArgsTable/ArgsTable.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ArgsTable, ArgsTableError } from './ArgsTable';
import { stringType, numberType } from './ArgRow.stories';
import * as ArgRow from './ArgRow.stories';

export default {
component: ArgsTable,
Expand All @@ -10,20 +10,44 @@ export default {
const propsSection = { category: 'props ' };
const eventsSection = { category: 'events ' };

export const Normal = () => <ArgsTable rows={{ stringType, numberType }} />;
const stringType = ArgRow.String.args.row;
const numberType = ArgRow.Number.args.row;

export const Compact = () => <ArgsTable compact rows={{ stringType, numberType }} />;
export const Normal = (args) => <ArgsTable {...args} />;
Normal.args = {
rows: {
stringType,
numberType,
},
};

export const Compact = (args) => <ArgsTable {...args} />;
Compact.args = {
...Normal.args,
compact: true,
};

const sectionRows = {
a: { ...stringType, table: { ...stringType.table, ...propsSection } },
b: { ...numberType, table: { ...stringType.table, ...propsSection } },
c: { ...stringType, table: { ...stringType.table, ...eventsSection } },
};

export const Sections = () => <ArgsTable rows={sectionRows} />;
export const Sections = (args) => <ArgsTable {...args} />;
Sections.args = {
rows: sectionRows,
};

export const SectionsCompact = () => <ArgsTable compact rows={sectionRows} />;
export const SectionsCompact = (args) => <ArgsTable {...args} />;
SectionsCompact.args = {
...Sections.args,
compact: true,
};

export const Error = () => <ArgsTable error={ArgsTableError.NO_COMPONENT} />;
export const Error = (args) => <ArgsTable {...args} />;
Error.args = {
error: ArgsTableError.NO_COMPONENT,
};

export const Empty = () => <ArgsTable rows={{}} />;
export const Empty = (args) => <ArgsTable {...args} />;
Empty.args = { rows: {} };
25 changes: 25 additions & 0 deletions lib/components/src/blocks/ArgsTable/TabbedArgsTable.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { TabbedArgsTable } from './TabbedArgsTable';
import { Normal, Compact, Sections } from './ArgsTable.stories';

export default {
component: TabbedArgsTable,
title: 'Docs/TabbedArgsTable',
};

const propsSection = { category: 'props ' };
const eventsSection = { category: 'events ' };

export const Tabs = (args) => <TabbedArgsTable {...args} />;
Tabs.args = {
tabs: {
Normal: Normal.args,
Compact: Compact.args,
Sections: Sections.args,
},
};

export const Empty = Tabs.bind();
Empty.args = {
tabs: {},
};
13 changes: 11 additions & 2 deletions lib/components/src/blocks/Description.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export default {

const textCaption = `That was Wintermute, manipulating the lock the way it had manipulated the drone micro and the amplified breathing of the room where Case waited. The semiotics of the bright void beyond the chain link. The tug Marcus Garvey, a steel drum nine meters long and two in diameter, creaked and shuddered as Maelcum punched for a California gambling cartel, then as a paid killer in the dark, curled in his capsule in some coffin hotel, his hands clawed into the nearest door and watched the other passengers as he rode. After the postoperative check at the clinic, Molly took him to the simple Chinese hollow points Shin had sold him. Still it was a handgun and nine rounds of ammunition, and as he made his way down Shiga from the missionaries, the train reached Case’s station. Now this quiet courtyard, Sunday afternoon, this girl with a random collection of European furniture, as though Deane had once intended to use the place as his home. Case felt the edge of the Flatline as a construct, a hardwired ROM cassette replicating a dead man’s skills, obsessions, kneejerk responses. They were dropping, losing altitude in a canyon of rainbow foliage, a lurid communal mural that completely covered the hull of the console in faded pinks and yellows.`;

export const text = () => <Description markdown={textCaption} />;
export const Text = (args) => {
console.log({ args });
return <Description {...args} />;
};
Text.args = {
markdown: textCaption,
};

export const markdown = () => <Description markdown={markdownCaption} />;
export const Markdown = (args) => <Description {...args} />;
Markdown.args = {
markdown: markdownCaption,
};
Loading