@contentful/field-editor-multiple-line 1.3.10 → 1.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
54
54
  return newObj;
55
55
  }
56
56
  function MultipleLineEditor(props) {
57
- const { field, locales, isInitiallyDisabled } = props;
57
+ const { field, locales, isInitiallyDisabled, withCharValidation } = props;
58
58
  const constraints = _fieldeditorshared.ConstraintsUtils.fromFieldValidations(field.validations, field.type);
59
59
  const checkConstraint = _fieldeditorshared.ConstraintsUtils.makeChecker(constraints);
60
60
  const direction = locales.direction[field.locale] || 'ltr';
@@ -74,15 +74,22 @@ function MultipleLineEditor(props) {
74
74
  onChange: (e)=>{
75
75
  setValue(e.target.value);
76
76
  }
77
- }), _react.createElement("div", {
78
- className: _styles.counterRow
77
+ }), withCharValidation && _react.createElement("div", {
78
+ className: _styles.validationRow
79
79
  }, _react.createElement(_fieldeditorshared.CharCounter, {
80
80
  value: value || '',
81
- checkConstraint: checkConstraint,
81
+ checkConstraint: checkConstraint
82
+ }), _react.createElement(_fieldeditorshared.CharValidation, {
82
83
  constraints: constraints
84
+ })), !withCharValidation && _react.createElement("div", {
85
+ className: _styles.validationRow
86
+ }, _react.createElement(_fieldeditorshared.CharCounter, {
87
+ value: value || '',
88
+ checkConstraint: ()=>true
83
89
  })));
84
90
  });
85
91
  }
86
92
  MultipleLineEditor.defaultProps = {
87
- isInitiallyDisabled: true
93
+ isInitiallyDisabled: true,
94
+ withCharValidation: true
88
95
  };
@@ -66,7 +66,6 @@ describe('MultipleLineEditor', ()=>{
66
66
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
67
67
  return {
68
68
  ...field,
69
- type: 'Text',
70
69
  id: 'field-id',
71
70
  getValue: ()=>{
72
71
  return initialValue;
@@ -79,7 +78,6 @@ describe('MultipleLineEditor', ()=>{
79
78
  isInitiallyDisabled: false
80
79
  }));
81
80
  expect(getByTestId('cf-ui-textarea')).toHaveValue(initialValue);
82
- expect(getByTestId('cf-ui-char-counter')).toHaveTextContent(`${initialValue.length} / 50000`);
83
81
  });
84
82
  it('calls field.setValue when user types and calls field.removeValue when user clears the input', async ()=>{
85
83
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
@@ -9,11 +9,11 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- counterRow: function() {
13
- return counterRow;
14
- },
15
12
  rightToLeft: function() {
16
13
  return rightToLeft;
14
+ },
15
+ validationRow: function() {
16
+ return validationRow;
17
17
  }
18
18
  });
19
19
  const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
@@ -23,12 +23,12 @@ function _interop_require_default(obj) {
23
23
  default: obj
24
24
  };
25
25
  }
26
- const counterRow = (0, _emotion.css)({
27
- float: 'right',
26
+ const validationRow = (0, _emotion.css)({
27
+ display: 'flex',
28
+ justifyContent: 'space-between',
28
29
  fontSize: _f36tokens.default.fontSizeM,
29
30
  marginTop: _f36tokens.default.spacingXs,
30
- marginLeft: _f36tokens.default.spacingS,
31
- color: _f36tokens.default.gray500
31
+ color: _f36tokens.default.gray700
32
32
  });
33
33
  const rightToLeft = (0, _emotion.css)({
34
34
  direction: 'rtl'
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { Textarea } from '@contentful/f36-components';
3
- import { FieldConnector, CharCounter, ConstraintsUtils } from '@contentful/field-editor-shared';
3
+ import { FieldConnector, CharCounter, CharValidation, ConstraintsUtils } from '@contentful/field-editor-shared';
4
4
  import * as styles from './styles';
5
5
  export function MultipleLineEditor(props) {
6
- const { field, locales, isInitiallyDisabled } = props;
6
+ const { field, locales, isInitiallyDisabled, withCharValidation } = props;
7
7
  const constraints = ConstraintsUtils.fromFieldValidations(field.validations, field.type);
8
8
  const checkConstraint = ConstraintsUtils.makeChecker(constraints);
9
9
  const direction = locales.direction[field.locale] || 'ltr';
@@ -23,15 +23,22 @@ export function MultipleLineEditor(props) {
23
23
  onChange: (e)=>{
24
24
  setValue(e.target.value);
25
25
  }
26
- }), React.createElement("div", {
27
- className: styles.counterRow
26
+ }), withCharValidation && React.createElement("div", {
27
+ className: styles.validationRow
28
28
  }, React.createElement(CharCounter, {
29
29
  value: value || '',
30
- checkConstraint: checkConstraint,
30
+ checkConstraint: checkConstraint
31
+ }), React.createElement(CharValidation, {
31
32
  constraints: constraints
33
+ })), !withCharValidation && React.createElement("div", {
34
+ className: styles.validationRow
35
+ }, React.createElement(CharCounter, {
36
+ value: value || '',
37
+ checkConstraint: ()=>true
32
38
  })));
33
39
  });
34
40
  }
