Skip to content

Commit

Permalink
feat(text-area): make monospace font optional
Browse files Browse the repository at this point in the history
Closes #87
  • Loading branch information
Niklas Kiefer committed Aug 3, 2021
1 parent 77fff84 commit 7e6f1eb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
7 changes: 7 additions & 0 deletions assets/properties-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
border-radius: 3px;
background-color: var(--color-input-background);
font-size: 14px;
font-style: normal;
font-weight: 400;
font-family: inherit;
}

.bio-properties-panel-input[type=number],
Expand All @@ -294,6 +297,10 @@ textarea.bio-properties-panel-input,
border: 1px solid var(--color-input-border-focus);
}

.bio-properties-panel-input-monospace {
font-family: monospace;
}

.bio-properties-panel-input[type="checkbox"], .bio-properties-panel-input[type="radio"] {
margin: 0;
}
Expand Down
17 changes: 13 additions & 4 deletions src/components/entries/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
useMemo
} from 'preact/hooks';

import classnames from 'classnames';

function TextArea(props) {

const {
Expand All @@ -10,7 +12,8 @@ function TextArea(props) {
rows = 2,
debounce,
onInput,
value = ''
value = '',
monospace
} = props;

const handleInput = useMemo(() => {
Expand All @@ -24,7 +27,10 @@ function TextArea(props) {
id={ prefixId(id) }
name={ id }
spellCheck="false"
class="bio-properties-panel-input"
class={ classnames(
'bio-properties-panel-input',
monospace ? 'bio-properties-panel-input-monospace' : '')
}
onInput={ handleInput }
onFocus={ props.onFocus }
onBlur={ props.onBlur }
Expand All @@ -44,6 +50,7 @@ function TextArea(props) {
* @param {Function} props.getValue
* @param {Function} props.setValue
* @param {Number} props.rows
* @param {Boolean} props.monospace
*/
export default function TextAreaEntry(props) {
const {
Expand All @@ -54,7 +61,8 @@ export default function TextAreaEntry(props) {
label,
getValue,
setValue,
rows
rows,
monospace
} = props;

const value = getValue(element);
Expand All @@ -66,7 +74,8 @@ export default function TextAreaEntry(props) {
value={ value }
onInput={ setValue }
rows={ rows }
debounce={ debounce } />
debounce={ debounce }
monospace={ monospace } />
{ description && <div class="bio-properties-panel-description">{ description }</div> }
</div>
);
Expand Down
17 changes: 16 additions & 1 deletion test/spec/components/TextArea.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import TestContainer from 'mocha-test-container-support';

import {
classes as domClasses,
query as domQuery
} from 'min-dom';

Expand Down Expand Up @@ -39,6 +40,18 @@ describe('<TextArea>', function() {
});


it('should render - monospace', function() {

// given
const result = createTextArea({ container, monospace: true });

const input = domQuery('.bio-properties-panel-input', result.container);

// then
expect(domClasses(input).has('bio-properties-panel-input-monospace')).to.be.true;
});


it('should update', function() {

// given
Expand Down Expand Up @@ -122,6 +135,7 @@ function createTextArea(options = {}) {
getValue = noop,
setValue = noop,
rows,
monospace,
container
} = options;

Expand All @@ -134,6 +148,7 @@ function createTextArea(options = {}) {
getValue={ getValue }
setValue={ setValue }
debounce={ debounce }
rows={ rows } />,
rows={ rows }
monospace={ monospace } />,
{ container });
}

0 comments on commit 7e6f1eb

Please sign in to comment.