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: WordPress components gallery #45523

Merged
merged 8 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions client/devdocs/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ const devdocs = {
next();
},

wpComponentsGallery( context, next ) {
context.primary = <AsyncLoad require="./design/wordpress-components-gallery" />;
next();
},

selectors: function ( context, next ) {
context.primary = (
<AsyncLoad
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { __experimentalAlignmentMatrixControl as AlignmentMatrixControl } from '@wordpress/components';

const AlignmentMatrixControlExample = () => {
const [ alignment, setAlignment ] = useState( 'center center' );

return <AlignmentMatrixControl value={ alignment } onChange={ setAlignment } />;
};

export default AlignmentMatrixControlExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { AnglePickerControl } from '@wordpress/components';

const AnglePickerControlExample = () => {
const [ angle, setAngle ] = useState();
return <AnglePickerControl value={ angle } onChange={ setAngle } />;
};

export default AnglePickerControlExample;
21 changes: 21 additions & 0 deletions client/devdocs/design/wordpress-components-gallery/animate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* External dependencies
*/
import React from 'react';

/**
* WordPress dependencies
*/
import { Animate, Notice } from '@wordpress/components';

const AnimateExample = () => (
<Animate type="loading">
{ ( { className } ) => (
<Notice className={ className } status="success">
<p>Loading animation</p>
</Notice>
) }
</Animate>
);

export default AnimateExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { Autocomplete, __experimentalInputControl as InputControl } from '@wordpress/components';

const autocompleters = [
{
name: 'fruit',
// The prefix that triggers this completer
triggerPrefix: '~',
// The option data
options: [
{ visual: '🍎', name: 'Apple', id: 1 },
{ visual: '🍊', name: 'Orange', id: 2 },
{ visual: '🍇', name: 'Grapes', id: 3 },
],
// Returns a label for an option like "🍊 Orange"
getOptionLabel: ( option ) => (
<span>
<span>{ option.visual }</span>
{ option.name }
</span>
),
// Declares that options should be matched by their name
getOptionKeywords: ( option ) => [ option.name ],
// Declares that the Grapes option is disabled
isOptionDisabled: ( option ) => option.name === 'Grapes',
// Declares completions should be inserted as abbreviations
getOptionCompletion: ( option ) => <abbr title={ option.name }>{ option.visual }</abbr>,
},
];

const AutocompleteExample = () => {
const [ value, setValue ] = useState( '' );
return (
<div>
<Autocomplete record={ value } onChange={ setValue } completers={ autocompleters }>
{ ( { isExpanded, listBoxId, activeId, onKeyDown } ) => (
<InputControl
onKeyDown={ onKeyDown }
aria-autocomplete="list"
aria-expanded={ isExpanded }
aria-owns={ listBoxId }
aria-activedescendant={ activeId }
/>
) }
</Autocomplete>
<p>Type ~ for triggering the autocomplete.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why I'm unable to make this work by typing ~ 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it doesn't seem to work, I think it's potentially one of the things that is broken 😱

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's something related to how its popover works? But we can investigate in another PR, I don't consider that a blocker 😉

</div>
);
};

export default AutocompleteExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* External dependencies
*/
import React from 'react';

/**
* WordPress dependencies
*/
import { BaseControl } from '@wordpress/components';

const BaseControlExample = () => (
<BaseControl id="textarea-1" label="Text" help="Enter some text">
<textarea id="textarea-1" />
</BaseControl>
);

export default BaseControlExample;
29 changes: 29 additions & 0 deletions client/devdocs/design/wordpress-components-gallery/box-control.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';

const { __Visualizer: Visualizer } = BoxControl;

const BoxControlExample = () => {
const [ values, setValues ] = useState( {
top: '50px',
left: '10%',
right: '10%',
bottom: '50px',
} );

return (
<>
<BoxControl values={ values } onChange={ setValues } />
<Visualizer values={ values } />
</>
);
};

export default BoxControlExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* External dependencies
*/
import React from 'react';

/**
* WordPress dependencies
*/
import { Button, ButtonGroup } from '@wordpress/components';

const ButtonGroupExample = () => {
const style = { margin: '0 4px' };
return (
<ButtonGroup>
<Button isPrimary style={ style }>
Button 1
</Button>
<Button isPrimary style={ style }>
Button 2
</Button>
</ButtonGroup>
);
};

export default ButtonGroupExample;
60 changes: 60 additions & 0 deletions client/devdocs/design/wordpress-components-gallery/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* External dependencies
*/
import React from 'react';

/**
* WordPress dependencies
*/
import { more } from '@wordpress/icons';
import { Button as InnerButton, Flex, FlexItem } from '@wordpress/components';

const Button = ( props: InnerButton.Props ) => (
<FlexItem>
<InnerButton { ...props } />
</FlexItem>
);

const ButtonExample = () => {
return (
<div style={ { padding: '20px' } }>
<h2>Small Buttons</h2>
<Flex gap={ 2 }>
<Button isSmall>Button</Button>
<Button isPrimary isSmall>
Primary Button
</Button>
<Button isSecondary isSmall>
Secondary Button
</Button>
<Button isTertiary isSmall>
Tertiary Button
</Button>
<Button isSmall icon={ more } />
<Button isSmall isPrimary icon={ more } />
<Button isSmall isSecondary icon={ more } />
<Button isSmall isTertiary icon={ more } />
<Button isSmall isPrimary icon={ more }>
Icon & Text
</Button>
</Flex>

<h2>Regular Buttons</h2>
<Flex gap={ 4 }>
<Button>Button</Button>
<Button isPrimary>Primary Button</Button>
<Button isSecondary>Secondary Button</Button>
<Button isTertiary>Tertiary Button</Button>
<Button icon={ more } />
<Button isPrimary icon={ more } />
<Button isSecondary icon={ more } />
<Button isTertiary icon={ more } />
<Button isPrimary icon={ more }>
Icon & Text
</Button>
</Flex>
</div>
);
};

export default ButtonExample;
42 changes: 42 additions & 0 deletions client/devdocs/design/wordpress-components-gallery/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* External dependencies
*/
import React from 'react';

/**
* WordPress dependencies
*/
import {
Button,
Card,
CardBody,
CardFooter,
CardDivider,
CardHeader,
FlexBlock,
FlexItem,
} from '@wordpress/components';

const CardExample = () => (
<Card isElevated>
<CardHeader isShady={ false }>
<FlexBlock>Header: Code is Poetry</FlexBlock>
<FlexItem>
<Button isLink>Dismiss</Button>
</FlexItem>
</CardHeader>

<CardBody>...</CardBody>
<CardDivider />
<CardBody>...</CardBody>

<CardFooter isShady={ false }>
<FlexBlock>Footer: Code is Poetry</FlexBlock>
<FlexItem>
<Button isPrimary>Action</Button>
</FlexItem>
</CardFooter>
</Card>
);

export default CardExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { CheckboxControl } from '@wordpress/components';

const CheckboxControlExample = () => {
const [ isChecked, setChecked ] = useState( false );

return (
<CheckboxControl
label="Example Checkbox Control"
checked={ isChecked }
onChange={ setChecked }
/>
);
};

export default CheckboxControlExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { ClipboardButton } from '@wordpress/components';

const ClipboardButtonExample = () => {
const [ isCopied, setCopied ] = useState( false );

const text = 'Code is Poetry';
return (
<ClipboardButton
text={ text }
isPrimary
onCopy={ () => setCopied( true ) }
onFinishCopy={ () => setCopied( false ) }
>
{ isCopied ? 'Copied!' : `Copy "${ text }"` }
</ClipboardButton>
);
};

export default ClipboardButtonExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* External dependencies
*/
import React, { useState } from 'react';

/**
* WordPress dependencies
*/
import { ColorPalette } from '@wordpress/components';

const ColorPaletteExample = () => {
const colors: ColorPalette.Color[] = [
{ name: 'red', color: '#f00' },
{ name: 'white', color: '#fff' },
{ name: 'blue', color: '#00f' },
];

const [ color, setColor ] = useState( colors[ 0 ] );

return (
<ColorPalette
colors={ colors }
value={ color }
onChange={ ( maybeColor ) => maybeColor && setColor( maybeColor ) }
/>
);
};

export default ColorPaletteExample;
Loading