@contentful/field-editor-single-line 1.3.9 → 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.
- package/dist/cjs/SingleLineEditor.js +4 -8
- package/dist/cjs/SingleLineEditor.test.js +2 -29
- package/dist/cjs/styles.js +10 -10
- package/dist/esm/SingleLineEditor.js +5 -9
- package/dist/esm/SingleLineEditor.test.js +2 -29
- package/dist/esm/styles.js +7 -7
- package/dist/types/SingleLineEditor.d.ts +0 -5
- package/dist/types/styles.d.ts +1 -1
- package/package.json +3 -3
|
@@ -57,7 +57,7 @@ function isSupportedFieldTypes(val) {
|
|
|
57
57
|
return val === 'Symbol' || val === 'Text';
|
|
58
58
|
}
|
|
59
59
|
function SingleLineEditor(props) {
|
|
60
|
-
const { field, locales
|
|
60
|
+
const { field, locales } = props;
|
|
61
61
|
if (!isSupportedFieldTypes(field.type)) {
|
|
62
62
|
throw new Error(`"${field.type}" field type is not supported by SingleLineEditor`);
|
|
63
63
|
}
|
|
@@ -81,11 +81,8 @@ function SingleLineEditor(props) {
|
|
|
81
81
|
setValue(e.target.value);
|
|
82
82
|
}
|
|
83
83
|
}), _react.createElement("div", {
|
|
84
|
-
className: _styles.
|
|
85
|
-
}, _react.createElement(_fieldeditorshared.
|
|
86
|
-
constraints: constraints,
|
|
87
|
-
enabled: withCharValidation
|
|
88
|
-
}), _react.createElement(_fieldeditorshared.CharCounter, {
|
|
84
|
+
className: _styles.counterRow
|
|
85
|
+
}, _react.createElement(_fieldeditorshared.CharCounter, {
|
|
89
86
|
value: value || '',
|
|
90
87
|
checkConstraint: checkConstraint,
|
|
91
88
|
constraints: constraints
|
|
@@ -93,6 +90,5 @@ function SingleLineEditor(props) {
|
|
|
93
90
|
});
|
|
94
91
|
}
|
|
95
92
|
SingleLineEditor.defaultProps = {
|
|
96
|
-
isInitiallyDisabled: true
|
|
97
|
-
withCharValidation: true
|
|
93
|
+
isInitiallyDisabled: true
|
|
98
94
|
};
|
|
@@ -170,13 +170,12 @@ describe('SingleLineEditor', ()=>{
|
|
|
170
170
|
id: 'field-id'
|
|
171
171
|
};
|
|
172
172
|
});
|
|
173
|
-
const {
|
|
173
|
+
const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
|
|
174
174
|
field: field,
|
|
175
175
|
isInitiallyDisabled: false,
|
|
176
176
|
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
|
|
177
177
|
}));
|
|
178
178
|
expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 1000');
|
|
179
|
-
expect(getByText('Requires between 100 and 1000 characters')).toBeInTheDocument();
|
|
180
179
|
});
|
|
181
180
|
it('shows proper min validation message', ()=>{
|
|
182
181
|
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
@@ -193,38 +192,12 @@ describe('SingleLineEditor', ()=>{
|
|
|
193
192
|
id: 'field-id'
|
|
194
193
|
};
|
|
195
194
|
});
|
|
196
|
-
const {
|
|
195
|
+
const { getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
|
|
197
196
|
field: field,
|
|
198
197
|
isInitiallyDisabled: false,
|
|
199
198
|
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
|
|
200
199
|
}));
|
|
201
200
|
expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0');
|
|
202
201
|
expect(getByTestId('cf-ui-char-counter')).not.toHaveTextContent('0 / 1000');
|
|
203
|
-
expect(getByText('Requires at least 1000 characters')).toBeInTheDocument();
|
|
204
|
-
});
|
|
205
|
-
it('renders no validation message if withCharValidation is falsy', ()=>{
|
|
206
|
-
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
207
|
-
return {
|
|
208
|
-
...field,
|
|
209
|
-
type: 'Symbol',
|
|
210
|
-
validations: [
|
|
211
|
-
{
|
|
212
|
-
size: {
|
|
213
|
-
min: 100,
|
|
214
|
-
max: 1000
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
],
|
|
218
|
-
id: 'field-id'
|
|
219
|
-
};
|
|
220
|
-
});
|
|
221
|
-
const { queryByText, getByTestId } = (0, _react1.render)(_react.createElement(_SingleLineEditor.SingleLineEditor, {
|
|
222
|
-
field: field,
|
|
223
|
-
withCharValidation: false,
|
|
224
|
-
isInitiallyDisabled: false,
|
|
225
|
-
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)()
|
|
226
|
-
}));
|
|
227
|
-
expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 1000');
|
|
228
|
-
expect(queryByText('Requires between 100 and 1000 characters')).not.toBeInTheDocument();
|
|
229
202
|
});
|
|
230
203
|
});
|
package/dist/cjs/styles.js
CHANGED
|
@@ -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,13 +23,13 @@ function _interop_require_default(obj) {
|
|
|
23
23
|
default: obj
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const counterRow = (0, _emotion.css)({
|
|
27
|
+
float: 'right',
|
|
28
|
+
marginLeft: _f36tokens.default.spacingS,
|
|
29
|
+
fontSize: _f36tokens.default.fontSizeM,
|
|
30
|
+
marginTop: _f36tokens.default.spacingXs,
|
|
31
|
+
color: _f36tokens.default.gray500
|
|
32
|
+
});
|
|
33
33
|
const rightToLeft = (0, _emotion.css)({
|
|
34
34
|
direction: 'rtl'
|
|
35
35
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { TextInput } from '@contentful/f36-components';
|
|
3
|
-
import { FieldConnector, ConstraintsUtils, CharCounter
|
|
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';
|
|
7
7
|
}
|
|
8
8
|
export function SingleLineEditor(props) {
|
|
9
|
-
const { field, locales
|
|
9
|
+
const { field, locales } = props;
|
|
10
10
|
if (!isSupportedFieldTypes(field.type)) {
|
|
11
11
|
throw new Error(`"${field.type}" field type is not supported by SingleLineEditor`);
|
|
12
12
|
}
|
|
@@ -30,11 +30,8 @@ export function SingleLineEditor(props) {
|
|
|
30
30
|
setValue(e.target.value);
|
|
31
31
|
}
|
|
32
32
|
}), React.createElement("div", {
|
|
33
|
-
className: styles.
|
|
34
|
-
}, React.createElement(
|
|
35
|
-
constraints: constraints,
|
|
36
|
-
enabled: withCharValidation
|
|
37
|
-
}), React.createElement(CharCounter, {
|
|
33
|
+
className: styles.counterRow
|
|
34
|
+
}, React.createElement(CharCounter, {
|
|
38
35
|
value: value || '',
|
|
39
36
|
checkConstraint: checkConstraint,
|
|
40
37
|
constraints: constraints
|
|
@@ -42,6 +39,5 @@ export function SingleLineEditor(props) {
|
|
|
42
39
|
});
|
|
43
40
|
}
|
|
44
41
|
SingleLineEditor.defaultProps = {
|
|
45
|
-
isInitiallyDisabled: true
|
|
46
|
-
withCharValidation: true
|
|
42
|
+
isInitiallyDisabled: true
|
|
47
43
|
};
|
|
@@ -125,13 +125,12 @@ describe('SingleLineEditor', ()=>{
|
|
|
125
125
|
id: 'field-id'
|
|
126
126
|
};
|
|
127
127
|
});
|
|
128
|
-
const {
|
|
128
|
+
const { getByTestId } = render(React.createElement(SingleLineEditor, {
|
|
129
129
|
field: field,
|
|
130
130
|
isInitiallyDisabled: false,
|
|
131
131
|
locales: createFakeLocalesAPI()
|
|
132
132
|
}));
|
|
133
133
|
expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 1000');
|
|
134
|
-
expect(getByText('Requires between 100 and 1000 characters')).toBeInTheDocument();
|
|
135
134
|
});
|
|
136
135
|
it('shows proper min validation message', ()=>{
|
|
137
136
|
const [field] = createFakeFieldAPI((field)=>{
|
|
@@ -148,38 +147,12 @@ describe('SingleLineEditor', ()=>{
|
|
|
148
147
|
id: 'field-id'
|
|
149
148
|
};
|
|
150
149
|
});
|
|
151
|
-
const {
|
|
150
|
+
const { getByTestId } = render(React.createElement(SingleLineEditor, {
|
|
152
151
|
field: field,
|
|
153
152
|
isInitiallyDisabled: false,
|
|
154
153
|
locales: createFakeLocalesAPI()
|
|
155
154
|
}));
|
|
156
155
|
expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0');
|
|
157
156
|
expect(getByTestId('cf-ui-char-counter')).not.toHaveTextContent('0 / 1000');
|
|
158
|
-
expect(getByText('Requires at least 1000 characters')).toBeInTheDocument();
|
|
159
|
-
});
|
|
160
|
-
it('renders no validation message if withCharValidation is falsy', ()=>{
|
|
161
|
-
const [field] = createFakeFieldAPI((field)=>{
|
|
162
|
-
return {
|
|
163
|
-
...field,
|
|
164
|
-
type: 'Symbol',
|
|
165
|
-
validations: [
|
|
166
|
-
{
|
|
167
|
-
size: {
|
|
168
|
-
min: 100,
|
|
169
|
-
max: 1000
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
],
|
|
173
|
-
id: 'field-id'
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
const { queryByText, getByTestId } = render(React.createElement(SingleLineEditor, {
|
|
177
|
-
field: field,
|
|
178
|
-
withCharValidation: false,
|
|
179
|
-
isInitiallyDisabled: false,
|
|
180
|
-
locales: createFakeLocalesAPI()
|
|
181
|
-
}));
|
|
182
|
-
expect(getByTestId('cf-ui-char-counter')).toHaveTextContent('0 / 1000');
|
|
183
|
-
expect(queryByText('Requires between 100 and 1000 characters')).not.toBeInTheDocument();
|
|
184
157
|
});
|
|
185
158
|
});
|
package/dist/esm/styles.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import tokens from '@contentful/f36-tokens';
|
|
2
2
|
import { css } from 'emotion';
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export const counterRow = css({
|
|
4
|
+
float: 'right',
|
|
5
|
+
marginLeft: tokens.spacingS,
|
|
6
|
+
fontSize: tokens.fontSizeM,
|
|
7
|
+
marginTop: tokens.spacingXs,
|
|
8
|
+
color: tokens.gray500
|
|
9
|
+
});
|
|
10
10
|
export const rightToLeft = css({
|
|
11
11
|
direction: 'rtl'
|
|
12
12
|
});
|
|
@@ -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
|
}
|
package/dist/types/styles.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
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.
|
|
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.
|
|
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": "
|
|
53
|
+
"gitHead": "1d7d630fe6f9576ee4cf35feed8badc8440acbf1"
|
|
54
54
|
}
|