@contentful/field-editor-radio 1.2.0 → 1.3.0
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/RadioEditor.js +111 -0
- package/dist/cjs/RadioEditor.spec.js +209 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/styles.js +37 -0
- package/dist/esm/RadioEditor.js +62 -0
- package/dist/esm/RadioEditor.spec.js +166 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/styles.js +11 -0
- package/dist/{RadioEditor.d.ts → types/RadioEditor.d.ts} +22 -22
- package/dist/types/RadioEditor.spec.d.ts +1 -0
- package/dist/{index.d.ts → types/index.d.ts} +1 -1
- package/dist/{styles.d.ts → types/styles.d.ts} +3 -3
- package/package.json +26 -12
- package/CHANGELOG.md +0 -206
- package/dist/field-editor-radio.cjs.development.js +0 -87
- package/dist/field-editor-radio.cjs.development.js.map +0 -1
- package/dist/field-editor-radio.cjs.production.min.js +0 -2
- package/dist/field-editor-radio.cjs.production.min.js.map +0 -1
- package/dist/field-editor-radio.esm.js +0 -81
- package/dist/field-editor-radio.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "RadioEditor", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return RadioEditor;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _fieldeditordropdown = require("@contentful/field-editor-dropdown");
|
|
14
|
+
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
15
|
+
const _emotion = require("emotion");
|
|
16
|
+
const _styles = _interop_require_wildcard(require("./styles"));
|
|
17
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
18
|
+
if (typeof WeakMap !== "function") return null;
|
|
19
|
+
var cacheBabelInterop = new WeakMap();
|
|
20
|
+
var cacheNodeInterop = new WeakMap();
|
|
21
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
22
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
23
|
+
})(nodeInterop);
|
|
24
|
+
}
|
|
25
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
26
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
30
|
+
return {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
35
|
+
if (cache && cache.has(obj)) {
|
|
36
|
+
return cache.get(obj);
|
|
37
|
+
}
|
|
38
|
+
var newObj = {};
|
|
39
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
|
+
for(var key in obj){
|
|
41
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
43
|
+
if (desc && (desc.get || desc.set)) {
|
|
44
|
+
Object.defineProperty(newObj, key, desc);
|
|
45
|
+
} else {
|
|
46
|
+
newObj[key] = obj[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
newObj.default = obj;
|
|
51
|
+
if (cache) {
|
|
52
|
+
cache.set(obj, newObj);
|
|
53
|
+
}
|
|
54
|
+
return newObj;
|
|
55
|
+
}
|
|
56
|
+
function RadioEditor(props) {
|
|
57
|
+
const { field , locales } = props;
|
|
58
|
+
const options = (0, _fieldeditordropdown.getOptions)(field);
|
|
59
|
+
const misconfigured = options.length === 0;
|
|
60
|
+
if (misconfigured) {
|
|
61
|
+
return _react.createElement(_fieldeditorshared.PredefinedValuesError, null);
|
|
62
|
+
}
|
|
63
|
+
const direction = locales.direction[field.locale] || 'ltr';
|
|
64
|
+
return _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
65
|
+
throttle: 0,
|
|
66
|
+
field: field,
|
|
67
|
+
isInitiallyDisabled: props.isInitiallyDisabled
|
|
68
|
+
}, ({ disabled , value , setValue })=>{
|
|
69
|
+
const setOption = (value)=>{
|
|
70
|
+
setValue((0, _fieldeditordropdown.parseValue)(value, field.type));
|
|
71
|
+
};
|
|
72
|
+
const clearOption = ()=>{
|
|
73
|
+
setValue(undefined);
|
|
74
|
+
};
|
|
75
|
+
return _react.createElement(_f36components.Form, {
|
|
76
|
+
testId: "radio-editor",
|
|
77
|
+
className: (0, _emotion.cx)(_styles.form, direction === 'rtl' ? _styles.rightToLeft : '')
|
|
78
|
+
}, options.map((item, index)=>{
|
|
79
|
+
const id = [
|
|
80
|
+
'entity',
|
|
81
|
+
field.id,
|
|
82
|
+
field.locale,
|
|
83
|
+
index,
|
|
84
|
+
item.id
|
|
85
|
+
].join('.');
|
|
86
|
+
const checked = value === item.value;
|
|
87
|
+
return _react.createElement(_f36components.Flex, {
|
|
88
|
+
key: id,
|
|
89
|
+
alignItems: "center",
|
|
90
|
+
marginBottom: "spacingS"
|
|
91
|
+
}, _react.createElement(_f36components.Radio, {
|
|
92
|
+
id: id,
|
|
93
|
+
isDisabled: disabled,
|
|
94
|
+
value: item.value === undefined ? '' : String(item.value),
|
|
95
|
+
isChecked: checked,
|
|
96
|
+
onChange: (e)=>{
|
|
97
|
+
if (e.target.checked) {
|
|
98
|
+
setOption(e.target.value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, item.label), checked && !disabled && _react.createElement(_f36components.TextLink, {
|
|
102
|
+
as: "button",
|
|
103
|
+
className: _styles.clearBtn,
|
|
104
|
+
onClick: clearOption
|
|
105
|
+
}, "Clear"));
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
RadioEditor.defaultProps = {
|
|
110
|
+
isInitiallyDisabled: true
|
|
111
|
+
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
6
|
+
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
7
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
8
|
+
const _react1 = require("@testing-library/react");
|
|
9
|
+
const _RadioEditor = require("./RadioEditor");
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
11
|
+
if (typeof WeakMap !== "function") return null;
|
|
12
|
+
var cacheBabelInterop = new WeakMap();
|
|
13
|
+
var cacheNodeInterop = new WeakMap();
|
|
14
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
15
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
16
|
+
})(nodeInterop);
|
|
17
|
+
}
|
|
18
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
19
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
23
|
+
return {
|
|
24
|
+
default: obj
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
28
|
+
if (cache && cache.has(obj)) {
|
|
29
|
+
return cache.get(obj);
|
|
30
|
+
}
|
|
31
|
+
var newObj = {};
|
|
32
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
33
|
+
for(var key in obj){
|
|
34
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
35
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
36
|
+
if (desc && (desc.get || desc.set)) {
|
|
37
|
+
Object.defineProperty(newObj, key, desc);
|
|
38
|
+
} else {
|
|
39
|
+
newObj[key] = obj[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
newObj.default = obj;
|
|
44
|
+
if (cache) {
|
|
45
|
+
cache.set(obj, newObj);
|
|
46
|
+
}
|
|
47
|
+
return newObj;
|
|
48
|
+
}
|
|
49
|
+
(0, _react1.configure)({
|
|
50
|
+
testIdAttribute: 'data-test-id'
|
|
51
|
+
});
|
|
52
|
+
describe('RadioEditor', ()=>{
|
|
53
|
+
afterEach(_react1.cleanup);
|
|
54
|
+
it('renders a warning if no options are present', ()=>{
|
|
55
|
+
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((mock)=>{
|
|
56
|
+
return {
|
|
57
|
+
...mock,
|
|
58
|
+
validations: []
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
const { getByTestId , queryByTestId } = (0, _react1.render)(_react.createElement(_RadioEditor.RadioEditor, {
|
|
62
|
+
field: field,
|
|
63
|
+
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
|
|
64
|
+
isInitiallyDisabled: false
|
|
65
|
+
}));
|
|
66
|
+
expect(getByTestId('predefined-values-warning')).toBeInTheDocument();
|
|
67
|
+
expect(queryByTestId('radio-editor')).not.toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
it('renders inputs for predefined values', ()=>{
|
|
70
|
+
const predefined = [
|
|
71
|
+
'banana',
|
|
72
|
+
'orange',
|
|
73
|
+
'strawberry'
|
|
74
|
+
];
|
|
75
|
+
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((mock)=>{
|
|
76
|
+
return {
|
|
77
|
+
...mock,
|
|
78
|
+
validations: [
|
|
79
|
+
{
|
|
80
|
+
in: predefined
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const { container } = (0, _react1.render)(_react.createElement(_RadioEditor.RadioEditor, {
|
|
86
|
+
field: field,
|
|
87
|
+
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
|
|
88
|
+
isInitiallyDisabled: false
|
|
89
|
+
}));
|
|
90
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
91
|
+
expect($inputs).toHaveLength(3);
|
|
92
|
+
predefined.forEach((item, index)=>{
|
|
93
|
+
expect($inputs[index].value).toEqual(item);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('calls setValue and removeValue properly', ()=>{
|
|
97
|
+
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
98
|
+
jest.spyOn(field, 'setValue');
|
|
99
|
+
jest.spyOn(field, 'removeValue');
|
|
100
|
+
return {
|
|
101
|
+
...field,
|
|
102
|
+
validations: [
|
|
103
|
+
{
|
|
104
|
+
in: [
|
|
105
|
+
'banana',
|
|
106
|
+
'orange',
|
|
107
|
+
'strawberry'
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
const { container , queryByText , getByText } = (0, _react1.render)(_react.createElement(_RadioEditor.RadioEditor, {
|
|
114
|
+
field: field,
|
|
115
|
+
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
|
|
116
|
+
isInitiallyDisabled: false
|
|
117
|
+
}));
|
|
118
|
+
expect(queryByText('Clear')).not.toBeInTheDocument();
|
|
119
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
120
|
+
_react1.fireEvent.click($inputs[0]);
|
|
121
|
+
expect(field.setValue).toHaveBeenCalledWith('banana');
|
|
122
|
+
_react1.fireEvent.click($inputs[1]);
|
|
123
|
+
expect(field.setValue).toHaveBeenCalledWith('orange');
|
|
124
|
+
expect(field.removeValue).toHaveBeenCalledTimes(0);
|
|
125
|
+
_react1.fireEvent.click(getByText('Clear'));
|
|
126
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
127
|
+
});
|
|
128
|
+
describe('Number field', ()=>{
|
|
129
|
+
it('calls setValue and removeValue properly', function() {
|
|
130
|
+
const predefined = [
|
|
131
|
+
1,
|
|
132
|
+
'2.71',
|
|
133
|
+
'0'
|
|
134
|
+
];
|
|
135
|
+
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
136
|
+
jest.spyOn(field, 'setValue');
|
|
137
|
+
jest.spyOn(field, 'removeValue');
|
|
138
|
+
return {
|
|
139
|
+
...field,
|
|
140
|
+
type: 'Number',
|
|
141
|
+
validations: [
|
|
142
|
+
{
|
|
143
|
+
in: predefined
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
const { container , getByText } = (0, _react1.render)(_react.createElement(_RadioEditor.RadioEditor, {
|
|
149
|
+
field: field,
|
|
150
|
+
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
|
|
151
|
+
isInitiallyDisabled: false
|
|
152
|
+
}));
|
|
153
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
154
|
+
_react1.fireEvent.click($inputs[0]);
|
|
155
|
+
expect(field.setValue).toHaveBeenCalledWith(1);
|
|
156
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
157
|
+
_react1.fireEvent.click($inputs[1]);
|
|
158
|
+
expect(field.setValue).toHaveBeenCalledWith(2.71);
|
|
159
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
160
|
+
_react1.fireEvent.click($inputs[2]);
|
|
161
|
+
expect(field.setValue).toHaveBeenCalledWith(0);
|
|
162
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
163
|
+
expect(field.removeValue).toHaveBeenCalledTimes(0);
|
|
164
|
+
_react1.fireEvent.click(getByText('Clear'));
|
|
165
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('Integer field', ()=>{
|
|
169
|
+
it('calls setValue and removeValue properly', function() {
|
|
170
|
+
const predefined = [
|
|
171
|
+
0,
|
|
172
|
+
'65',
|
|
173
|
+
'99',
|
|
174
|
+
100
|
|
175
|
+
];
|
|
176
|
+
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
177
|
+
jest.spyOn(field, 'setValue');
|
|
178
|
+
jest.spyOn(field, 'removeValue');
|
|
179
|
+
return {
|
|
180
|
+
...field,
|
|
181
|
+
type: 'Number',
|
|
182
|
+
validations: [
|
|
183
|
+
{
|
|
184
|
+
in: predefined
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
const { container , getByText } = (0, _react1.render)(_react.createElement(_RadioEditor.RadioEditor, {
|
|
190
|
+
field: field,
|
|
191
|
+
locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
|
|
192
|
+
isInitiallyDisabled: false
|
|
193
|
+
}));
|
|
194
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
195
|
+
_react1.fireEvent.click($inputs[0]);
|
|
196
|
+
expect(field.setValue).toHaveBeenCalledWith(0);
|
|
197
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
198
|
+
_react1.fireEvent.click($inputs[1]);
|
|
199
|
+
expect(field.setValue).toHaveBeenCalledWith(65);
|
|
200
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
201
|
+
_react1.fireEvent.click($inputs[2]);
|
|
202
|
+
expect(field.setValue).toHaveBeenCalledWith(99);
|
|
203
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
204
|
+
expect(field.removeValue).toHaveBeenCalledTimes(0);
|
|
205
|
+
_react1.fireEvent.click(getByText('Clear'));
|
|
206
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "RadioEditor", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _RadioEditor.RadioEditor;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _RadioEditor = require("./RadioEditor");
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
form: function() {
|
|
13
|
+
return form;
|
|
14
|
+
},
|
|
15
|
+
rightToLeft: function() {
|
|
16
|
+
return rightToLeft;
|
|
17
|
+
},
|
|
18
|
+
clearBtn: function() {
|
|
19
|
+
return clearBtn;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
23
|
+
const _emotion = require("emotion");
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const form = (0, _emotion.css)({
|
|
30
|
+
marginTop: _f36tokens.default.spacingS
|
|
31
|
+
});
|
|
32
|
+
const rightToLeft = (0, _emotion.css)({
|
|
33
|
+
direction: 'rtl'
|
|
34
|
+
});
|
|
35
|
+
const clearBtn = (0, _emotion.css)({
|
|
36
|
+
marginLeft: _f36tokens.default.spacingL
|
|
37
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TextLink, Flex, Radio, Form } from '@contentful/f36-components';
|
|
3
|
+
import { getOptions, parseValue } from '@contentful/field-editor-dropdown';
|
|
4
|
+
import { FieldConnector, PredefinedValuesError } from '@contentful/field-editor-shared';
|
|
5
|
+
import { cx } from 'emotion';
|
|
6
|
+
import * as styles from './styles';
|
|
7
|
+
export function RadioEditor(props) {
|
|
8
|
+
const { field , locales } = props;
|
|
9
|
+
const options = getOptions(field);
|
|
10
|
+
const misconfigured = options.length === 0;
|
|
11
|
+
if (misconfigured) {
|
|
12
|
+
return React.createElement(PredefinedValuesError, null);
|
|
13
|
+
}
|
|
14
|
+
const direction = locales.direction[field.locale] || 'ltr';
|
|
15
|
+
return React.createElement(FieldConnector, {
|
|
16
|
+
throttle: 0,
|
|
17
|
+
field: field,
|
|
18
|
+
isInitiallyDisabled: props.isInitiallyDisabled
|
|
19
|
+
}, ({ disabled , value , setValue })=>{
|
|
20
|
+
const setOption = (value)=>{
|
|
21
|
+
setValue(parseValue(value, field.type));
|
|
22
|
+
};
|
|
23
|
+
const clearOption = ()=>{
|
|
24
|
+
setValue(undefined);
|
|
25
|
+
};
|
|
26
|
+
return React.createElement(Form, {
|
|
27
|
+
testId: "radio-editor",
|
|
28
|
+
className: cx(styles.form, direction === 'rtl' ? styles.rightToLeft : '')
|
|
29
|
+
}, options.map((item, index)=>{
|
|
30
|
+
const id = [
|
|
31
|
+
'entity',
|
|
32
|
+
field.id,
|
|
33
|
+
field.locale,
|
|
34
|
+
index,
|
|
35
|
+
item.id
|
|
36
|
+
].join('.');
|
|
37
|
+
const checked = value === item.value;
|
|
38
|
+
return React.createElement(Flex, {
|
|
39
|
+
key: id,
|
|
40
|
+
alignItems: "center",
|
|
41
|
+
marginBottom: "spacingS"
|
|
42
|
+
}, React.createElement(Radio, {
|
|
43
|
+
id: id,
|
|
44
|
+
isDisabled: disabled,
|
|
45
|
+
value: item.value === undefined ? '' : String(item.value),
|
|
46
|
+
isChecked: checked,
|
|
47
|
+
onChange: (e)=>{
|
|
48
|
+
if (e.target.checked) {
|
|
49
|
+
setOption(e.target.value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, item.label), checked && !disabled && React.createElement(TextLink, {
|
|
53
|
+
as: "button",
|
|
54
|
+
className: styles.clearBtn,
|
|
55
|
+
onClick: clearOption
|
|
56
|
+
}, "Clear"));
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
RadioEditor.defaultProps = {
|
|
61
|
+
isInitiallyDisabled: true
|
|
62
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
|
|
3
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
4
|
+
import { cleanup, configure, fireEvent, render } from '@testing-library/react';
|
|
5
|
+
import { RadioEditor } from './RadioEditor';
|
|
6
|
+
configure({
|
|
7
|
+
testIdAttribute: 'data-test-id'
|
|
8
|
+
});
|
|
9
|
+
describe('RadioEditor', ()=>{
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
it('renders a warning if no options are present', ()=>{
|
|
12
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
13
|
+
return {
|
|
14
|
+
...mock,
|
|
15
|
+
validations: []
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
const { getByTestId , queryByTestId } = render(React.createElement(RadioEditor, {
|
|
19
|
+
field: field,
|
|
20
|
+
locales: createFakeLocalesAPI(),
|
|
21
|
+
isInitiallyDisabled: false
|
|
22
|
+
}));
|
|
23
|
+
expect(getByTestId('predefined-values-warning')).toBeInTheDocument();
|
|
24
|
+
expect(queryByTestId('radio-editor')).not.toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
it('renders inputs for predefined values', ()=>{
|
|
27
|
+
const predefined = [
|
|
28
|
+
'banana',
|
|
29
|
+
'orange',
|
|
30
|
+
'strawberry'
|
|
31
|
+
];
|
|
32
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
33
|
+
return {
|
|
34
|
+
...mock,
|
|
35
|
+
validations: [
|
|
36
|
+
{
|
|
37
|
+
in: predefined
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const { container } = render(React.createElement(RadioEditor, {
|
|
43
|
+
field: field,
|
|
44
|
+
locales: createFakeLocalesAPI(),
|
|
45
|
+
isInitiallyDisabled: false
|
|
46
|
+
}));
|
|
47
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
48
|
+
expect($inputs).toHaveLength(3);
|
|
49
|
+
predefined.forEach((item, index)=>{
|
|
50
|
+
expect($inputs[index].value).toEqual(item);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('calls setValue and removeValue properly', ()=>{
|
|
54
|
+
const [field] = createFakeFieldAPI((field)=>{
|
|
55
|
+
jest.spyOn(field, 'setValue');
|
|
56
|
+
jest.spyOn(field, 'removeValue');
|
|
57
|
+
return {
|
|
58
|
+
...field,
|
|
59
|
+
validations: [
|
|
60
|
+
{
|
|
61
|
+
in: [
|
|
62
|
+
'banana',
|
|
63
|
+
'orange',
|
|
64
|
+
'strawberry'
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const { container , queryByText , getByText } = render(React.createElement(RadioEditor, {
|
|
71
|
+
field: field,
|
|
72
|
+
locales: createFakeLocalesAPI(),
|
|
73
|
+
isInitiallyDisabled: false
|
|
74
|
+
}));
|
|
75
|
+
expect(queryByText('Clear')).not.toBeInTheDocument();
|
|
76
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
77
|
+
fireEvent.click($inputs[0]);
|
|
78
|
+
expect(field.setValue).toHaveBeenCalledWith('banana');
|
|
79
|
+
fireEvent.click($inputs[1]);
|
|
80
|
+
expect(field.setValue).toHaveBeenCalledWith('orange');
|
|
81
|
+
expect(field.removeValue).toHaveBeenCalledTimes(0);
|
|
82
|
+
fireEvent.click(getByText('Clear'));
|
|
83
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
84
|
+
});
|
|
85
|
+
describe('Number field', ()=>{
|
|
86
|
+
it('calls setValue and removeValue properly', function() {
|
|
87
|
+
const predefined = [
|
|
88
|
+
1,
|
|
89
|
+
'2.71',
|
|
90
|
+
'0'
|
|
91
|
+
];
|
|
92
|
+
const [field] = createFakeFieldAPI((field)=>{
|
|
93
|
+
jest.spyOn(field, 'setValue');
|
|
94
|
+
jest.spyOn(field, 'removeValue');
|
|
95
|
+
return {
|
|
96
|
+
...field,
|
|
97
|
+
type: 'Number',
|
|
98
|
+
validations: [
|
|
99
|
+
{
|
|
100
|
+
in: predefined
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
const { container , getByText } = render(React.createElement(RadioEditor, {
|
|
106
|
+
field: field,
|
|
107
|
+
locales: createFakeLocalesAPI(),
|
|
108
|
+
isInitiallyDisabled: false
|
|
109
|
+
}));
|
|
110
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
111
|
+
fireEvent.click($inputs[0]);
|
|
112
|
+
expect(field.setValue).toHaveBeenCalledWith(1);
|
|
113
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
114
|
+
fireEvent.click($inputs[1]);
|
|
115
|
+
expect(field.setValue).toHaveBeenCalledWith(2.71);
|
|
116
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
117
|
+
fireEvent.click($inputs[2]);
|
|
118
|
+
expect(field.setValue).toHaveBeenCalledWith(0);
|
|
119
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
120
|
+
expect(field.removeValue).toHaveBeenCalledTimes(0);
|
|
121
|
+
fireEvent.click(getByText('Clear'));
|
|
122
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
describe('Integer field', ()=>{
|
|
126
|
+
it('calls setValue and removeValue properly', function() {
|
|
127
|
+
const predefined = [
|
|
128
|
+
0,
|
|
129
|
+
'65',
|
|
130
|
+
'99',
|
|
131
|
+
100
|
|
132
|
+
];
|
|
133
|
+
const [field] = createFakeFieldAPI((field)=>{
|
|
134
|
+
jest.spyOn(field, 'setValue');
|
|
135
|
+
jest.spyOn(field, 'removeValue');
|
|
136
|
+
return {
|
|
137
|
+
...field,
|
|
138
|
+
type: 'Number',
|
|
139
|
+
validations: [
|
|
140
|
+
{
|
|
141
|
+
in: predefined
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
const { container , getByText } = render(React.createElement(RadioEditor, {
|
|
147
|
+
field: field,
|
|
148
|
+
locales: createFakeLocalesAPI(),
|
|
149
|
+
isInitiallyDisabled: false
|
|
150
|
+
}));
|
|
151
|
+
const $inputs = container.querySelectorAll('input[type="radio"]');
|
|
152
|
+
fireEvent.click($inputs[0]);
|
|
153
|
+
expect(field.setValue).toHaveBeenCalledWith(0);
|
|
154
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
155
|
+
fireEvent.click($inputs[1]);
|
|
156
|
+
expect(field.setValue).toHaveBeenCalledWith(65);
|
|
157
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
158
|
+
fireEvent.click($inputs[2]);
|
|
159
|
+
expect(field.setValue).toHaveBeenCalledWith(99);
|
|
160
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
161
|
+
expect(field.removeValue).toHaveBeenCalledTimes(0);
|
|
162
|
+
fireEvent.click(getByText('Clear'));
|
|
163
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RadioEditor } from './RadioEditor';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import tokens from '@contentful/f36-tokens';
|
|
2
|
+
import { css } from 'emotion';
|
|
3
|
+
export const form = css({
|
|
4
|
+
marginTop: tokens.spacingS
|
|
5
|
+
});
|
|
6
|
+
export const rightToLeft = css({
|
|
7
|
+
direction: 'rtl'
|
|
8
|
+
});
|
|
9
|
+
export const clearBtn = css({
|
|
10
|
+
marginLeft: tokens.spacingL
|
|
11
|
+
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { FieldAPI, LocalesAPI } from '@contentful/field-editor-shared';
|
|
3
|
-
export interface RadioEditorProps {
|
|
4
|
-
/**
|
|
5
|
-
* is the field disabled initially
|
|
6
|
-
*/
|
|
7
|
-
isInitiallyDisabled: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* sdk.field
|
|
10
|
-
*/
|
|
11
|
-
field: FieldAPI;
|
|
12
|
-
/**
|
|
13
|
-
* sdk.locales
|
|
14
|
-
*/
|
|
15
|
-
locales: LocalesAPI;
|
|
16
|
-
}
|
|
17
|
-
export declare function RadioEditor(props: RadioEditorProps): JSX.Element;
|
|
18
|
-
export declare namespace RadioEditor {
|
|
19
|
-
var defaultProps: {
|
|
20
|
-
isInitiallyDisabled: boolean;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { FieldAPI, LocalesAPI } from '@contentful/field-editor-shared';
|
|
3
|
+
export interface RadioEditorProps {
|
|
4
|
+
/**
|
|
5
|
+
* is the field disabled initially
|
|
6
|
+
*/
|
|
7
|
+
isInitiallyDisabled: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* sdk.field
|
|
10
|
+
*/
|
|
11
|
+
field: FieldAPI;
|
|
12
|
+
/**
|
|
13
|
+
* sdk.locales
|
|
14
|
+
*/
|
|
15
|
+
locales: LocalesAPI;
|
|
16
|
+
}
|
|
17
|
+
export declare function RadioEditor(props: RadioEditorProps): React.JSX.Element;
|
|
18
|
+
export declare namespace RadioEditor {
|
|
19
|
+
var defaultProps: {
|
|
20
|
+
isInitiallyDisabled: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RadioEditor } from './RadioEditor';
|
|
1
|
+
export { RadioEditor } from './RadioEditor';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const form: string;
|
|
2
|
-
export declare const rightToLeft: string;
|
|
3
|
-
export declare const clearBtn: string;
|
|
1
|
+
export declare const form: string;
|
|
2
|
+
export declare const rightToLeft: string;
|
|
3
|
+
export declare const clearBtn: string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-radio",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/
|
|
6
|
-
"
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"require": "./dist/cjs/index.js",
|
|
11
|
+
"default": "./dist/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist"
|
|
9
17
|
],
|
|
@@ -14,28 +22,34 @@
|
|
|
14
22
|
"url": "https://github.com/contentful/field-editors"
|
|
15
23
|
},
|
|
16
24
|
"scripts": {
|
|
17
|
-
"watch": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
25
|
+
"watch": "yarn concurrently \"yarn:watch:*\"",
|
|
26
|
+
"watch:cjs": "yarn build:cjs -w",
|
|
27
|
+
"watch:esm": "yarn build:esm -w",
|
|
28
|
+
"watch:types": "yarn build:types --watch",
|
|
29
|
+
"build": "yarn build:types && yarn build:cjs && yarn build:esm",
|
|
30
|
+
"build:types": "tsc --outDir dist/types --emitDeclarationOnly",
|
|
31
|
+
"build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
|
|
32
|
+
"build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
|
|
33
|
+
"test": "jest --watch",
|
|
34
|
+
"test:ci": "jest --ci",
|
|
21
35
|
"tsc": "tsc -p ./ --noEmit"
|
|
22
36
|
},
|
|
23
37
|
"dependencies": {
|
|
24
38
|
"@contentful/f36-components": "^4.0.27",
|
|
25
39
|
"@contentful/f36-tokens": "^4.0.0",
|
|
26
|
-
"@contentful/field-editor-dropdown": "^1.
|
|
27
|
-
"@contentful/field-editor-shared": "^1.
|
|
40
|
+
"@contentful/field-editor-dropdown": "^1.3.0",
|
|
41
|
+
"@contentful/field-editor-shared": "^1.3.0",
|
|
28
42
|
"emotion": "^10.0.17",
|
|
29
43
|
"lodash": "^4.17.15",
|
|
30
44
|
"lodash-es": "^4.17.15",
|
|
31
45
|
"nanoid": "^3.1.3"
|
|
32
46
|
},
|
|
33
47
|
"devDependencies": {
|
|
34
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
48
|
+
"@contentful/field-editor-test-utils": "^1.4.0",
|
|
35
49
|
"contentful-management": "^10.0.0"
|
|
36
50
|
},
|
|
37
51
|
"peerDependencies": {
|
|
38
52
|
"react": ">=16.8.0"
|
|
39
53
|
},
|
|
40
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
|
|
41
55
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [1.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.12...@contentful/field-editor-radio@1.2.0) (2023-04-19)
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
- upgrade cypress [TOL-1036] ([#1391](https://github.com/contentful/field-editors/issues/1391)) ([9c1aec9](https://github.com/contentful/field-editors/commit/9c1aec98aabbe464cdc3f1236c3bb1cc29b8208d))
|
|
11
|
-
|
|
12
|
-
## [1.1.12](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.11...@contentful/field-editor-radio@1.1.12) (2023-03-14)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
15
|
-
|
|
16
|
-
## [1.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.10...@contentful/field-editor-radio@1.1.11) (2023-03-10)
|
|
17
|
-
|
|
18
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
19
|
-
|
|
20
|
-
## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.9...@contentful/field-editor-radio@1.1.10) (2023-02-21)
|
|
21
|
-
|
|
22
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
23
|
-
|
|
24
|
-
## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.8...@contentful/field-editor-radio@1.1.9) (2023-02-07)
|
|
25
|
-
|
|
26
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
27
|
-
|
|
28
|
-
## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.7...@contentful/field-editor-radio@1.1.8) (2022-12-08)
|
|
29
|
-
|
|
30
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
31
|
-
|
|
32
|
-
## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.6...@contentful/field-editor-radio@1.1.7) (2022-07-29)
|
|
33
|
-
|
|
34
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
35
|
-
|
|
36
|
-
## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.5...@contentful/field-editor-radio@1.1.6) (2022-07-29)
|
|
37
|
-
|
|
38
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
39
|
-
|
|
40
|
-
## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.4...@contentful/field-editor-radio@1.1.5) (2022-07-11)
|
|
41
|
-
|
|
42
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
43
|
-
|
|
44
|
-
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.3...@contentful/field-editor-radio@1.1.4) (2022-06-22)
|
|
45
|
-
|
|
46
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
47
|
-
|
|
48
|
-
## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.2...@contentful/field-editor-radio@1.1.3) (2022-05-04)
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
- reflect disabled state on fields ([#1125](https://github.com/contentful/field-editors/issues/1125)) ([01502b9](https://github.com/contentful/field-editors/commit/01502b9d785c5f782b0e5de782d092c439cb690f))
|
|
53
|
-
|
|
54
|
-
## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.1...@contentful/field-editor-radio@1.1.2) (2022-02-15)
|
|
55
|
-
|
|
56
|
-
### Bug Fixes
|
|
57
|
-
|
|
58
|
-
- bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
|
|
59
|
-
|
|
60
|
-
## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.1.0...@contentful/field-editor-radio@1.1.1) (2022-02-14)
|
|
61
|
-
|
|
62
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
63
|
-
|
|
64
|
-
# [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.0.3...@contentful/field-editor-radio@1.1.0) (2022-01-11)
|
|
65
|
-
|
|
66
|
-
### Features
|
|
67
|
-
|
|
68
|
-
- bump f36 packages to stable v4 [BAU-521] ([#988](https://github.com/contentful/field-editors/issues/988)) ([419cf56](https://github.com/contentful/field-editors/commit/419cf56692179b074fcfa2743469d5265ed98429))
|
|
69
|
-
|
|
70
|
-
## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.0.2...@contentful/field-editor-radio@1.0.3) (2021-12-23)
|
|
71
|
-
|
|
72
|
-
### Bug Fixes
|
|
73
|
-
|
|
74
|
-
- markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
|
|
75
|
-
|
|
76
|
-
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.0.1...@contentful/field-editor-radio@1.0.2) (2021-12-20)
|
|
77
|
-
|
|
78
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
79
|
-
|
|
80
|
-
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@1.0.0...@contentful/field-editor-radio@1.0.1) (2021-11-17)
|
|
81
|
-
|
|
82
|
-
### Bug Fixes
|
|
83
|
-
|
|
84
|
-
- **card-actions:** update forma 36 to fix card actions click issue ([#927](https://github.com/contentful/field-editors/issues/927)) ([3dfdef2](https://github.com/contentful/field-editors/commit/3dfdef2c2b0045f12ea94ddafca89a8e9f25e7d0))
|
|
85
|
-
|
|
86
|
-
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.15.0...@contentful/field-editor-radio@1.0.0) (2021-11-04)
|
|
87
|
-
|
|
88
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
89
|
-
|
|
90
|
-
# [0.15.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.14.1...@contentful/field-editor-radio@0.15.0) (2021-11-04)
|
|
91
|
-
|
|
92
|
-
### Features
|
|
93
|
-
|
|
94
|
-
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
95
|
-
|
|
96
|
-
### BREAKING CHANGES
|
|
97
|
-
|
|
98
|
-
- adopts a new Forma v4 beta
|
|
99
|
-
|
|
100
|
-
## [0.14.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.14.0...@contentful/field-editor-radio@0.14.1) (2021-10-14)
|
|
101
|
-
|
|
102
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
103
|
-
|
|
104
|
-
# [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.13.4...@contentful/field-editor-radio@0.14.0) (2021-10-06)
|
|
105
|
-
|
|
106
|
-
### Features
|
|
107
|
-
|
|
108
|
-
- [EXT-3161] bump app sdk to v4 ([#881](https://github.com/contentful/field-editors/issues/881)) ([9c4a2af](https://github.com/contentful/field-editors/commit/9c4a2af07da203d59fb5f15c3a5188ecc64b1d44))
|
|
109
|
-
|
|
110
|
-
## [0.13.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.13.3...@contentful/field-editor-radio@0.13.4) (2021-09-17)
|
|
111
|
-
|
|
112
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
113
|
-
|
|
114
|
-
## [0.13.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.13.2...@contentful/field-editor-radio@0.13.3) (2021-09-16)
|
|
115
|
-
|
|
116
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
117
|
-
|
|
118
|
-
## [0.13.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.13.1...@contentful/field-editor-radio@0.13.2) (2021-08-19)
|
|
119
|
-
|
|
120
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
121
|
-
|
|
122
|
-
## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.13.0...@contentful/field-editor-radio@0.13.1) (2021-07-29)
|
|
123
|
-
|
|
124
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
125
|
-
|
|
126
|
-
# [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.6...@contentful/field-editor-radio@0.13.0) (2021-07-23)
|
|
127
|
-
|
|
128
|
-
### Features
|
|
129
|
-
|
|
130
|
-
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
131
|
-
|
|
132
|
-
## [0.12.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.3...@contentful/field-editor-radio@0.12.6) (2021-07-06)
|
|
133
|
-
|
|
134
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
135
|
-
|
|
136
|
-
## [0.12.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.3...@contentful/field-editor-radio@0.12.5) (2021-07-06)
|
|
137
|
-
|
|
138
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
139
|
-
|
|
140
|
-
## [0.12.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.3...@contentful/field-editor-radio@0.12.4) (2021-06-23)
|
|
141
|
-
|
|
142
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
143
|
-
|
|
144
|
-
## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.2...@contentful/field-editor-radio@0.12.3) (2021-06-23)
|
|
145
|
-
|
|
146
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
147
|
-
|
|
148
|
-
## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.1...@contentful/field-editor-radio@0.12.2) (2021-06-22)
|
|
149
|
-
|
|
150
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
151
|
-
|
|
152
|
-
## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.12.0...@contentful/field-editor-radio@0.12.1) (2021-03-05)
|
|
153
|
-
|
|
154
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
155
|
-
|
|
156
|
-
# [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.11.1...@contentful/field-editor-radio@0.12.0) (2021-02-19)
|
|
157
|
-
|
|
158
|
-
### Features
|
|
159
|
-
|
|
160
|
-
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
161
|
-
|
|
162
|
-
## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.11.1...@contentful/field-editor-radio@0.11.2) (2021-02-09)
|
|
163
|
-
|
|
164
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
165
|
-
|
|
166
|
-
## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.11.0...@contentful/field-editor-radio@0.11.1) (2021-02-01)
|
|
167
|
-
|
|
168
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
169
|
-
|
|
170
|
-
# [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.10.1...@contentful/field-editor-radio@0.11.0) (2021-01-20)
|
|
171
|
-
|
|
172
|
-
### Features
|
|
173
|
-
|
|
174
|
-
- update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
|
|
175
|
-
|
|
176
|
-
## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.10.0...@contentful/field-editor-radio@0.10.1) (2021-01-15)
|
|
177
|
-
|
|
178
|
-
### Bug Fixes
|
|
179
|
-
|
|
180
|
-
- 🐛 small layout adjustments ([#555](https://github.com/contentful/field-editors/issues/555)) ([235c594](https://github.com/contentful/field-editors/commit/235c5941db152d2921a9ef134c1a71b0069a4dc2))
|
|
181
|
-
|
|
182
|
-
# [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.9.5...@contentful/field-editor-radio@0.10.0) (2021-01-12)
|
|
183
|
-
|
|
184
|
-
### Features
|
|
185
|
-
|
|
186
|
-
- update minimal required Forma version to the 3.73.12 ([#552](https://github.com/contentful/field-editors/issues/552)) ([2816fd9](https://github.com/contentful/field-editors/commit/2816fd960c28815faebf49a9ef8f4c4c0d91fc36))
|
|
187
|
-
|
|
188
|
-
## [0.9.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.9.4...@contentful/field-editor-radio@0.9.5) (2020-12-16)
|
|
189
|
-
|
|
190
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
191
|
-
|
|
192
|
-
## [0.9.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.9.3...@contentful/field-editor-radio@0.9.4) (2020-11-06)
|
|
193
|
-
|
|
194
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
195
|
-
|
|
196
|
-
## [0.9.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.9.2...@contentful/field-editor-radio@0.9.3) (2020-11-06)
|
|
197
|
-
|
|
198
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
199
|
-
|
|
200
|
-
## [0.9.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.9.1...@contentful/field-editor-radio@0.9.2) (2020-10-28)
|
|
201
|
-
|
|
202
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
203
|
-
|
|
204
|
-
## [0.9.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-radio@0.9.0...@contentful/field-editor-radio@0.9.1) (2020-08-24)
|
|
205
|
-
|
|
206
|
-
**Note:** Version bump only for package @contentful/field-editor-radio
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var f36Components = require('@contentful/f36-components');
|
|
9
|
-
var fieldEditorDropdown = require('@contentful/field-editor-dropdown');
|
|
10
|
-
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
11
|
-
var emotion = require('emotion');
|
|
12
|
-
var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
13
|
-
|
|
14
|
-
const form = /*#__PURE__*/emotion.css({
|
|
15
|
-
marginTop: tokens.spacingS
|
|
16
|
-
});
|
|
17
|
-
const rightToLeft = /*#__PURE__*/emotion.css({
|
|
18
|
-
direction: 'rtl'
|
|
19
|
-
});
|
|
20
|
-
const clearBtn = /*#__PURE__*/emotion.css({
|
|
21
|
-
marginLeft: tokens.spacingL
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
function RadioEditor(props) {
|
|
25
|
-
const {
|
|
26
|
-
field,
|
|
27
|
-
locales
|
|
28
|
-
} = props;
|
|
29
|
-
const options = fieldEditorDropdown.getOptions(field);
|
|
30
|
-
const misconfigured = options.length === 0;
|
|
31
|
-
|
|
32
|
-
if (misconfigured) {
|
|
33
|
-
return React.createElement(fieldEditorShared.PredefinedValuesError, null);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const direction = locales.direction[field.locale] || 'ltr';
|
|
37
|
-
return React.createElement(fieldEditorShared.FieldConnector, {
|
|
38
|
-
throttle: 0,
|
|
39
|
-
field: field,
|
|
40
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
41
|
-
}, ({
|
|
42
|
-
disabled,
|
|
43
|
-
value,
|
|
44
|
-
setValue
|
|
45
|
-
}) => {
|
|
46
|
-
const setOption = value => {
|
|
47
|
-
setValue(fieldEditorDropdown.parseValue(value, field.type));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const clearOption = () => {
|
|
51
|
-
setValue(undefined);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return React.createElement(f36Components.Form, {
|
|
55
|
-
testId: "radio-editor",
|
|
56
|
-
className: emotion.cx(form, direction === 'rtl' ? rightToLeft : '')
|
|
57
|
-
}, options.map((item, index) => {
|
|
58
|
-
const id = ['entity', field.id, field.locale, index, item.id].join('.');
|
|
59
|
-
const checked = value === item.value;
|
|
60
|
-
return React.createElement(f36Components.Flex, {
|
|
61
|
-
key: id,
|
|
62
|
-
alignItems: "center",
|
|
63
|
-
marginBottom: "spacingS"
|
|
64
|
-
}, React.createElement(f36Components.Radio, {
|
|
65
|
-
id: id,
|
|
66
|
-
isDisabled: disabled,
|
|
67
|
-
value: item.value === undefined ? '' : String(item.value),
|
|
68
|
-
isChecked: checked,
|
|
69
|
-
onChange: e => {
|
|
70
|
-
if (e.target.checked) {
|
|
71
|
-
setOption(e.target.value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}, item.label), checked && !disabled && React.createElement(f36Components.TextLink, {
|
|
75
|
-
as: "button",
|
|
76
|
-
className: clearBtn,
|
|
77
|
-
onClick: clearOption
|
|
78
|
-
}, "Clear"));
|
|
79
|
-
}));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
RadioEditor.defaultProps = {
|
|
83
|
-
isInitiallyDisabled: true
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
exports.RadioEditor = RadioEditor;
|
|
87
|
-
//# sourceMappingURL=field-editor-radio.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-radio.cjs.development.js","sources":["../src/styles.ts","../src/RadioEditor.tsx"],"sourcesContent":["import tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport const form = css({\n marginTop: tokens.spacingS,\n});\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n\nexport const clearBtn = css({ marginLeft: tokens.spacingL });\n","import * as React from 'react';\n\nimport { TextLink, Flex, Radio, Form } from '@contentful/f36-components';\nimport { getOptions, parseValue } from '@contentful/field-editor-dropdown';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { cx } from 'emotion';\n\nimport * as styles from './styles';\n\n\nexport interface RadioEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function RadioEditor(props: RadioEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const setOption = (value: string) => {\n setValue(parseValue(value, field.type));\n };\n const clearOption = () => {\n setValue(undefined);\n };\n\n return (\n <Form\n testId=\"radio-editor\"\n className={cx(styles.form, direction === 'rtl' ? styles.rightToLeft : '')}>\n {options.map((item, index) => {\n const id = ['entity', field.id, field.locale, index, item.id].join('.');\n const checked = value === item.value;\n return (\n <Flex key={id} alignItems=\"center\" marginBottom=\"spacingS\">\n <Radio\n id={id}\n isDisabled={disabled}\n value={item.value === undefined ? '' : String(item.value)}\n isChecked={checked}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n if (e.target.checked) {\n setOption(e.target.value);\n }\n }}>\n {item.label}\n </Radio>\n {checked && !disabled && (\n <TextLink as=\"button\" className={styles.clearBtn} onClick={clearOption}>\n Clear\n </TextLink>\n )}\n </Flex>\n );\n })}\n </Form>\n );\n }}\n </FieldConnector>\n );\n}\n\nRadioEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["form","css","marginTop","tokens","spacingS","rightToLeft","direction","clearBtn","marginLeft","spacingL","RadioEditor","props","field","locales","options","getOptions","misconfigured","length","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","disabled","value","setValue","setOption","parseValue","type","clearOption","undefined","Form","testId","className","cx","styles","map","item","index","id","join","checked","Flex","key","alignItems","marginBottom","Radio","isDisabled","String","isChecked","onChange","e","target","label","TextLink","as","onClick","defaultProps"],"mappings":"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"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),i=require("@contentful/f36-components"),r=require("@contentful/field-editor-dropdown"),l=require("@contentful/field-editor-shared"),n=require("emotion"),a=(e=require("@contentful/f36-tokens"))&&"object"==typeof e&&"default"in e?e.default:e;const o=n.css({marginTop:a.spacingS}),s=n.css({direction:"rtl"}),c=n.css({marginLeft:a.spacingL});function d(e){const{field:a,locales:d}=e,u=r.getOptions(a);if(0===u.length)return t.createElement(l.PredefinedValuesError,null);const f=d.direction[a.locale]||"ltr";return t.createElement(l.FieldConnector,{throttle:0,field:a,isInitiallyDisabled:e.isInitiallyDisabled},({disabled:e,value:l,setValue:d})=>{const m=()=>{d(void 0)};return t.createElement(i.Form,{testId:"radio-editor",className:n.cx(o,"rtl"===f?s:"")},u.map((n,o)=>{const s=["entity",a.id,a.locale,o,n.id].join("."),u=l===n.value;return t.createElement(i.Flex,{key:s,alignItems:"center",marginBottom:"spacingS"},t.createElement(i.Radio,{id:s,isDisabled:e,value:void 0===n.value?"":String(n.value),isChecked:u,onChange:e=>{e.target.checked&&(e=>{d(r.parseValue(e,a.type))})(e.target.value)}},n.label),u&&!e&&t.createElement(i.TextLink,{as:"button",className:c,onClick:m},"Clear"))}))})}d.defaultProps={isInitiallyDisabled:!0},exports.RadioEditor=d;
|
|
2
|
-
//# sourceMappingURL=field-editor-radio.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-radio.cjs.production.min.js","sources":["../src/styles.ts","../src/RadioEditor.tsx"],"sourcesContent":["import tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport const form = css({\n marginTop: tokens.spacingS,\n});\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n\nexport const clearBtn = css({ marginLeft: tokens.spacingL });\n","import * as React from 'react';\n\nimport { TextLink, Flex, Radio, Form } from '@contentful/f36-components';\nimport { getOptions, parseValue } from '@contentful/field-editor-dropdown';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { cx } from 'emotion';\n\nimport * as styles from './styles';\n\n\nexport interface RadioEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function RadioEditor(props: RadioEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const setOption = (value: string) => {\n setValue(parseValue(value, field.type));\n };\n const clearOption = () => {\n setValue(undefined);\n };\n\n return (\n <Form\n testId=\"radio-editor\"\n className={cx(styles.form, direction === 'rtl' ? styles.rightToLeft : '')}>\n {options.map((item, index) => {\n const id = ['entity', field.id, field.locale, index, item.id].join('.');\n const checked = value === item.value;\n return (\n <Flex key={id} alignItems=\"center\" marginBottom=\"spacingS\">\n <Radio\n id={id}\n isDisabled={disabled}\n value={item.value === undefined ? '' : String(item.value)}\n isChecked={checked}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n if (e.target.checked) {\n setOption(e.target.value);\n }\n }}>\n {item.label}\n </Radio>\n {checked && !disabled && (\n <TextLink as=\"button\" className={styles.clearBtn} onClick={clearOption}>\n Clear\n </TextLink>\n )}\n </Flex>\n );\n })}\n </Form>\n );\n }}\n </FieldConnector>\n );\n}\n\nRadioEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["form","css","marginTop","tokens","spacingS","rightToLeft","direction","clearBtn","marginLeft","spacingL","RadioEditor","props","field","locales","options","getOptions","length","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","disabled","value","setValue","clearOption","undefined","Form","testId","className","cx","styles","map","item","index","id","join","checked","Flex","key","alignItems","marginBottom","Radio","isDisabled","String","isChecked","onChange","e","target","parseValue","type","setOption","label","TextLink","as","onClick","defaultProps"],"mappings":"6UAGO,MAAMA,EAAOC,MAAI,CACtBC,UAAWC,EAAOC,WAGPC,EAAcJ,MAAI,CAC7BK,UAAW,QAGAC,EAAWN,MAAI,CAAEO,WAAYL,EAAOM,oBCqBjCC,EAAYC,SACpBC,MAAEA,EAAFC,QAASA,GAAYF,EAErBG,EAAUC,aAAWH,MACc,IAAnBE,EAAQE,cAGrBC,gBAACC,oCAGJZ,EAAYO,EAAQP,UAAUM,EAAMO,SAAW,aAGnDF,gBAACG,kBACCC,SAAU,EACVT,MAAOA,EACPU,oBAAqBX,EAAMW,qBAC1B,EAAGC,SAAAA,EAAUC,MAAAA,EAAOC,SAAAA,YAIbC,EAAc,KAClBD,OAASE,WAITV,gBAACW,QACCC,OAAO,eACPC,UAAWC,KAAGC,EAA2B,QAAd1B,EAAsB0B,EAAqB,KACrElB,EAAQmB,IAAI,CAACC,EAAMC,WACZC,EAAK,CAAC,SAAUxB,EAAMwB,GAAIxB,EAAMO,OAAQgB,EAAOD,EAAKE,IAAIC,KAAK,KAC7DC,EAAUd,IAAUU,EAAKV,aAE7BP,gBAACsB,QAAKC,IAAKJ,EAAIK,WAAW,SAASC,aAAa,YAC9CzB,gBAAC0B,SACCP,GAAIA,EACJQ,WAAYrB,EACZC,WAAsBG,IAAfO,EAAKV,MAAsB,GAAKqB,OAAOX,EAAKV,OACnDsB,UAAWR,EACXS,SAAWC,IACLA,EAAEC,OAAOX,SAtBRd,CAAAA,IACjBC,EAASyB,aAAW1B,EAAOZ,EAAMuC,QAsBnBC,CAAUJ,EAAEC,OAAOzB,SAGtBU,EAAKmB,OAEPf,IAAYf,GACXN,gBAACqC,YAASC,GAAG,SAASzB,UAAWE,EAAiBwB,QAAS9B,kBAc/EhB,EAAY+C,aAAe,CACzBnC,qBAAqB"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
import { Form, Flex, Radio, TextLink } from '@contentful/f36-components';
|
|
3
|
-
import { getOptions, parseValue } from '@contentful/field-editor-dropdown';
|
|
4
|
-
import { PredefinedValuesError, FieldConnector } from '@contentful/field-editor-shared';
|
|
5
|
-
import { css, cx } from 'emotion';
|
|
6
|
-
import tokens from '@contentful/f36-tokens';
|
|
7
|
-
|
|
8
|
-
const form = /*#__PURE__*/css({
|
|
9
|
-
marginTop: tokens.spacingS
|
|
10
|
-
});
|
|
11
|
-
const rightToLeft = /*#__PURE__*/css({
|
|
12
|
-
direction: 'rtl'
|
|
13
|
-
});
|
|
14
|
-
const clearBtn = /*#__PURE__*/css({
|
|
15
|
-
marginLeft: tokens.spacingL
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
function RadioEditor(props) {
|
|
19
|
-
const {
|
|
20
|
-
field,
|
|
21
|
-
locales
|
|
22
|
-
} = props;
|
|
23
|
-
const options = getOptions(field);
|
|
24
|
-
const misconfigured = options.length === 0;
|
|
25
|
-
|
|
26
|
-
if (misconfigured) {
|
|
27
|
-
return createElement(PredefinedValuesError, null);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const direction = locales.direction[field.locale] || 'ltr';
|
|
31
|
-
return createElement(FieldConnector, {
|
|
32
|
-
throttle: 0,
|
|
33
|
-
field: field,
|
|
34
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
35
|
-
}, ({
|
|
36
|
-
disabled,
|
|
37
|
-
value,
|
|
38
|
-
setValue
|
|
39
|
-
}) => {
|
|
40
|
-
const setOption = value => {
|
|
41
|
-
setValue(parseValue(value, field.type));
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const clearOption = () => {
|
|
45
|
-
setValue(undefined);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return createElement(Form, {
|
|
49
|
-
testId: "radio-editor",
|
|
50
|
-
className: cx(form, direction === 'rtl' ? rightToLeft : '')
|
|
51
|
-
}, options.map((item, index) => {
|
|
52
|
-
const id = ['entity', field.id, field.locale, index, item.id].join('.');
|
|
53
|
-
const checked = value === item.value;
|
|
54
|
-
return createElement(Flex, {
|
|
55
|
-
key: id,
|
|
56
|
-
alignItems: "center",
|
|
57
|
-
marginBottom: "spacingS"
|
|
58
|
-
}, createElement(Radio, {
|
|
59
|
-
id: id,
|
|
60
|
-
isDisabled: disabled,
|
|
61
|
-
value: item.value === undefined ? '' : String(item.value),
|
|
62
|
-
isChecked: checked,
|
|
63
|
-
onChange: e => {
|
|
64
|
-
if (e.target.checked) {
|
|
65
|
-
setOption(e.target.value);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, item.label), checked && !disabled && createElement(TextLink, {
|
|
69
|
-
as: "button",
|
|
70
|
-
className: clearBtn,
|
|
71
|
-
onClick: clearOption
|
|
72
|
-
}, "Clear"));
|
|
73
|
-
}));
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
RadioEditor.defaultProps = {
|
|
77
|
-
isInitiallyDisabled: true
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export { RadioEditor };
|
|
81
|
-
//# sourceMappingURL=field-editor-radio.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-radio.esm.js","sources":["../src/styles.ts","../src/RadioEditor.tsx"],"sourcesContent":["import tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport const form = css({\n marginTop: tokens.spacingS,\n});\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n\nexport const clearBtn = css({ marginLeft: tokens.spacingL });\n","import * as React from 'react';\n\nimport { TextLink, Flex, Radio, Form } from '@contentful/f36-components';\nimport { getOptions, parseValue } from '@contentful/field-editor-dropdown';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { cx } from 'emotion';\n\nimport * as styles from './styles';\n\n\nexport interface RadioEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function RadioEditor(props: RadioEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const setOption = (value: string) => {\n setValue(parseValue(value, field.type));\n };\n const clearOption = () => {\n setValue(undefined);\n };\n\n return (\n <Form\n testId=\"radio-editor\"\n className={cx(styles.form, direction === 'rtl' ? styles.rightToLeft : '')}>\n {options.map((item, index) => {\n const id = ['entity', field.id, field.locale, index, item.id].join('.');\n const checked = value === item.value;\n return (\n <Flex key={id} alignItems=\"center\" marginBottom=\"spacingS\">\n <Radio\n id={id}\n isDisabled={disabled}\n value={item.value === undefined ? '' : String(item.value)}\n isChecked={checked}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n if (e.target.checked) {\n setOption(e.target.value);\n }\n }}>\n {item.label}\n </Radio>\n {checked && !disabled && (\n <TextLink as=\"button\" className={styles.clearBtn} onClick={clearOption}>\n Clear\n </TextLink>\n )}\n </Flex>\n );\n })}\n </Form>\n );\n }}\n </FieldConnector>\n );\n}\n\nRadioEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["form","css","marginTop","tokens","spacingS","rightToLeft","direction","clearBtn","marginLeft","spacingL","RadioEditor","props","field","locales","options","getOptions","misconfigured","length","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","disabled","value","setValue","setOption","parseValue","type","clearOption","undefined","Form","testId","className","cx","styles","map","item","index","id","join","checked","Flex","key","alignItems","marginBottom","Radio","isDisabled","String","isChecked","onChange","e","target","label","TextLink","as","onClick","defaultProps"],"mappings":"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"}
|