-
Notifications
You must be signed in to change notification settings - Fork 2k
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
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 d9bae6f
DevDocs: Gutenberg Components - Autocomplete example
mmtr d83890a
DevDocs: Gutenberg Components - BaseControl example
mmtr 2126f5b
DevDocs: Gutenberg Components - ButtonGroup example
mmtr 625f65f
DevDocs: Gutenberg Components - CheckboxControl example
mmtr 1190785
DevDocs: Gutenberg Components - ClipboardButton example
mmtr d1f656d
DevDocs: Gutenberg Components - Dashicon example
mmtr 68c36c5
DevDocs: Gutenberg Components - DateTimePicker example
mmtr e1648c4
DevDocs: Gutenberg Components - Disabled example
mmtr c61000f
DevDocs: Gutenberg Components - Draggable example
mmtr da33ce3
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr da91103
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr b9ddce7
DevDocs: Gutenberg Components - Load examples dynamically
mmtr a1e8c50
DevDocs: Gutenberg Components - Autocomplete example
mmtr 966b308
DevDocs: Gutenberg Components - BaseControl example
mmtr 9742133
DevDocs: Gutenberg Components - ButtonGroup example
mmtr 72c3e76
DevDocs: Gutenberg Components - CheckboxControl example
mmtr f9aeb82
DevDocs: Gutenberg Components - ClipboardButton example
mmtr 22ae635
DevDocs: Gutenberg Components - Dashicon example
mmtr 6eaf583
DevDocs: Gutenberg Components - DateTimePicker example
mmtr 165bb51
DevDocs: Gutenberg Components - Disabled example
mmtr 3a38988
DevDocs: Gutenberg Components - Draggable example
mmtr db0b02c
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr 7735c3e
DevDocs: Gutenberg Components - Loading examples dynamically
mmtr 1e934f6
Render Gutenberg examples assuming they are defining a MyComponent co…
mmtr b7b9e60
Remove duplicated style import
mmtr f86ecc0
Move Gutenberg components code to specific folder
mmtr 6bf8a25
Remove non-needed Jest config
mmtr 5e9efb4
Remove examples of deprecated components
mmtr e203c28
Tests for Gutenberg component example
mmtr 45c92c0
Tests for Gutenberg component example
mmtr b324d94
Upgrading @wordpress packages
mmtr e0e98e0
DevDocs: Gutenberg Components
mmtr 71a06f7
DevDocs: Gutenberg Components
mmtr 6ecdc17
DevDocs: Gutenberg Components
mmtr ad7b95a
DevDocs: Gutenberg Components
mmtr 0d2b951
DevDocs: Gutenberg Components
mmtr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
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.
This seems wise. I think we could perhaps leave this until a follow-up PR, on the proviso that we'll actually follow up :)
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.
The main reason for having this file is to avoid rendering deprecated components like
withContext
orwithAPIData
. 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.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.
+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.