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

Add components examples in README.md files - Part 2 #8338

Merged
merged 42 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9fda0fd
Components examples: Modal
mmtr Jul 31, 2018
3296d11
Components examples: Modal
mmtr Aug 2, 2018
1d6ad3e
Components examples assigned to const variables
mmtr Aug 2, 2018
b3dcc26
Components examples: Notice
mmtr Aug 3, 2018
e298099
Components examples: Panel
mmtr Aug 3, 2018
abe9a02
Components examples: Placeholder
mmtr Aug 3, 2018
68d9457
Components examples: Popover
mmtr Aug 3, 2018
e7c21e5
Components examples: QueryControls
mmtr Aug 3, 2018
48de4b4
Components examples: RadioControl
mmtr Aug 3, 2018
d764061
Components examples: RangeControl
mmtr Aug 3, 2018
183c7d1
Components examples: ResponsiveWrapper
mmtr Aug 3, 2018
0239415
Components examples: SandBox
mmtr Aug 3, 2018
6b2c8b2
Components examples: ScrollLock
mmtr Aug 3, 2018
308eefd
Components examples: SelectControl
mmtr Aug 3, 2018
32dafc0
Components examples: ServerSideRender
mmtr Aug 4, 2018
201ff80
Add metadata using YAML front matter so examples can be extracted
mmtr Aug 4, 2018
40d1d44
Add metadata using YAML front matter so examples can be extracted
mmtr Aug 4, 2018
f1debb9
Remove YAML front matter
mmtr Aug 4, 2018
04c2649
Components examples: SlotFill
mmtr Aug 4, 2018
f52ff8d
Components examples: Spinner
mmtr Aug 4, 2018
7cf6f08
Components examples: TabPanel
mmtr Aug 4, 2018
b541266
Components examples: TextControl
mmtr Aug 4, 2018
81ef947
Components examples: TextareaControl
mmtr Aug 4, 2018
5984848
Components examples: ToggleControl
mmtr Aug 4, 2018
aacb094
Components examples: Toolbar
mmtr Aug 4, 2018
2a75f76
Components examples: Tooltip
mmtr Aug 4, 2018
cb4d859
Components examples: TreeSelect
mmtr Aug 4, 2018
a0aca61
Components examples: NavigableContainer
mmtr Aug 4, 2018
e7f85bb
Components examples: navigateRegions
mmtr Aug 4, 2018
6bc6fbc
Components examples: withConstrainedTabbing
mmtr Aug 4, 2018
2b7c999
Components examples: withContext
mmtr Aug 4, 2018
4c387ce
Components examples: withFallbackStyles
mmtr Aug 4, 2018
9394810
Components examples: withFilters
mmtr Aug 4, 2018
0b0bba5
Components examples: withFocusOutside
mmtr Aug 4, 2018
8d5c451
Components examples: withFocusReturn
mmtr Aug 4, 2018
ed573aa
Components examples: withNotices
mmtr Aug 4, 2018
9a94a5b
Components examples: withSpokenMessages
mmtr Aug 4, 2018
89f0c1b
Components examples: withAPIData
mmtr Aug 5, 2018
5471769
Contributing guidelines for the components
mmtr Aug 5, 2018
c2e20b0
Contributing guidelines for the components
mmtr Aug 5, 2018
1d93a3b
Contributing guidelines for the components
mmtr Aug 5, 2018
33cbfae
Add dummy attributes to ServerSideRender example
mmtr Aug 6, 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: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Documentation is automatically synced from master to the [Gutenberg Documentatio

To add a new documentation page, you'll have to create a Markdown file in the [docs](https://github.com/WordPress/gutenberg/tree/master/docs) folder and add an item to the [manifest file](https://github.com/WordPress/gutenberg/blob/master/docs/manifest.json).

### `@wordpress/component`

If you're contributing to the documentation of any component from the `@wordpress/component` package, take a look at its [guidelines for contributing](./packages/components/CONTRIBUTING.md).

## Reporting Security Issues

Please see [SECURITY.md](./SECURITY.md).
Expand Down
15 changes: 15 additions & 0 deletions packages/components/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Contributing

Thank you for taking the time to contribute.

The following is a set of guidelines for contributing to the `@wordpress/components` package to be considered in addition to the general ones described in our [Contributing Policy](../../CONTRIBUTING.md).

## Examples

Each component needs to include an example in its README.md file to demonstrate the usage of the component.

These examples can be consumed automatically from other projects in order to visualize them in their documentation. To ensure these examples are extractable, compilable and renderable, they should be structured in the following way:

* It has to be included in a `jsx` code block.
* It has to work out-of-the-box. No additional code should be needed to have working the example.
* It has to define a React component called `My<ComponentName>` which renders the example (i.e.: `MyButton`). Examples for the Higher Order Components should define a `MyComponent<ComponentName>` component (i.e.: `MyComponentWithNotices`).
2 changes: 1 addition & 1 deletion packages/components/src/autocomplete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ The following is a contrived completer for fresh fruit.
```jsx
import { Autocomplete } from '@wordpress/components';

function FreshFruitAutocomplete() {
const MyAutocomplete = () => {
const autocompleters = [
{
name: 'fruit',
Expand Down
22 changes: 10 additions & 12 deletions packages/components/src/base-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ Render a BaseControl for a textarea input:
```jsx
import { BaseControl } from '@wordpress/components';

function MyBaseControl() {
return (
<BaseControl
const MyBaseControl = () => (
<BaseControl
id="textarea-1"
label="Text"
help="Enter some text"
>
<textarea
id="textarea-1"
label="Text"
help="Enter some text"
>
<textarea
id="textarea-1"
/>
</BaseControl>
);
}
/>
</BaseControl>
);
```

## Props
Expand Down
14 changes: 6 additions & 8 deletions packages/components/src/button-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
```jsx
import { Button, ButtonGroup } from '@wordpress/components';

function MyButtonGroup() {
return (
<ButtonGroup>
<Button isPrimary>Button 1</Button>
<Button isPrimary>Button 2</Button>
</ButtonGroup>
);
}
const MyButtonGroup = () => (
<ButtonGroup>
<Button isPrimary>Button 1</Button>
<Button isPrimary>Button 2</Button>
</ButtonGroup>
);
```
12 changes: 5 additions & 7 deletions packages/components/src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ Renders a button with default style.
```jsx
import { Button } from "@wordpress/components";

function MyButton() {
return (
<Button isDefault>
Click me!
</Button>
);
}
const MyButton = () => (
<Button isDefault>
Click me!
</Button>
);
```

## Props
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/checkbox-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Render an is author checkbox:
import { CheckboxControl } from '@wordpress/components';
import { withState } from '@wordpress/compose';

withState( {
const MyCheckboxControl = withState( {
isChecked: true,
} )( ( { isChecked, setState } ) => (
<CheckboxControl
Expand All @@ -20,7 +20,7 @@ withState( {
checked={ isChecked }
onChange={ ( isChecked ) => { setState( { isChecked } ) } }
/>
) )
) );
```

## Props
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/clipboard-button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { ClipboardButton } from '@wordpress/components';
import { withState } from '@wordpress/compose';

withState( {
const MyClipboardButton = withState( {
hasCopied: false,
} )( ( { hasCopied, setState } ) => (
<ClipboardButton
Expand Down
8 changes: 3 additions & 5 deletions packages/components/src/color-indicator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
```jsx
import { ColorIndicator } from '@wordpress/components';

function MyColorIndicator() {
return (
<ColorIndicator colorValue="#f00" />
);
}
const MyColorIndicator = () => (
<ColorIndicator colorValue="#f00" />
);
```
6 changes: 3 additions & 3 deletions packages/components/src/color-palette/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { ColorPalette } from '@wordpress/components';
import { withState } from '@wordpress/compose';

withState( {
const MyColorPalette = withState( {
color: '#f00',
} )( ( { color, setState } ) => {
const colors = [
Expand All @@ -18,8 +18,8 @@ withState( {
<ColorPalette
colors={ colors }
value={ color }
onChange={ color => setState( { color } ) }
onChange={ ( color ) => setState( { color } ) }
/>
)
} )
} );
```
16 changes: 7 additions & 9 deletions packages/components/src/dashicon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
```jsx
import { Dashicon } from '@wordpress/components';

function MyDashicons() {
return (
<div>
<Dashicon icon="admin-home" />
<Dashicon icon="products" />
<Dashicon icon="wordpress" />
</div>
);
}
const MyDashicon = () => (
<div>
<Dashicon icon="admin-home" />
<Dashicon icon="products" />
<Dashicon icon="wordpress" />
</div>
);
```
10 changes: 7 additions & 3 deletions packages/components/src/date-time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ Render a DateTimePicker.
```jsx
import { DateTimePicker } from '@wordpress/components';
import { getSettings } from '@wordpress/date';
import { withState } from '@wordpress/compose';

function selectTime( date, onUpdateDate ) {

const MyDateTimePicker = withState( {
date: new Date(),
} )( ( { date, setState } ) => {
const settings = getSettings();

// To know if the current timezone is a 12 hour time with look for "a" in the time format.
Expand All @@ -25,12 +29,12 @@ function selectTime( date, onUpdateDate ) {
return (
<DateTimePicker
currentDate={ date }
onChange={ onUpdateDate }
onChange={ ( date ) => setState( { date } ) }
locale={ settings.l10n.locale }
is12Hour={ is12HourTime }
/>
);
}
} );
```

## Props
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/disabled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Assuming you have a form component, you can disable all form inputs by wrapping
import { Button, Disabled, TextControl } from '@wordpress/components';
import { withState } from '@wordpress/compose';

withState( {
const MyDisabled = withState( {
isDisabled: true,
} )( ( { isDisabled, setState } ) => {
let input = <TextControl label="Input" onChange={ () => {} } />;
Expand All @@ -30,7 +30,7 @@ withState( {
</Button>
</div>
);
} )
} );
```

A component can detect if it has been wrapped in a `<Disabled>` by accessing its [context](https://reactjs.org/docs/context.html) using `Disabled.Consumer`.
Expand Down
30 changes: 14 additions & 16 deletions packages/components/src/draggable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,18 @@ The function called when dragging ends.
```jsx
import { Dashicon, Draggable, Panel, PanelBody } from '@wordpress/components';

function DraggablePanel() {
return (
<div id="draggable-panel">
<Panel header="Draggable panel" >
<PanelBody>
<Draggable
elementId="draggable-panel"
transferData={ { } }
>
<Dashicon icon="move" />
</Draggable>
</PanelBody>
</Panel>
</div>
);
}
const MyDraggable = () => (
<div id="draggable-panel">
<Panel header="Draggable panel" >
<PanelBody>
<Draggable
elementId="draggable-panel"
transferData={ { } }
>
<Dashicon icon="move" />
</Draggable>
</PanelBody>
</Panel>
</div>
);
```
2 changes: 1 addition & 1 deletion packages/components/src/drop-zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { DropZoneProvider, DropZone } from '@wordpress/components';
import { withState } from '@wordpress/compose';

withState( {
const MyDropZone = withState( {
hasDropped: false,
} )( ( { hasDropped, setState } ) => (
<DropZoneProvider>
Expand Down
58 changes: 28 additions & 30 deletions packages/components/src/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,34 @@ Render a Dropdown Menu with a set of controls:
```jsx
import { DropdownMenu } from '@wordpress/components';

function DirectionMenu() {
return (
<DropdownMenu
icon="move"
label="Select a direction"
controls={ [
{
title: 'Up',
icon: 'arrow-up-alt',
onClick: () => console.log( 'up' )
},
{
title: 'Right',
icon: 'arrow-right-alt',
onClick: () => console.log( 'right' )
},
{
title: 'Down',
icon: 'arrow-down-alt',
onClick: () => console.log( 'down' )
},
{
title: 'Left',
icon: 'arrow-left-alt',
onClick: () => console.log( 'left' )
},
] }
/>
);
}
const MyDropdownMenu = () => (
<DropdownMenu
icon="move"
label="Select a direction"
controls={ [
{
title: 'Up',
icon: 'arrow-up-alt',
onClick: () => console.log( 'up' )
},
{
title: 'Right',
icon: 'arrow-right-alt',
onClick: () => console.log( 'right' )
},
{
title: 'Down',
icon: 'arrow-down-alt',
onClick: () => console.log( 'down' )
},
{
title: 'Left',
icon: 'arrow-left-alt',
onClick: () => console.log( 'left' )
},
] }
/>
);
```

## Props
Expand Down
36 changes: 17 additions & 19 deletions packages/components/src/dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ and uses render props to render the button and the content.
```jsx
import { Button, Dropdown } from '@wordpress/components';

function MyDropdownMenu() {
return (
<Dropdown
className="my-container-class-name"
contentClassName="my-popover-content-classname"
position="bottom right"
renderToggle={ ( { isOpen, onToggle } ) => (
<Button isPrimary onClick={ onToggle } aria-expanded={ isOpen }>
Toggle Popover!
</Button>
) }
renderContent={ () => (
<div>
This is the content of the popover.
</div>
) }
/>
);
}
const MyDropdown = () => (
<Dropdown
className="my-container-class-name"
contentClassName="my-popover-content-classname"
position="bottom right"
renderToggle={ ( { isOpen, onToggle } ) => (
<Button isPrimary onClick={ onToggle } aria-expanded={ isOpen }>
Toggle Popover!
</Button>
) }
renderContent={ () => (
<div>
This is the content of the popover.
</div>
) }
/>
);
```

## Props
Expand Down
8 changes: 3 additions & 5 deletions packages/components/src/external-link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
```jsx
import { ExternalLink } from '@wordpress/components';

function MyExternalLink() {
return (
<ExternalLink href="https://wordpress.org">WordPress.org</ExternalLink>
);
}
const MyExternalLink = () => (
<ExternalLink href="https://wordpress.org">WordPress.org</ExternalLink>
);
```
Loading