35
41
  MultipleLineEditor.defaultProps = {
36
- isInitiallyDisabled: true
42
+ isInitiallyDisabled: true,
43
+ withCharValidation: true
37
44
  };
@@ -21,7 +21,6 @@ describe('MultipleLineEditor', ()=>{
21
21
  const [field] = createFakeFieldAPI((field)=>{
22
22
  return {
23
23
  ...field,
24
- type: 'Text',
25
24
  id: 'field-id',
26
25
  getValue: ()=>{
27
26
  return initialValue;
@@ -34,7 +33,6 @@ describe('MultipleLineEditor', ()=>{
34
33
  isInitiallyDisabled: false
35
34
  }));
36
35
  expect(getByTestId('cf-ui-textarea')).toHaveValue(initialValue);
37
- expect(getByTestId('cf-ui-char-counter')).toHaveTextContent(`${initialValue.length} / 50000`);
38
36
  });
39
37
  it('calls field.setValue when user types and calls field.removeValue when user clears the input', async ()=>{
40
38
  const [field] = createFakeFieldAPI((field)=>{
@@ -1,11 +1,11 @@
1
1
  import tokens from '@contentful/f36-tokens';
2
2
  import { css } from 'emotion';
3
- export const counterRow = css({
4
- float: 'right',
3
+ export const validationRow = css({
4
+ display: 'flex',
5
+ justifyContent: 'space-between',
5
6
  fontSize: tokens.fontSizeM,
6
7
  marginTop: tokens.spacingXs,
7
- marginLeft: tokens.spacingS,
8
- color: tokens.gray500
8
+ color: tokens.gray700
9
9
  });
10
10
  export const rightToLeft = css({
11
11
  direction: 'rtl'
@@ -5,6 +5,10 @@ export interface MultipleLineEditorProps {
5
5
  * is the field disabled initially
6
6
  */
7
7
  isInitiallyDisabled: boolean;
8
+ /**
9
+ * whether char validation should be shown or not
10
+ */
11
+ withCharValidation: boolean;
8
12
  /**
9
13
  * sdk.field
10
14
  */
@@ -18,5 +22,6 @@ export declare function MultipleLineEditor(props: MultipleLineEditorProps): JSX.
18
22
  export declare namespace MultipleLineEditor {
19
23
  var defaultProps: {
20
24
  isInitiallyDisabled: boolean;
25
+ withCharValidation: boolean;
21
26
  };
22
27
  }
@@ -1,2 +1,2 @@
1
- export declare const counterRow: string;
1
+ export declare const validationRow: string;
2
2
  export declare const rightToLeft: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-multiple-line",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@contentful/f36-components": "^4.0.27",
39
39
  "@contentful/f36-tokens": "^4.0.0",
40
- "@contentful/field-editor-shared": "^1.4.8",
40
+ "@contentful/field-editor-shared": "^1.4.9",
41
41
  "emotion": "^10.0.17",
42
42
  "lodash": "^4.17.15"
43
43
  },
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "registry": "https://npm.pkg.github.com/"
52
52
  },
53
- "gitHead": "1d7d630fe6f9576ee4cf35feed8badc8440acbf1"
53
+ "gitHead": "29cf5fb16a8d61f6c23678dad618c61aceec320d"
54
54
  }