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

DevDocs: Gutenberg components - Updating examples #26367

Merged
merged 37 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
50841ad
DevDocs: New "Gutenberg components" section
mmtr Jul 25, 2018
d9bae6f
DevDocs: Gutenberg Components - Autocomplete example
mmtr Jul 27, 2018
d83890a
DevDocs: Gutenberg Components - BaseControl example
mmtr Jul 27, 2018
2126f5b
DevDocs: Gutenberg Components - ButtonGroup example
mmtr Jul 27, 2018
625f65f
DevDocs: Gutenberg Components - CheckboxControl example
mmtr Jul 27, 2018
1190785
DevDocs: Gutenberg Components - ClipboardButton example
mmtr Jul 27, 2018
d1f656d
DevDocs: Gutenberg Components - Dashicon example
mmtr Jul 27, 2018
68c36c5
DevDocs: Gutenberg Components - DateTimePicker example
mmtr Jul 27, 2018
e1648c4
DevDocs: Gutenberg Components - Disabled example
mmtr Jul 28, 2018
c61000f
DevDocs: Gutenberg Components - Draggable example
mmtr Jul 28, 2018
da33ce3
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr Jul 29, 2018
da91103
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr Jul 29, 2018
b9ddce7
DevDocs: Gutenberg Components - Load examples dynamically
mmtr Jul 29, 2018
a1e8c50
DevDocs: Gutenberg Components - Autocomplete example
mmtr Jul 27, 2018
966b308
DevDocs: Gutenberg Components - BaseControl example
mmtr Jul 27, 2018
9742133
DevDocs: Gutenberg Components - ButtonGroup example
mmtr Jul 27, 2018
72c3e76
DevDocs: Gutenberg Components - CheckboxControl example
mmtr Jul 27, 2018
f9aeb82
DevDocs: Gutenberg Components - ClipboardButton example
mmtr Jul 27, 2018
22ae635
DevDocs: Gutenberg Components - Dashicon example
mmtr Jul 27, 2018
6eaf583
DevDocs: Gutenberg Components - DateTimePicker example
mmtr Jul 27, 2018
165bb51
DevDocs: Gutenberg Components - Disabled example
mmtr Jul 28, 2018
3a38988
DevDocs: Gutenberg Components - Draggable example
mmtr Jul 28, 2018
db0b02c
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr Jul 29, 2018
7735c3e
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr Jul 29, 2018
1e934f6
Render Gutenberg examples assuming they are defining a MyComponent co…
mmtr Aug 3, 2018
b7b9e60
Remove duplicated style import
mmtr Aug 3, 2018
f86ecc0
Move Gutenberg components code to specific folder
mmtr Aug 5, 2018
6bf8a25
Remove non-needed Jest config
mmtr Aug 5, 2018
5e9efb4
Remove examples of deprecated components
mmtr Aug 6, 2018
e203c28
Tests for Gutenberg component example
mmtr Aug 7, 2018
45c92c0
Tests for Gutenberg component example
mmtr Aug 8, 2018
b324d94
Upgrading @wordpress packages
mmtr Aug 9, 2018
e0e98e0
DevDocs: Gutenberg Components
mmtr Aug 12, 2018
71a06f7
DevDocs: Gutenberg Components
mmtr Aug 12, 2018
6ecdc17
DevDocs: Gutenberg Components
mmtr Aug 20, 2018
ad7b95a
DevDocs: Gutenberg Components
mmtr Aug 21, 2018
0d2b951
DevDocs: Gutenberg Components
mmtr Aug 22, 2018
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
4 changes: 1 addition & 3 deletions assets/stylesheets/sections/devdocs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
@import 'devdocs/style';
@import 'devdocs/design/style';
@import 'devdocs/design/syntax.scss';
@import 'devdocs/gutenberg-components/style';
@import 'devdocs/gutenberg-blocks/style';

@import 'assets/stylesheets/sections/media';

