-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevDocs: Gutenberg components - Updating examples (#26367)
DevDocs: Gutenberg components Adding examples for all the components
- Loading branch information
Showing
21 changed files
with
396 additions
and
166 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
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
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,77 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import * as components from '@wordpress/components'; | ||
import { withState } from '@wordpress/compose'; | ||
import { getSettings } from '@wordpress/date'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { LiveError, LivePreview, LiveProvider } from 'react-live'; | ||
import request from 'superagent'; | ||
import codeBlocks from 'gfm-code-blocks'; | ||
import classnames from 'classnames'; | ||
import { kebabCase } from 'lodash'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class Example extends React.Component { | ||
state = { | ||
code: null, | ||
}; | ||
|
||
componentDidMount() { | ||
this.getCode(); | ||
} | ||
|
||
async getReadme() { | ||
const readmeFilePath = `/node_modules/@wordpress/components/src/${ | ||
this.props.readmeFilePath | ||
}/README.md`; | ||
|
||
const { text } = await request.get( '/devdocs/service/content' ).query( { | ||
path: readmeFilePath, | ||
format: 'markdown', | ||
} ); | ||
return text; | ||
} | ||
|
||
async getCode() { | ||
const readme = await this.getReadme(); | ||
|
||
// Example to render is the first jsx code block that appears in the readme | ||
let code = codeBlocks( readme ).find( block => 'jsx' === block.lang ).code; | ||
|
||
// react-live cannot resolve imports in real time, so we get rid of them | ||
// (dependencies will be injected via the scope property). | ||
code = code.replace( /^.*import.*$/gm, '' ); | ||
|
||
code = `${ code } render( <${ this.props.render } /> );`; | ||
|
||
this.setState( { code } ); | ||
} | ||
|
||
render() { | ||
const { code } = this.state; | ||
const scope = { | ||
...components, | ||
withState, | ||
getSettings, | ||
PropTypes, | ||
addFilter, | ||
}; | ||
const className = classnames( | ||
'devdocs__gutenberg-components-example', | ||
`devdocs__gutenberg-components-example--${ kebabCase( this.props.component ) }` | ||
); | ||
|
||
return code ? ( | ||
<LiveProvider code={ code } scope={ scope } className={ className } noInline={ true }> | ||
<LiveError /> | ||
<LivePreview /> | ||
</LiveProvider> | ||
) : null; | ||
} | ||
} | ||
|
||
export default Example; |
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,90 @@ | ||
[ | ||
{ "component": "Autocomplete" }, | ||
{ "component": "BaseControl" }, | ||
{ "component": "Button" }, | ||
{ "component": "ButtonGroup" }, | ||
{ "component": "CheckboxControl" }, | ||
{ "component": "ClipboardButton" }, | ||
{ "component": "ColorIndicator" }, | ||
{ "component": "ColorPalette" }, | ||
{ "component": "Dashicon" }, | ||
{ "component": "DateTimePicker", "readmeFilePath": "date-time" }, | ||
{ "component": "Disabled" }, | ||
{ "component": "Draggable" }, | ||
{ "component": "DropZone" }, | ||
{ "component": "Dropdown" }, | ||
{ "component": "DropdownMenu" }, | ||
{ "component": "ExternalLink" }, | ||
{ "component": "FocusableIframe" }, | ||
{ "component": "FontSizePicker" }, | ||
{ "component": "FormFileUpload" }, | ||
{ "component": "FormToggle" }, | ||
{ "component": "FormTokenField" }, | ||
{ "component": "IconButton" }, | ||
{ "component": "KeyboardShortcuts" }, | ||
{ "component": "MenuGroup" }, | ||
{ "component": "MenuItem" }, | ||
{ "component": "MenuItemsChoice" }, | ||
{ "component": "Modal" }, | ||
{ | ||
"component": "navigateRegions", | ||
"readmeFilePath": "higher-order/navigate-regions", | ||
"render": "MyComponentWithNavigateRegions" | ||
}, | ||
{ "component": "NavigableContainer" }, | ||
{ "component": "Notice" }, | ||
{ "component": "Panel" }, | ||
{ "component": "Placeholder" }, | ||
{ "component": "Popover" }, | ||
{ "component": "QueryControls" }, | ||
{ "component": "RadioControl" }, | ||
{ "component": "RangeControl" }, | ||
{ "component": "ResponsiveWrapper" }, | ||
{ "component": "SandBox", "readmeFilePath": "sandbox" }, | ||
{ "component": "ScrollLock" }, | ||
{ "component": "SelectControl" }, | ||
{ "component": "SlotFillProvider", "readmeFilePath": "slot-fill" }, | ||
{ "component": "Spinner" }, | ||
{ "component": "TabPanel" }, | ||
{ "component": "TextControl" }, | ||
{ "component": "TextareaControl" }, | ||
{ "component": "ToggleControl" }, | ||
{ "component": "Toolbar" }, | ||
{ "component": "Tooltip" }, | ||
{ "component": "TreeSelect" }, | ||
{ | ||
"component": "withConstrainedTabbing", | ||
"readmeFilePath": "higher-order/with-constrained-tabbing", | ||
"render": "MyComponentWithConstrainedTabbing" | ||
}, | ||
{ | ||
"component": "withFallbackStyles", | ||
"readmeFilePath": "higher-order/with-fallback-styles", | ||
"render": "MyComponentWithFallbackStyles" | ||
}, | ||
{ | ||
"component": "withFilters", | ||
"readmeFilePath": "higher-order/with-filters", | ||
"render": "MyComponentWithFilters" | ||
}, | ||
{ | ||
"component": "withFocusOutside", | ||
"readmeFilePath": "higher-order/with-focus-outside", | ||
"render": "MyComponentWithFocusOutside" | ||
}, | ||
{ | ||
"component": "withFocusReturn", | ||
"readmeFilePath": "higher-order/with-focus-return", | ||
"render": "MyComponentWithFocusReturn" | ||
}, | ||
{ | ||
"component": "withNotices", | ||
"readmeFilePath": "higher-order/with-notices", | ||
"render": "MyComponentWithNotices" | ||
}, | ||
{ | ||
"component": "withSpokenMessages", | ||
"readmeFilePath": "higher-order/with-spoken-messages", | ||
"render": "MyComponentWithSpokenMessages" | ||
} | ||
] |
Oops, something went wrong.