@contentful/field-editor-single-line 1.3.8 → 1.3.10

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.
@@ -80,22 +80,15 @@ function SingleLineEditor(props) {
80
80
  onChange: (e)=>{
81
81
  setValue(e.target.value);
82
82
  }
83
- }), props.withCharValidation && _react.createElement("div", {
84
- className: _styles.validationRow
83
+ }), _react.createElement("div", {
84
+ className: _styles.counterRow
85
85
  }, _react.createElement(_fieldeditorshared.CharCounter, {
86
86
  value: value || '',
87
- checkConstraint: checkConstraint
88
- }), _react.createElement(_fieldeditorshared.CharValidation, {
87
+ checkConstraint: checkConstraint,
89
88
  constraints: constraints
90
- })), props.withCharValidation === false && _react.createElement("div", {
91
- className: _styles.validationRow
92
- }, _react.createElement(_fieldeditorshared.CharCounter, {
93
- value: value || '',
94
- checkConstraint: ()=>true
95
89
  })));
96
90
  });
97
91
  }
98
92
  SingleLineEditor.defaultProps = {
99
- isInitiallyDisabled: true,
100
- withCharValidation: true
93
+ isInitiallyDisabled: true
101
94
  };
@@ -78,14 +78,13 @@ describe('SingleLineEditor', ()=>{
78
78
  }
79
79
  };
80
80
  });
81
- const { getByTestId, getByText } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
81
+ const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
82
82
  field: field,
83
83
  isInitiallyDisabled: false,
84
84
  locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
85
85
  }));
86
86
  expect(getByTestId('cf-ui-text-input')).toHaveValue(initialValue);
87
- expect(getByText(`${initialValue.length} characters`)).toBeInTheDocument();
88
- expect(getByText('Maximum 256 characters')).toBeInTheDocument();
87
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent(`${initialValue.length} / 256`);
89
88
  });
90
89
  it('calls field.setValue when user types and calls field.removeValue when user clears the input', async ()=>{
91
90
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
@@ -133,13 +132,12 @@ describe('SingleLineEditor', ()=>{
133
132
  id: 'field-id'
134
133
  };
135
134
  });
136
- const { getByText } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
135
+ const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
137
136
  field: field,
138
137
  isInitiallyDisabled: false,
139
138
  locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
140
139
  }));
141
- expect(getByText('0 characters')).toBeInTheDocument();
142
- expect(getByText('Maximum 256 characters')).toBeInTheDocument();
140
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 256');
143
141
  });
144
142
  it('shows proper validation message (Text)', ()=>{
145
143
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
@@ -149,13 +147,12 @@ describe('SingleLineEditor', ()=>{
149
147
  id: 'field-id'
150
148
  };
151
149
  });
152
- const { getByText } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
150
+ const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
153
151
  field: field,
154
152
  isInitiallyDisabled: false,
155
153
  locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
156
154
  }));
157
- expect(getByText('0 characters')).toBeInTheDocument();
158
- expect(getByText('Maximum 50000 characters')).toBeInTheDocument();
155
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 50000');
159
156
  });
160
157
  it('shows proper min-max validation message', ()=>{
161
158
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
@@ -173,13 +170,12 @@ describe('SingleLineEditor', ()=>{
173
170
  id: 'field-id'
174
171
  };
175
172
  });
176
- const { getByText } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
173
+ const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
177
174
  field: field,
178
175
  isInitiallyDisabled: false,
179
176
  locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
180
177
  }));
181
- expect(getByText('0 characters')).toBeInTheDocument();
182
- expect(getByText('Requires between 100 and 1000 characters')).toBeInTheDocument();
178
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 1000');
183
179
  });
184
180
  it('shows proper min validation message', ()=>{
185
181
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
@@ -196,37 +192,12 @@ describe('SingleLineEditor', ()=>{
196
192
  id: 'field-id'
197
193
  };
198
194
  });
199
- const { getByText } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
200
- field: field,
201
- isInitiallyDisabled: false,
202
- locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
203
- }));
204
- expect(getByText('0 characters')).toBeInTheDocument();
205
- expect(getByText('Requires at least 1000 characters')).toBeInTheDocument();
206
- });
207
- it('renders no validation message if withCharValidation is falsy', ()=>{
208
- const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
209
- return {
210
- ...field,
211
- type: 'Symbol',
212
- validations: [
213
- {
214
- size: {
215
- min: 100,
216
- max: 1000
217
- }
218
- }
219
- ],
220
- id: 'field-id'
221
- };
222
- });
223
- const { getByText, queryByText } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
195
+ const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
224
196
  field: field,
225
- withCharValidation: false,
226
197
  isInitiallyDisabled: false,
