File size: 3,578 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
import { Button, Gridicon } from '@automattic/components';
import { Component } from 'react';
import FormInputCheckbox from 'calypso/components/forms/form-checkbox';
import Table from '..';
import TableItem from '../table-item';
import TableRow from '../table-row';
class Example extends Component {
state = {
hasBorder: false,
isCompact: false,
};
onToggleCompact = () => {
this.setState( { isCompact: ! this.state.isCompact } );
};
render() {
const titles = (
<TableRow isHeader>
{ [ 'Title', '', 'Qty', 'Total' ].map( ( item, i ) => (
<TableItem isHeader key={ i } isTitle={ 0 === i }>
{ item }
</TableItem>
) ) }
</TableRow>
);
// eslint-disable-next-line jsx-a11y/anchor-is-valid
const link = <a href="#">An internal Link!</a>;
const externalLink = (
// eslint-disable-next-line jsx-a11y/anchor-is-valid
<a href="#">
<Gridicon icon="external" size={ 18 } />
</a>
);
const placeholder = '';
const values = [
// eslint-disable-next-line jsx-a11y/anchor-is-valid
[ 'one', placeholder, <a href="#">222</a>, 45 ],
[ 'really really really really really really long name', placeholder, 55, 777 ],
[ 'three', externalLink, <div>9</div>, 45 ],
[ link, externalLink, <Gridicon icon="cog" size={ 18 } />, 8 ],
];
const middleColValues = [
[ <FormInputCheckbox />, 'Thing 1', 65 ],
[ <FormInputCheckbox />, 'Thing 2', 66 ],
[ <FormInputCheckbox />, 'Thing 3', 67 ],
[ <FormInputCheckbox />, 'Thing 4', <Gridicon icon="cog" size={ 18 } /> ],
];
const middleColTitles = (
<TableRow isHeader>
{ [ <FormInputCheckbox />, 'Description', 'Total' ].map( ( item, i ) => (
<TableItem isHeader key={ i } isTitle={ 1 === i } alignRight={ 2 === i }>
{ item }
</TableItem>
) ) }
</TableRow>
);
return (
<div className="woocommerce">
<div className="docs__design-toggle">
<Button onClick={ this.onToggleCompact }>
{ this.state.isCompact ? 'Expanded' : 'Compact' }
</Button>
</div>
<Table header={ titles } compact={ this.state.isCompact }>
{ values.map( ( row, i ) => (
<TableRow key={ i }>
{ row.map( ( item, j ) => (
<TableItem key={ j } isTitle={ 0 === j }>
{ item }
</TableItem>
) ) }
</TableRow>
) ) }
</Table>
<Table header={ middleColTitles } compact={ this.state.isCompact }>
{ middleColValues.map( ( row, i ) => (
<TableRow key={ i }>
{ row.map( ( item, j ) => (
<TableItem
key={ j }
isRowHeader={ 1 === j }
isTitle={ 1 === j }
alignRight={ 2 === j }
>
{ item }
</TableItem>
) ) }
</TableRow>
) ) }
</Table>
<div style={ { width: '50%' } }>
<Table header={ titles } compact={ this.state.isCompact }>
{ values.map( ( row, i ) => (
<TableRow key={ i }>
{ row.map( ( item, j ) => (
<TableItem key={ j } isRowHeader={ 0 === j } isTitle={ 0 === j }>
{ item }
</TableItem>
) ) }
</TableRow>
) ) }
</Table>
</div>
<div style={ { width: '33%' } }>
<Table header={ titles } compact={ this.state.isCompact }>
{ values.map( ( row, i ) => (
<TableRow key={ i }>
{ row.map( ( item, j ) => (
<TableItem key={ j } isTitle={ 0 === j }>
{ item }
</TableItem>
) ) }
</TableRow>
) ) }
</Table>
</div>
</div>
);
}
}
Example.displayName = 'WooTable';
export default Example;
|