diff --git a/app/soapbox/features/compose/components/compose_form.js b/app/soapbox/features/compose/components/compose_form.js index 0f34cc24d..0cb9eb98c 100644 --- a/app/soapbox/features/compose/components/compose_form.js +++ b/app/soapbox/features/compose/components/compose_form.js @@ -1,5 +1,6 @@ import React from 'react'; -import CharacterCounter from './character_counter'; +// import TextCharacterCounter from './text_character_counter'; +import VisualCharacterCounter from './visual_character_counter'; import Button from '../../../components/button'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; @@ -351,7 +352,12 @@ export default class ComposeForm extends ImmutablePureComponent { - {maxTootChars &&
} + {maxTootChars && ( +
+ {/* */} + +
+ )}
diff --git a/app/soapbox/features/compose/components/text_character_counter.js b/app/soapbox/features/compose/components/text_character_counter.js new file mode 100644 index 000000000..99a96d1ca --- /dev/null +++ b/app/soapbox/features/compose/components/text_character_counter.js @@ -0,0 +1,25 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { length } from 'stringz'; + +export default class TextCharacterCounter extends React.PureComponent { + + static propTypes = { + text: PropTypes.string.isRequired, + max: PropTypes.number.isRequired, + }; + + checkRemainingText(diff) { + if (diff < 0) { + return {diff}; + } + + return {diff}; + } + + render() { + const diff = this.props.max - length(this.props.text); + return this.checkRemainingText(diff); + } + +} diff --git a/app/soapbox/features/compose/components/character_counter.js b/app/soapbox/features/compose/components/visual_character_counter.js similarity index 66% rename from app/soapbox/features/compose/components/character_counter.js rename to app/soapbox/features/compose/components/visual_character_counter.js index a3daa3867..f7873e82c 100644 --- a/app/soapbox/features/compose/components/character_counter.js +++ b/app/soapbox/features/compose/components/visual_character_counter.js @@ -13,7 +13,7 @@ const messages = defineMessages({ * @param {string} props.text - text to use to measure * @param {number} props.max - max text allowed */ -class CharacterCounter extends React.PureComponent { +class VisualCharacterCounter extends React.PureComponent { render() { const { intl, text, max } = this.props; @@ -22,21 +22,23 @@ class CharacterCounter extends React.PureComponent { const progress = textLength / max; return ( - +
+ +
); } } -CharacterCounter.propTypes = { +VisualCharacterCounter.propTypes = { intl: PropTypes.object.isRequired, text: PropTypes.string.isRequired, max: PropTypes.number.isRequired, }; -export default injectIntl(CharacterCounter); +export default injectIntl(VisualCharacterCounter); diff --git a/app/styles/components/compose-form.scss b/app/styles/components/compose-form.scss index 4345c77ec..cd9e91ec4 100644 --- a/app/styles/components/compose-form.scss +++ b/app/styles/components/compose-form.scss @@ -27,7 +27,7 @@ } } - .compose-form__warning { + &__warning { color: var(--primary-text-color); margin-bottom: 10px; background: var(--brand-color--faint); @@ -66,7 +66,7 @@ right: 5px; } - .compose-form__autosuggest-wrapper { + &__autosuggest-wrapper { position: relative; } @@ -195,7 +195,7 @@ color: var(--primary-text-color--faint); } - .compose-form__modifiers { + &__modifiers { color: var(--primary-text-color); font-family: inherit; font-size: 14px; @@ -327,7 +327,7 @@ } } // end .compose-form .compose-form__modifiers - .compose-form__buttons-wrapper { + &__buttons-wrapper { padding: 10px; background: var(--background-color); display: flex; @@ -380,13 +380,23 @@ } } - .character-counter__wrapper { - align-self: center; - margin: 0 10px 0 auto; + .character-counter { + display: block; + cursor: default; + font-family: var(--font-sans-serif), sans-serif; + font-size: 14px; + font-weight: 600; + color: var(--primary-text-color--faint); + &.character-counter--over { color: $warning-red; } + } + + .character-counter, + .visual-character-counter { + margin-right: 10px; } } - .compose-form__publish { + &__publish { display: flex; justify-content: flex-end; min-width: 0; @@ -396,6 +406,13 @@ overflow: hidden; } } + + &__counter { + display: flex; + align-items: center; + align-self: center; + margin-left: auto; + } } // end .compose-form // Icon tweaks