227
198
  locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
228
199
  }));
229
- expect(getByText('0 characters')).toBeInTheDocument();
230
- expect(queryByText('Requires between 100 and 1000 characters')).not.toBeInTheDocument();
200
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0');
201
+ expect(getByTestId('cf-ui-char-counter')).not.toHaveTextContent('0 / 1000');
231
202
  });
232
203
  });
@@ -9,11 +9,11 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ counterRow: function() {
13
+ return counterRow;
14
+ },
12
15
  rightToLeft: function() {
13
16
  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 validationRow = (0, _emotion.css)({
27
- display: 'flex',
28
- justifyContent: 'space-between',
26
+ const counterRow = (0, _emotion.css)({
27
+ float: 'right',
28
+ marginLeft: _f36tokens.default.spacingS,
29
29
  fontSize: _f36tokens.default.fontSizeM,
30
30
  marginTop: _f36tokens.default.spacingXs,
31
- color: _f36tokens.default.gray700
31
+ color: _f36tokens.default.gray500
32
32
  });
33
33
  const rightToLeft = (0, _emotion.css)({
34
34
  direction: 'rtl'
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { TextInput } from '@contentful/f36-components';
3
- import { FieldConnector, ConstraintsUtils, CharCounter, CharValidation } from '@contentful/field-editor-shared';
3
+ import { FieldConnector, ConstraintsUtils, CharCounter } from '@contentful/field-editor-shared';
4
4
  import * as styles from './styles';
5
5
  function isSupportedFieldTypes(val) {
6
6
  return val === 'Symbol' || val === 'Text';
@@ -29,22 +29,15 @@ export function SingleLineEditor(props) {
29
29
  onChange: (e)=>{
30
30
  setValue(e.target.value);
31
31
  }
32
- }), props.withCharValidation && React.createElement("div", {
33
- className: styles.validationRow
32
+ }), React.createElement("div", {
33
+ className: styles.counterRow
34
34
  }, React.createElement(CharCounter, {
35
35
  value: value || '',
36
- checkConstraint: checkConstraint
37
- }), React.createElement(CharValidation, {
36
+ checkConstraint: checkConstraint,
38
37
  constraints: constraints
39
- })), props.withCharValidation === false && React.createElement("div", {
40
- className: styles.validationRow
41
- }, React.createElement(CharCounter, {
42
- value: value || '',
43
- checkConstraint: ()=>true
44
38
  })));
45
39
  });
46
40
  }
47
41
  SingleLineEditor.defaultProps = {
48
- isInitiallyDisabled: true,
49
- withCharValidation: true
42
+ isInitiallyDisabled: true
50
43
  };
@@ -33,14 +33,13 @@ describe('SingleLineEditor', ()=>{
33
33
  }
34
34
  };
35
35
  });