// Gutenberg components
@import '../../../node_modules/@wordpress/components/build-style/style';
2 changes: 1 addition & 1 deletion client/devdocs/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const devdocs = {
// Gutenberg Components
gutenbergComponents: function( context, next ) {
context.primary = (
<AsyncLoad component={ context.params.component } require="./design/gutenberg-components" />
<AsyncLoad component={ context.params.component } require="./gutenberg-components" />
);
next();
},
Expand Down
3 changes: 0 additions & 3 deletions client/devdocs/design/component-playground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class ComponentPlayground extends Component {
const { section } = this.props;
let scope = null;
switch ( section ) {
case 'gutenberg-components':
scope = require( '@wordpress/components' );
break;
case 'gutenberg-blocks':
scope = require( 'gutenberg-blocks' );
break;
Expand Down
59 changes: 0 additions & 59 deletions client/devdocs/design/gutenberg-components.jsx

This file was deleted.

14 changes: 7 additions & 7 deletions client/devdocs/design/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

.design__playground {
margin: -24px;
@include breakpoint( '>960px') {
@include breakpoint( '>960px' ) {
margin: -32px;
}
}
Expand All @@ -27,25 +27,25 @@
box-sizing: border-box;
color: $alert-red;
position: sticky;
top: 0;
top: 0;
}

.react-live-error,
.design__preview {
padding: 24px;
@include breakpoint( '>960px') {
@include breakpoint( '>960px' ) {
padding: 32px;
}
}

.design__preview {
position: relative;
@include breakpoint( '>960px') {
@include breakpoint( '>960px' ) {
position: static;
}
}

@include breakpoint( '>960px') {
@include breakpoint( '>960px' ) {
.design__playground {
display: flex;
height: calc( 100vh - 47px );
Expand All @@ -71,8 +71,8 @@
.design__component-playground-clipboard {
padding: 0;
position: absolute;
right: 10px;
top: 10px;
right: 10px;
top: 10px;
}

.design__component-playground-show-code {
Expand Down
13 changes: 0 additions & 13 deletions client/devdocs/design/test/component-playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ComponentPlayground from '../component-playground';

jest.mock( 'devdocs/design/playground-scope', () => 'PlaygroundScope' );
jest.mock( 'gutenberg-blocks', () => 'GutenbergBlocks' );
jest.mock( '@wordpress/components', () => 'GutenbergComponents' );

describe( 'ComponentPlayground', () => {
test( 'LiveProvider should use the components scope by default', () => {
Expand All @@ -28,18 +27,6 @@ describe( 'ComponentPlayground', () => {
expect( liveProvider.props().scope ).toBe( 'PlaygroundScope' );
} );

test(
'LiveProvider should use the Gutenberg components scope when section is Gutenberg' +
' components',
() => {
const wrapper = shallow(
<ComponentPlayground section="gutenberg-components" code="foo" name="foo" url="foo" />
);
const liveProvider = wrapper.find( LiveProvider );
expect( liveProvider.props().scope ).toBe( 'GutenbergComponents' );
}
);

test( 'LiveProvider should use the Gutenberg blocks scope when section is Gutenberg blocks', () => {
const wrapper = shallow(
<ComponentPlayground section="gutenberg-blocks" code="foo" name="foo" url="foo" />
Expand Down
77 changes: 77 additions & 0 deletions client/devdocs/gutenberg-components/example.jsx
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;
90 changes: 90 additions & 0 deletions client/devdocs/gutenberg-components/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{ "component": "Autocomplete" },
{ "component": "BaseControl" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to generate this list on the fly? Given that it is README based it quickly might become outdated. Unless you have a plan how to prevent regressions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wise. I think we could perhaps leave this until a follow-up PR, on the proviso that we'll actually follow up :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for having this file is to avoid rendering deprecated components like withContext or withAPIData. It's true we can autogenerate the rest of the data, but I don't know if we have some way of knowing if a component is deprecated or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for following up on this. I think we can probably move this sort of declaration to the WordPress package examples or more clearly mark which are intended to be deprecated.

{ "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"
}
]
Loading