1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +02:00
planka/client/src/components/DueDate/DueDate.jsx

76 lines
1.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import styles from './DueDate.module.css';
const SIZES = {
TINY: 'tiny',
SMALL: 'small',
MEDIUM: 'medium',
};
// TODO: move to styles
const STYLES = {
tiny: {
fontSize: '12px',
lineHeight: '20px',
padding: '0px 6px',
},
small: {
fontSize: '12px',
lineHeight: '20px',
padding: '2px 6px',
},
medium: {
lineHeight: '20px',
padding: '6px 12px',
},
};
const FORMATS = {
tiny: 'longDate',
small: 'longDate',
medium: 'longDateTime',
};
const DueDate = React.memo(({ value, size, isDisabled, onClick }) => {
const [t] = useTranslation();
const style = {
...STYLES[size],
};
const contentNode = (
<span className={classNames(styles.wrapper, onClick && styles.hoverable)} style={style}>
{t(`format:${FORMATS[size]}`, {
value,
postProcess: 'formatDate',
})}
</span>
);
return onClick ? (
<button type="button" disabled={isDisabled} className={styles.button} onClick={onClick}>
{contentNode}
</button>
) : (
contentNode
);
});
DueDate.propTypes = {
value: PropTypes.instanceOf(Date).isRequired,
size: PropTypes.oneOf(Object.values(SIZES)),
isDisabled: PropTypes.bool,
onClick: PropTypes.func,
};
DueDate.defaultProps = {
size: SIZES.MEDIUM,
isDisabled: false,
onClick: undefined,
};
export default DueDate;