-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addon-docs: Vue slots/events props table + generalization (#8489)
Addon-docs: Vue slots/events props table + generalization
- Loading branch information
Showing
41 changed files
with
393 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
// FIXME: move this to typescript and src/react folder | ||
module.exports = require('../dist/lib/getPropDefs'); | ||
module.exports = require('../dist/frameworks/common'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from '../../lib/getPropDefs'; | ||
export * from '../../lib/propsUtils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PropDef } from '@storybook/components'; | ||
import { PropsExtractor, propsFromDocgen, hasDocgen } from '../../lib/propsUtils'; | ||
|
||
const SECTIONS = ['props', 'events', 'slots']; | ||
|
||
export const extractProps: PropsExtractor = component => { | ||
if (!hasDocgen(component)) { | ||
return null; | ||
} | ||
const sections: Record<string, PropDef[]> = {}; | ||
SECTIONS.forEach(section => { | ||
sections[section] = propsFromDocgen(component, section); | ||
}); | ||
return { sections }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import { PropDef, PropsTableProps } from '@storybook/components'; | ||
import { Component } from '../blocks/shared'; | ||
|
||
export type PropsExtractor = (component: Component) => PropsTableProps | null; | ||
|
||
export type PropDefGetter = (type: Component, section: string) => PropDef[] | null; | ||
|
||
export const hasDocgen = (obj: any) => !!obj.__docgenInfo; | ||
|
||
export const hasDocgenSection = (obj: any, section: string) => | ||
obj.__docgenInfo && | ||
obj.__docgenInfo[section] && | ||
Object.keys(obj.__docgenInfo[section]).length > 0; | ||
|
||
export const propsFromDocgen: PropDefGetter = (type, section) => { | ||
const props: Record<string, PropDef> = {}; | ||
const docgenInfoProps = type.__docgenInfo[section]; | ||
if (!docgenInfoProps) { | ||
return null; | ||
} | ||
|
||
Object.keys(docgenInfoProps).forEach(property => { | ||
const docgenInfoProp = docgenInfoProps[property]; | ||
const defaultValueDesc = docgenInfoProp.defaultValue || {}; | ||
const propType = docgenInfoProp.flowType || docgenInfoProp.type || 'other'; | ||
|
||
props[property] = { | ||
name: property, | ||
type: propType, | ||
required: docgenInfoProp.required, | ||
description: docgenInfoProp.description, | ||
defaultValue: defaultValueDesc.value, | ||
}; | ||
}); | ||
|
||
return Object.values(props); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
declare module '@mdx-js/react'; | ||
declare module '@storybook/addon-docs/mdx-compiler-plugin'; | ||
declare module 'global'; | ||
declare module 'react-is'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import { DocgenButton } from './DocgenButton'; | ||
|
||
export const ForwardRefButton = React.forwardRef((props, ref) => ( | ||
<DocgenButton ref={ref} {...props} /> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react'; | ||
import { DocgenButton } from './DocgenButton'; | ||
|
||
export const MemoButton = React.memo(props => <DocgenButton {...props} />); |
2 changes: 1 addition & 1 deletion
2
examples/official-storybook/stories/addon-docs/addon-docs.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
examples/official-storybook/stories/addon-docs/forward-ref.stories.js
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
examples/official-storybook/stories/addon-docs/props.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Meta, Props } from '@storybook/addon-docs/blocks'; | ||
import { DocgenButton } from '../../components/DocgenButton'; | ||
import { ForwardRefButton } from '../../components/ForwardRefButton'; | ||
import { MemoButton } from '../../components/MemoButton'; | ||
|
||
<Meta title="Addons|Docs/props" /> | ||
|
||
## Docgen | ||
|
||
<Props of={DocgenButton} /> | ||
|
||
## React.forwardRef | ||
|
||
<Props of={ForwardRefButton} /> | ||
|
||
## React.memo | ||
|
||
<Props of={MemoButton} /> |
12 changes: 0 additions & 12 deletions
12
examples/official-storybook/stories/addon-docs/react-memo.stories.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b7f3882
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: