Skip to content

Commit

Permalink
DevDocs: Gutenberg Components - Load examples dynamically
Browse files Browse the repository at this point in the history
Each example has now a specific class
  • Loading branch information
mmtr committed Jul 29, 2018
1 parent 1ec523b commit f8402d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
10 changes: 8 additions & 2 deletions client/devdocs/design/gutenberg-component-example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getSettings } from '@wordpress/date';
import { LiveError, LivePreview, LiveProvider } from 'react-live';
import request from 'superagent';
import codeBlocks from 'gfm-code-blocks';
import classnames from 'classnames';

class Example extends React.Component {
state = {
Expand All @@ -32,7 +33,7 @@ class Example extends React.Component {
format: 'markdown',
} )
.then( ( { text } ) => {
let code = codeBlocks( text )[ 0 ].code;
let code = codeBlocks( text ).filter( block => 'jsx' === block.lang )[ 0 ].code;

// react-live cannot resolve imports in real time, so we get rid of them
// (dependencies will be injected via the scope property)
Expand All @@ -49,8 +50,13 @@ class Example extends React.Component {
withState,
getSettings,
};
const className = classnames(
'design__gutenberg-component-example',
`design__gutenberg-component-example--${ this.props.readmeFilePath }`
);

return code ? (
<LiveProvider code={ code } scope={ scope } className="design__gutenberg-component-example">
<LiveProvider code={ code } scope={ scope } className={ className }>
<LiveError />
<LivePreview />
</LiveProvider>
Expand Down
16 changes: 16 additions & 0 deletions client/devdocs/design/gutenberg-components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,26 @@ export default class extends React.Component {
'ButtonGroup',
'CheckboxControl',
'ClipboardButton',
'ColorIndicator',
'ColorPalette',
'Dashicon',
'Disabled',
'Draggable',
[ 'DateTimePicker', { readmeFilePath: 'date-time' } ],
'DropZone',
'Dropdown',
'DropdownMenu',
'ExternalLink',
'FocusableIframe',
'FontSizePicker',
'FormFileUpload',
'FormToggle',
'FormTokenField',
'IconButton',
'KeyboardShortcuts',
'MenuGroup',
'MenuItem',
'MenuItemsChoice',
];

return (
Expand Down
19 changes: 14 additions & 5 deletions client/devdocs/design/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@
}
}

.design__gutenberg-component-example {
// Styles the contenteditable div included in the Autocomplete example as an input
.components-autocomplete [contenteditable] {
@extend %form-field;
}
// Styles the contenteditable div included in the Gutenberg Autocomplete component example as an input
.design__gutenberg-component-example--autocomplete [contenteditable] {
@extend %form-field;
}

.design__gutenberg-component-example--drop-zone {
position: relative;
text-align: center;
padding: 50px;
}

.design__gutenberg-component-example--date-time,
.design__gutenberg-component-example--dropdown {
display: inline-block;
}

0 comments on commit f8402d4

Please sign in to comment.