36
- const { getByTestId, getByText } = render(React.createElement(SingleLineEditor, {
36
+ const { getByTestId } = render(React.createElement(SingleLineEditor, {
37
37
  field: field,
38
38
  isInitiallyDisabled: false,
39
39
  locales: createFakeLocalesAPI()
40
40
  }));
41
41
  expect(getByTestId('cf-ui-text-input')).toHaveValue(initialValue);
42
- expect(getByText(`${initialValue.length} characters`)).toBeInTheDocument();
43
- expect(getByText('Maximum 256 characters')).toBeInTheDocument();
42
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent(`${initialValue.length} / 256`);
44
43
  });
45
44
  it('calls field.setValue when user types and calls field.removeValue when user clears the input', async ()=>{
46
45
  const [field] = createFakeFieldAPI((field)=>{
@@ -88,13 +87,12 @@ describe('SingleLineEditor', ()=>{
88
87
  id: 'field-id'
89
88
  };
90
89
  });
91
- const { getByText } = render(React.createElement(SingleLineEditor, {
90
+ const { getByTestId } = render(React.createElement(SingleLineEditor, {
92
91
  field: field,
93
92
  isInitiallyDisabled: false,
94
93
  locales: createFakeLocalesAPI()
95
94
  }));
96
- expect(getByText('0 characters')).toBeInTheDocument();
97
- expect(getByText('Maximum 256 characters')).toBeInTheDocument();
95
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 256');
98
96
  });
99
97
  it('shows proper validation message (Text)', ()=>{
100
98
  const [field] = createFakeFieldAPI((field)=>{
@@ -104,13 +102,12 @@ describe('SingleLineEditor', ()=>{
104
102
  id: 'field-id'
105
103
  };
106
104
  });
107
- const { getByText } = render(React.createElement(SingleLineEditor, {
105
+ const { getByTestId } = render(React.createElement(SingleLineEditor, {
108
106
  field: field,
109
107
  isInitiallyDisabled: false,
110
108
  locales: createFakeLocalesAPI()
111
109
  }));
112
- expect(getByText('0 characters')).toBeInTheDocument();
113
- expect(getByText('Maximum 50000 characters')).toBeInTheDocument();
110
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 50000');
114
111
  });
115
112
  it('shows proper min-max validation message', ()=>{
116
113
  const [field] = createFakeFieldAPI((field)=>{
@@ -128,13 +125,12 @@ describe('SingleLineEditor', ()=>{
128
125
  id: 'field-id'
129
126
  };
130
127
  });
131
- const { getByText } = render(React.createElement(SingleLineEditor, {
128
+ const { getByTestId } = render(React.createElement(SingleLineEditor, {
132
129
  field: field,
133
130
  isInitiallyDisabled: false,
134
131
  locales: createFakeLocalesAPI()
135
132
  }));
136
- expect(getByText('0 characters')).toBeInTheDocument();
137
- expect(getByText('Requires between 100 and 1000 characters')).toBeInTheDocument();
133
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 1000');
138
134
  });
139
135
  it('shows proper min validation message', ()=>{
140
136
  const [field] = createFakeFieldAPI((field)=>{
@@ -151,37 +147,12 @@ describe('SingleLineEditor', ()=>{
151
147
  id: 'field-id'
152
148
  };
153
149
  });
154
- const { getByText } = render(React.createElement(SingleLineEditor, {
155
- field: field,
156
- isInitiallyDisabled: false,
157
- locales: createFakeLocalesAPI()
158
- }));
159
- expect(getByText('0 characters')).toBeInTheDocument();
160
- expect(getByText('Requires at least 1000 characters')).toBeInTheDocument();
161
- });
162
- it('renders no validation message if withCharValidation is falsy', ()=>{
163
- const [field] = createFakeFieldAPI((field)=>{
164
- return {
165
- ...field,
166
- type: 'Symbol',
167
- validations: [
168
- {
169
- size: {
170
- min: 100,
171
- max: 1000
172
- }
173
- }
174
- ],
175
- id: 'field-id'
176
- };
177
- });
178
- const { getByText, queryByText } = render(React.createElement(SingleLineEditor, {
150
+ const { getByTestId } = render(React.createElement(SingleLineEditor, {
179
151
  field: field,
180
- withCharValidation: false,
181
152
  isInitiallyDisabled: false,
182
153
  locales: createFakeLocalesAPI()
183
154
  }));
184
- expect(getByText('0 characters')).toBeInTheDocument();
185
- expect(queryByText('Requires between 100 and 1000 characters')).not.toBeInTheDocument();
155
+ expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0');
156
+ expect(getByTestId('cf-ui-char-counter')).not.toHaveTextContent('0 / 1000');
186
157
  });
187
158
  });
@@ -1,11 +1,11 @@
1
1
  import tokens from '@contentful/f36-tokens';
2
2
  import { css } from 'emotion';
3
- export const validationRow = css({
4
- display: 'flex',
5
- justifyContent: 'space-between',
3
+ export const counterRow = css({
4
+ float: 'right',
5
+ marginLeft: tokens.spacingS,
6
6
  fontSize: tokens.fontSizeM,
7
7
  marginTop: tokens.spacingXs,
8
- color: tokens.gray700
8
+ color: tokens.gray500
9
9
  });
10
10
  export const rightToLeft = css({
11
11
  direction: 'rtl'
@@ -9,10 +9,6 @@ export interface SingleLineEditorProps {
9
9
  * is the field manually disabled
10
10
  */
11
11
  isDisabled?: boolean;
12
- /**
13
- * whether char validation should be shown or not
14
- */
15
- withCharValidation: boolean;
16
12
  /**
17
13
  * sdk.field
18
14
  */
@@ -26,6 +22,5 @@ export declare function SingleLineEditor(props: SingleLineEditorProps): JSX.Elem
26
22
  export declare namespace SingleLineEditor {
27
23
  var defaultProps: {
28
24
  isInitiallyDisabled: boolean;
29
- withCharValidation: boolean;
30
25
  };
31
26
  }
@@ -1,2 +1,2 @@
1
- export declare const validationRow: string;
1
+ export declare const counterRow: string;
2
2
  export declare const rightToLeft: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-single-line",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
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.6",
40
+ "@contentful/field-editor-shared": "^1.4.8",
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": "894934e9a2888aeb0a894cfebea3e034ba830f2a"
53
+ "gitHead": "1d7d630fe6f9576ee4cf35feed8badc8440acbf1"
54
54
  }