2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2017-04-26 00:37:51 +09:00
|
|
|
import { length } from 'stringz';
|
2016-08-31 23:15:12 +09:00
|
|
|
|
2024-01-26 00:41:31 +09:00
|
|
|
export const CharacterCounter = ({ text, max }) => {
|
|
|
|
const diff = max - length(text);
|
2016-08-31 23:15:12 +09:00
|
|
|
|
2024-01-26 00:41:31 +09:00
|
|
|
if (diff < 0) {
|
|
|
|
return <span className='character-counter character-counter--over'>{diff}</span>;
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-04-17 17:34:33 +09:00
|
|
|
|
2024-01-26 00:41:31 +09:00
|
|
|
return <span className='character-counter'>{diff}</span>;
|
|
|
|
};
|
2016-08-26 02:52:55 +09:00
|
|
|
|
2024-01-26 00:41:31 +09:00
|
|
|
CharacterCounter.propTypes = {
|
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
max: PropTypes.number.isRequired,
|
|
|
|
};
|