All files / buffer-web-components/ScheduleSetting/ScheduleTable/ScheduleTableCell index.jsx

100% Statements 12/12
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12
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                      2x           104x                   104x             104x       104x   104x 2x                   104x                                             2x         96x                 2x         2x                                  
import React from 'react';
import PropTypes from 'prop-types';
import {
  Button,
  CloseIcon,
  InputTime,
} from '@bufferapp/components';
import { calculateStyles } from '@bufferapp/components/lib/utils';
import TableCell from '../../../TableCell';
 
/* eslint-disable react/prop-types */
const TableCellContents = ({
  disabled,
  hovered,
  select24Hours,
  time,
}) => {
  const style = calculateStyles({
    default: {
      position: 'relative',
      display: 'flex',
      height: '2rem',
      justifyContent: 'center',
      alignItems: 'center',
    },
  });
 
  const buttonStyle = calculateStyles({
    default: {
      position: 'absolute',
      right: '0.25rem',
    },
  });
 
  const iconWrapperStyle = {
    marginTop: '0.1rem',
  };
 
  let removeButton = '';
 
  if (hovered && !disabled) {
    removeButton =
      <div style={buttonStyle}>
        <Button onClick={time.onRemoveTimeClick} noStyle>
          <div style={iconWrapperStyle}>
            <CloseIcon size={'small'} />
          </div>
        </Button>
      </div>;
  }
 
  return (
    <div style={style}>
      {removeButton}
      <div
        style={{
          width: '4.5rem',
        }}
      >
        <InputTime
          fontSize={'small'}
          disabled={disabled}
          input={time}
          select24Hours={select24Hours}
          minimal
          centerText
          displayTimeColon
        />
      </div>
    </div>
  );
};
/* eslint-enable react/prop-types */
 
const ScheduleTableCell = ({
  disabled,
  select24Hours,
  time,
}) => (
  <TableCell>
    <TableCellContents
      disabled={disabled}
      select24Hours={select24Hours}
      time={time}
    />
  </TableCell>
  );
 
ScheduleTableCell.defaultProps = {
  disabled: false,
  select24Hours: false,
};
 
ScheduleTableCell.propTypes = {
  disabled: PropTypes.bool.isRequired,
  select24Hours: PropTypes.bool.isRequired,
  time: PropTypes.shape({
    value: PropTypes.oneOfType([
      PropTypes.shape({
        hours: PropTypes.number.isRequired,
        minutes: PropTypes.number.isRequired,
      }),
      PropTypes.string,
    ]),
    onChange: PropTypes.func.isRequired,
    onRemoveTimeClick: PropTypes.func.isRequired,
  }).isRequired,
};
 
export default ScheduleTableCell;