2020-03-25 13:05:23 +01:00
|
|
|
import React, { useState, useRef } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useClickAwayListener } from '@buffetjs/hooks';
|
|
|
|
import { useGlobalContext } from 'strapi-helper-plugin';
|
|
|
|
import DoubleFile from '../../icons/DoubleFile';
|
|
|
|
import File from '../../icons/File';
|
|
|
|
import Padded from '../Padded';
|
|
|
|
import Button from './Button';
|
|
|
|
import Spacer from './Spacer';
|
2020-04-03 17:08:45 +02:00
|
|
|
import CardControl from '../CardControl';
|
2020-04-03 10:09:38 +02:00
|
|
|
import CustomDropdownSection from './CustomDropdownSection';
|
2020-03-25 13:05:23 +01:00
|
|
|
import { getTrad } from '../../utils';
|
|
|
|
|
2020-03-31 16:30:43 +02:00
|
|
|
const CheckControl = ({ title, onSubmitEdit }) => {
|
2020-03-25 13:05:23 +01:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
const { formatMessage } = useGlobalContext();
|
|
|
|
const dropdownRef = useRef();
|
|
|
|
|
|
|
|
useClickAwayListener(dropdownRef, () => setIsOpen(false));
|
|
|
|
|
|
|
|
const handleClick = e => {
|
|
|
|
e.persist();
|
|
|
|
setIsOpen(false);
|
|
|
|
onSubmitEdit(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickDuplicate = e => {
|
|
|
|
e.persist();
|
|
|
|
setIsOpen(false);
|
|
|
|
onSubmitEdit(e, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleToggle = () => {
|
|
|
|
setIsOpen(v => !v);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-04-02 18:27:18 +02:00
|
|
|
<div ref={dropdownRef}>
|
2020-04-03 17:08:45 +02:00
|
|
|
<CardControl
|
|
|
|
color="#6DBB1A"
|
2020-04-02 18:27:18 +02:00
|
|
|
onClick={handleToggle}
|
2020-04-03 17:08:45 +02:00
|
|
|
type="check"
|
2020-04-07 10:57:59 +02:00
|
|
|
title={title}
|
2020-04-03 17:08:45 +02:00
|
|
|
iconStyle={{ height: '1.4rem', width: '1.4rem' }}
|
|
|
|
/>
|
2020-04-03 10:09:38 +02:00
|
|
|
<CustomDropdownSection isOpen={isOpen}>
|
2020-03-25 13:05:23 +01:00
|
|
|
<Padded left right bottom top size="15px">
|
|
|
|
<Button onClick={handleClick}>
|
2020-04-03 17:08:45 +02:00
|
|
|
<File style={{ height: '2rem' }} />
|
2020-03-25 13:05:23 +01:00
|
|
|
{formatMessage({ id: getTrad('checkControl.crop-original') })}
|
|
|
|
</Button>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={handleClickDuplicate}>
|
2020-04-03 17:08:45 +02:00
|
|
|
<DoubleFile style={{ height: '1.8rem' }} />
|
2020-03-25 13:05:23 +01:00
|
|
|
{formatMessage({ id: getTrad('checkControl.crop-duplicate') })}
|
|
|
|
</Button>
|
|
|
|
</Padded>
|
2020-04-03 10:09:38 +02:00
|
|
|
</CustomDropdownSection>
|
2020-04-02 18:27:18 +02:00
|
|
|
</div>
|
2020-03-25 13:05:23 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
CheckControl.defaultProps = {
|
|
|
|
onSubmitEdit: () => {},
|
2020-03-31 16:30:43 +02:00
|
|
|
title: null,
|
2020-03-25 13:05:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckControl.propTypes = {
|
|
|
|
onSubmitEdit: PropTypes.func,
|
2020-03-31 16:30:43 +02:00
|
|
|
title: PropTypes.string,
|
2020-03-25 13:05:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default CheckControl;
|