All files / src/list-examples WithComponents.js

100% Statements 6/6
100% Branches 6/6
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                    2x                                                                                               2x 4x 4x 4x   4x                                                                    
// @flow strict
import React from 'react';
 
import List from '../material-toolbox/list';
import ListItem from '../material-toolbox/list/Item';
import ListItemDetail from '../material-toolbox/list/ItemDetail';
import ListItemText from '../material-toolbox/list/ItemText';
import ListDivider from '../material-toolbox/list/Divider';
import Checkbox from '../material-toolbox/checkbox';
import Radio from '../material-toolbox/radio';
 
import Example from '../Example';
 
type Props = {
  title: string,
  type: 'checkbox' | 'radio',
};
 
const source = `import React from 'react';
 
import List from 'material-toolbox/list';
import ListItem from 'material-toolbox/list/Item';
import ListItemDetail from 'material-toolbox/list/ItemDetail';
import ListItemText from 'material-toolbox/list/ItemText';
import ListDivider from 'material-toolbox/list/Divider';
import Checkbox from 'material-toolbox/checkbox';
import Radio from 'material-toolbox/radio';
 
const WithComponents = ({ title, type }: Props) => {
  const Component = type === 'checkbox' ? Checkbox : Radio;
  const role = type === 'checkbox' ? 'group' : 'radiogroup';
  const label = type === 'checkbox' ? 'List with checkbox items' : undefined;
 
  return (
    <List className="demo-list" role={role}>
      <ListItem role={type}>
        <ListItemText>Dog Photos</ListItemText>
        <ListItemDetail end>
          <Component name={\`\${type}-list-component\`} />
        </ListItemDetail>
      </ListItem>
      <ListItem role={type}>
        <ListItemText>Cat Photos</ListItemText>
        <ListItemDetail end>
          <Component name={\`\${type}-list-component\`} />
        </ListItemDetail>
      </ListItem>
      <ListDivider />
      <ListItem role={type}>
        <ListItemText>Potatos</ListItemText>
        <ListItemDetail end>
          <Component name={\`\${type}-list-component\`} />
        </ListItemDetail>
      </ListItem>
      <ListItem role={type}>
        <ListItemText>Carrots</ListItemText>
        <ListItemDetail end>
          <Component name={\`\${type}-list-component\`} />
        </ListItemDetail>
      </ListItem>
    </List>
  );
};
 
export default WithComponents;`;
 
const WithComponents = ({ title, type }: Props) => {
  const Component = type === 'checkbox' ? Checkbox : Radio;
  const role = type === 'checkbox' ? 'group' : 'radiogroup';
  const label = type === 'checkbox' ? 'List with checkbox items' : undefined;
 
  return (
    <Example title={title} source={source} aria-label={label}>
      <List className="demo-list" role={role}>
        <ListItem role={type}>
          <ListItemText>Dog Photos</ListItemText>
          <ListItemDetail end>
            <Component name={`${type}-list-component`} />
          </ListItemDetail>
        </ListItem>
        <ListItem role={type}>
          <ListItemText>Cat Photos</ListItemText>
          <ListItemDetail end>
            <Component name={`${type}-list-component`} />
          </ListItemDetail>
        </ListItem>
        <ListDivider />
        <ListItem role={type}>
          <ListItemText>Potatos</ListItemText>
          <ListItemDetail end>
            <Component name={`${type}-list-component`} />
          </ListItemDetail>
        </ListItem>
        <ListItem role={type}>
          <ListItemText>Carrots</ListItemText>
          <ListItemDetail end>
            <Component name={`${type}-list-component`} />
          </ListItemDetail>
        </ListItem>
      </List>
    </Example>
  );
};
 
export default WithComponents;