All files / src/card-examples WithActions.js

100% Statements 6/6
100% Branches 1/1
100% Functions 2/2
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                                  2x                                                                                                                               2x                                                       2x 4x                                                                 2x 2x              
// @flow strict
import React from 'react';
import cx from 'classnames';
import Example from '../Example';
 
import Button from '../material-toolbox/button';
import IconButton from '../material-toolbox/icon-button';
import IconButtonState from '../material-toolbox/icon-button/State';
import Card from '../material-toolbox/card';
import CardActions from '../material-toolbox/card/Actions';
import CardActionButtons from '../material-toolbox/card/ActionButtons';
import CardAction from '../material-toolbox/card/Action';
import CardActionIcons from '../material-toolbox/card/ActionIcons';
import CardPrimaryAction from '../material-toolbox/card/PrimaryAction';
 
import CommonContent from './CommonContent';
 
const source = `import Text from 'material-toolbox/typography/Text';
import Button from 'material-toolbox/button/Button';
import ButtonIcon from 'material-toolbox/button/Icon';
import IconToggle from 'material-toolbox/icon-toggle';
import Card from 'material-toolbox/card/Card';
import CardActions from 'material-toolbox/card/Actions';
import CardActionButtons from 'material-toolbox/card/ActionButtons';
import CardAction from 'material-toolbox/card/Action';
import CardActionIcons from 'material-toolbox/card/ActionIcons';
import CardPrimaryAction from 'material-toolbox/card/PrimaryAction';
 
const BasicWithAction = ({ shaped = false }: { shaped?: boolean }) => (
  <Card className={cx('demo-card', { 'demo-card-shaped': shaped })}>
    <CardPrimaryAction>
      <div className="demo-card__primary">
        <Text text="headline6" as="h2" className="demo-card__title">
          Our Changing Planet
        </Text>
        <Text text="subtitle2" as="h3" className="demo-card__subtitle">
          by Kurt Wagner
        </Text>
      </div>
      <Text className="demo-card__secondary" text="body2" as="div">
        Visit ten places on our planet that are undergoing the biggest changes
        today.
      </Text>
    </CardPrimaryAction>
    <CardActions>
      <CardActionButtons>
        <CardAction>
          <Button>Read</Button>
          <Button>Bookmark</Button>
        </CardAction>
      </CardActionButtons>
      <CardActionIcons>
        <CardAction icon>
          <IconButton
            onLabel="Remove from favorites"
            offLabel="Add to favorites"
            toggle>
            <IconButtonState className="material-icons">
              favorite_border
            </IconButtonState>
            <IconButtonState className="material-icons" isOn>
              favorite
            </IconButtonState>
          </IconButton>
          <IconButton className="material-icons">share</IconButton>
          <IconButton className="material-icons">more_vert</IconButton>
        </CardAction>
      </CardActionIcons>
    </CardActions>
  </Card>
);
 
const WithActions = () => (
  <React.Fragment>
    <BasicWithAction />
    <BasicWithAction shaped />
  </React.Fragment>
);
 
export default WithActions;`;
 
const scssSource = `.demo-card {
  width: 350px;
  margin: 48px 0;
 
  &__primary {
    padding: 1rem;
  }
 
  &__title,
  &__subtitle {
    margin: 0;
  }
 
  &__secondary {
    padding: 0 1rem 8px;
  }
 
  &__secondary,
  &__subtitle {
    color: rgba(0, 0, 0, 0.54);
    color: var(--mdc-theme-text-secondary-on-background, rgba(0, 0, 0, 0.54));
  }
 
  &-shaped {
    border-radius: 24px 8px;
  }
}`;
 
const BasicWithAction = ({ shaped = false }: { shaped?: boolean }) => (
  <Card className={cx('demo-card', { 'demo-card-shaped': shaped })}>
    <CardPrimaryAction>
      <CommonContent />
    </CardPrimaryAction>
    <CardActions>
      <CardActionButtons>
        <CardAction>
          <Button>Read</Button>
          <Button>Bookmark</Button>
        </CardAction>
      </CardActionButtons>
      <CardActionIcons>
        <CardAction icon>
          <IconButton
            onLabel="Remove from favorites"
            offLabel="Add to favorites"
            toggle
          >
            <IconButtonState className="material-icons">
              favorite_border
            </IconButtonState>
            <IconButtonState className="material-icons" isOn>
              favorite
            </IconButtonState>
          </IconButton>
          <IconButton className="material-icons">share</IconButton>
          <IconButton className="material-icons">more_vert</IconButton>
        </CardAction>
      </CardActionIcons>
    </CardActions>
  </Card>
);
 
const WithActions = () => (
  <Example title="With actions" source={source} scss={scssSource}>
    <BasicWithAction />
    <BasicWithAction shaped />
  </Example>
);
 
export default WithActions;