@contentful/field-editor-checkbox 1.1.12 → 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/CheckboxEditor.js +164 -0
- package/dist/cjs/CheckboxEditor.spec.js +219 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/styles.js +44 -0
- package/dist/esm/CheckboxEditor.js +112 -0
- package/dist/esm/CheckboxEditor.spec.js +176 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/styles.js +15 -0
- package/dist/{CheckboxEditor.d.ts → types/CheckboxEditor.d.ts} +22 -22
- package/dist/types/CheckboxEditor.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} +4 -4
- package/package.json +25 -11
- package/CHANGELOG.md +0 -198
- package/dist/field-editor-checkbox.cjs.development.js +0 -151
- package/dist/field-editor-checkbox.cjs.development.js.map +0 -1
- package/dist/field-editor-checkbox.cjs.production.min.js +0 -2
- package/dist/field-editor-checkbox.cjs.production.min.js.map +0 -1
- package/dist/field-editor-checkbox.esm.js +0 -145
- package/dist/field-editor-checkbox.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,176 @@
|
|
|
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 { CheckboxEditor } from './CheckboxEditor';
|
|
6
|
+
configure({
|
|
7
|
+
testIdAttribute: 'data-test-id'
|
|
8
|
+
});
|
|
9
|
+
describe('CheckboxEditor', ()=>{
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
it('renders a warning if no options are present', ()=>{
|
|
12
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
13
|
+
return {
|
|
14
|
+
...mock,
|
|
15
|
+
items: {
|
|
16
|
+
type: '',
|
|
17
|
+
validations: []
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
const { getByTestId , queryByTestId } = render(React.createElement(CheckboxEditor, {
|
|
22
|
+
field: field,
|
|
23
|
+
locales: createFakeLocalesAPI(),
|
|
24
|
+
isInitiallyDisabled: false
|
|
25
|
+
}));
|
|
26
|
+
expect(getByTestId('predefined-values-warning')).toBeInTheDocument();
|
|
27
|
+
expect(queryByTestId('dropdown-editor')).not.toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
it('renders checkboxes for predefined values', ()=>{
|
|
30
|
+
const predefined = [
|
|
31
|
+
'banana',
|
|
32
|
+
'orange',
|
|
33
|
+
'strawberry'
|
|
34
|
+
];
|
|
35
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
36
|
+
return {
|
|
37
|
+
...mock,
|
|
38
|
+
items: {
|
|
39
|
+
type: '',
|
|
40
|
+
validations: [
|
|
41
|
+
{
|
|
42
|
+
in: predefined
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
const { container } = render(React.createElement(CheckboxEditor, {
|
|
49
|
+
field: field,
|
|
50
|
+
locales: createFakeLocalesAPI(),
|
|
51
|
+
isInitiallyDisabled: false
|
|
52
|
+
}));
|
|
53
|
+
const $inputs = container.querySelectorAll('input[type="checkbox"]');
|
|
54
|
+
expect($inputs).toHaveLength(3);
|
|
55
|
+
predefined.forEach((item, index)=>{
|
|
56
|
+
expect($inputs[index].value).toEqual(item);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it('calls setValue for every check event and removeValue if all items are unclicked', ()=>{
|
|
60
|
+
const predefined = [
|
|
61
|
+
'banana',
|
|
62
|
+
'orange',
|
|
63
|
+
'strawberry'
|
|
64
|
+
];
|
|
65
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
66
|
+
jest.spyOn(mock, 'setValue');
|
|
67
|
+
jest.spyOn(mock, 'removeValue');
|
|
68
|
+
return {
|
|
69
|
+
...mock,
|
|
70
|
+
items: {
|
|
71
|
+
type: '',
|
|
72
|
+
validations: [
|
|
73
|
+
{
|
|
74
|
+
in: predefined
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
const { container } = render(React.createElement(CheckboxEditor, {
|
|
81
|
+
field: field,
|
|
82
|
+
locales: createFakeLocalesAPI(),
|
|
83
|
+
isInitiallyDisabled: false
|
|
84
|
+
}));
|
|
85
|
+
const $inputs = container.querySelectorAll('input[type="checkbox"]');
|
|
86
|
+
fireEvent.click($inputs[0]);
|
|
87
|
+
expect(field.setValue).toHaveBeenCalledWith([
|
|
88
|
+
predefined[0]
|
|
89
|
+
]);
|
|
90
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
91
|
+
fireEvent.click($inputs[2]);
|
|
92
|
+
expect(field.setValue).toHaveBeenCalledWith([
|
|
93
|
+
predefined[0],
|
|
94
|
+
predefined[2]
|
|
95
|
+
]);
|
|
96
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
97
|
+
fireEvent.click($inputs[1]);
|
|
98
|
+
expect(field.setValue).toHaveBeenCalledWith([
|
|
99
|
+
predefined[0],
|
|
100
|
+
predefined[2],
|
|
101
|
+
predefined[1]
|
|
102
|
+
]);
|
|
103
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
104
|
+
$inputs.forEach(($input)=>{
|
|
105
|
+
fireEvent.click($input);
|
|
106
|
+
});
|
|
107
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
108
|
+
});
|
|
109
|
+
it('renders invalid text and remove link when value set is not in predefined values', ()=>{
|
|
110
|
+
const predefined = [
|
|
111
|
+
'banana',
|
|
112
|
+
'orange',
|
|
113
|
+
'strawberry'
|
|
114
|
+
];
|
|
115
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
116
|
+
jest.spyOn(mock, 'setValue');
|
|
117
|
+
jest.spyOn(mock, 'removeValue');
|
|
118
|
+
return {
|
|
119
|
+
...mock,
|
|
120
|
+
items: {
|
|
121
|
+
type: '',
|
|
122
|
+
validations: [
|
|
123
|
+
{
|
|
124
|
+
in: predefined
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
field.setValue([
|
|
131
|
+
'mango'
|
|
132
|
+
]);
|
|
133
|
+
const { getByTestId } = render(React.createElement(CheckboxEditor, {
|
|
134
|
+
field: field,
|
|
135
|
+
locales: createFakeLocalesAPI(),
|
|
136
|
+
isInitiallyDisabled: false
|
|
137
|
+
}));
|
|
138
|
+
expect(getByTestId('invalid-text')).toBeInTheDocument();
|
|
139
|
+
expect(getByTestId('cf-ui-text-link')).toBeInTheDocument();
|
|
140
|
+
fireEvent.click(getByTestId('cf-ui-text-link'));
|
|
141
|
+
expect(field.removeValue).toHaveBeenCalledTimes(1);
|
|
142
|
+
});
|
|
143
|
+
it('renders checkboxes with unique ids', async ()=>{
|
|
144
|
+
const predefined = [
|
|
145
|
+
'banana',
|
|
146
|
+
'orange',
|
|
147
|
+
'strawberry'
|
|
148
|
+
];
|
|
149
|
+
const [field] = createFakeFieldAPI((mock)=>{
|
|
150
|
+
return {
|
|
151
|
+
...mock,
|
|
152
|
+
items: {
|
|
153
|
+
type: '',
|
|
154
|
+
validations: [
|
|
155
|
+
{
|
|
156
|
+
in: predefined
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
const locales = createFakeLocalesAPI();
|
|
163
|
+
const { findAllByTestId } = render(React.createElement("div", null, React.createElement(CheckboxEditor, {
|
|
164
|
+
field: field,
|
|
165
|
+
locales: locales,
|
|
166
|
+
isInitiallyDisabled: false
|
|
167
|
+
}), React.createElement(CheckboxEditor, {
|
|
168
|
+
field: field,
|
|
169
|
+
locales: locales,
|
|
170
|
+
isInitiallyDisabled: false
|
|
171
|
+
})));
|
|
172
|
+
const $labels = await findAllByTestId('cf-ui-checkbox');
|
|
173
|
+
const uniqueIds = Array.from(new Set($labels.map((label)=>label.getAttribute('for'))));
|
|
174
|
+
expect(uniqueIds).toHaveLength(6);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CheckboxEditor } from './CheckboxEditor';
|
|
@@ -0,0 +1,15 @@
|
|
|
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 invalidText = css({
|
|
10
|
+
color: tokens.red500,
|
|
11
|
+
marginLeft: tokens.spacing2Xs
|
|
12
|
+
});
|
|
13
|
+
export const removeBtn = css({
|
|
14
|
+
marginLeft: tokens.spacingL
|
|
15
|
+
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import { FieldAPI, LocalesAPI } from '@contentful/field-editor-shared';
|
|
3
|
-
export interface CheckboxEditorProps {
|
|
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 CheckboxEditor(props: CheckboxEditorProps): JSX.Element;
|
|
18
|
-
export declare namespace CheckboxEditor {
|
|
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 CheckboxEditorProps {
|
|
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 CheckboxEditor(props: CheckboxEditorProps): React.JSX.Element;
|
|
18
|
+
export declare namespace CheckboxEditor {
|
|
19
|
+
var defaultProps: {
|
|
20
|
+
isInitiallyDisabled: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CheckboxEditor } from './CheckboxEditor';
|
|
1
|
+
export { CheckboxEditor } from './CheckboxEditor';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const form: string;
|
|
2
|
-
export declare const rightToLeft: string;
|
|
3
|
-
export declare const invalidText: string;
|
|
4
|
-
export declare const removeBtn: string;
|
|
1
|
+
export declare const form: string;
|
|
2
|
+
export declare const rightToLeft: string;
|
|
3
|
+
export declare const invalidText: string;
|
|
4
|
+
export declare const removeBtn: string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-checkbox",
|
|
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,25 +22,31 @@
|
|
|
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.3.23",
|
|
25
39
|
"@contentful/f36-tokens": "^4.0.0",
|
|
26
|
-
"@contentful/field-editor-shared": "^1.
|
|
40
|
+
"@contentful/field-editor-shared": "^1.3.0",
|
|
27
41
|
"emotion": "^10.0.17",
|
|
28
42
|
"lodash": "^4.17.15",
|
|
29
43
|
"lodash-es": "^4.17.15"
|
|
30
44
|
},
|
|
31
45
|
"devDependencies": {
|
|
32
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
46
|
+
"@contentful/field-editor-test-utils": "^1.4.0"
|
|
33
47
|
},
|
|
34
48
|
"peerDependencies": {
|
|
35
49
|
"react": ">=16.8.0"
|
|
36
50
|
},
|
|
37
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
|
|
38
52
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,198 +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.1.12](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.11...@contentful/field-editor-checkbox@1.1.12) (2023-03-14)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
9
|
-
|
|
10
|
-
## [1.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.10...@contentful/field-editor-checkbox@1.1.11) (2023-03-10)
|
|
11
|
-
|
|
12
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
13
|
-
|
|
14
|
-
## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.9...@contentful/field-editor-checkbox@1.1.10) (2023-02-21)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
17
|
-
|
|
18
|
-
## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.8...@contentful/field-editor-checkbox@1.1.9) (2023-02-07)
|
|
19
|
-
|
|
20
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
21
|
-
|
|
22
|
-
## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.7...@contentful/field-editor-checkbox@1.1.8) (2022-12-08)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
25
|
-
|
|
26
|
-
## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.6...@contentful/field-editor-checkbox@1.1.7) (2022-12-06)
|
|
27
|
-
|
|
28
|
-
### Bug Fixes
|
|
29
|
-
|
|
30
|
-
- clickable area of checkbox was too big ([#1301](https://github.com/contentful/field-editors/issues/1301)) ([696713b](https://github.com/contentful/field-editors/commit/696713b55670f77ea4afa6f7cfc7cb8217d74552))
|
|
31
|
-
|
|
32
|
-
## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.5...@contentful/field-editor-checkbox@1.1.6) (2022-07-29)
|
|
33
|
-
|
|
34
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
35
|
-
|
|
36
|
-
## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.4...@contentful/field-editor-checkbox@1.1.5) (2022-07-29)
|
|
37
|
-
|
|
38
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
39
|
-
|
|
40
|
-
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.3...@contentful/field-editor-checkbox@1.1.4) (2022-07-11)
|
|
41
|
-
|
|
42
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
43
|
-
|
|
44
|
-
## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.2...@contentful/field-editor-checkbox@1.1.3) (2022-06-22)
|
|
45
|
-
|
|
46
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
47
|
-
|
|
48
|
-
## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.1...@contentful/field-editor-checkbox@1.1.2) (2022-02-15)
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
- bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
|
|
53
|
-
|
|
54
|
-
## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.1.0...@contentful/field-editor-checkbox@1.1.1) (2022-02-14)
|
|
55
|
-
|
|
56
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
57
|
-
|
|
58
|
-
# [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.0.3...@contentful/field-editor-checkbox@1.1.0) (2022-01-11)
|
|
59
|
-
|
|
60
|
-
### Features
|
|
61
|
-
|
|
62
|
-
- 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))
|
|
63
|
-
|
|
64
|
-
## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.0.2...@contentful/field-editor-checkbox@1.0.3) (2021-12-23)
|
|
65
|
-
|
|
66
|
-
### Bug Fixes
|
|
67
|
-
|
|
68
|
-
- markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
|
|
69
|
-
|
|
70
|
-
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.0.1...@contentful/field-editor-checkbox@1.0.2) (2021-12-20)
|
|
71
|
-
|
|
72
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
73
|
-
|
|
74
|
-
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@1.0.0...@contentful/field-editor-checkbox@1.0.1) (2021-11-17)
|
|
75
|
-
|
|
76
|
-
### Bug Fixes
|
|
77
|
-
|
|
78
|
-
- **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))
|
|
79
|
-
|
|
80
|
-
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.16.0...@contentful/field-editor-checkbox@1.0.0) (2021-11-04)
|
|
81
|
-
|
|
82
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
83
|
-
|
|
84
|
-
# [0.16.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.6...@contentful/field-editor-checkbox@0.16.0) (2021-11-04)
|
|
85
|
-
|
|
86
|
-
### Features
|
|
87
|
-
|
|
88
|
-
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
89
|
-
|
|
90
|
-
### BREAKING CHANGES
|
|
91
|
-
|
|
92
|
-
- adopts a new Forma v4 beta
|
|
93
|
-
|
|
94
|
-
## [0.15.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.5...@contentful/field-editor-checkbox@0.15.6) (2021-10-14)
|
|
95
|
-
|
|
96
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
97
|
-
|
|
98
|
-
## [0.15.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.4...@contentful/field-editor-checkbox@0.15.5) (2021-10-06)
|
|
99
|
-
|
|
100
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
101
|
-
|
|
102
|
-
## [0.15.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.3...@contentful/field-editor-checkbox@0.15.4) (2021-09-17)
|
|
103
|
-
|
|
104
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
105
|
-
|
|
106
|
-
## [0.15.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.2...@contentful/field-editor-checkbox@0.15.3) (2021-09-16)
|
|
107
|
-
|
|
108
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
109
|
-
|
|
110
|
-
## [0.15.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.1...@contentful/field-editor-checkbox@0.15.2) (2021-08-19)
|
|
111
|
-
|
|
112
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
113
|
-
|
|
114
|
-
## [0.15.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.15.0...@contentful/field-editor-checkbox@0.15.1) (2021-07-29)
|
|
115
|
-
|
|
116
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
117
|
-
|
|
118
|
-
# [0.15.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.14.0...@contentful/field-editor-checkbox@0.15.0) (2021-07-23)
|
|
119
|
-
|
|
120
|
-
### Features
|
|
121
|
-
|
|
122
|
-
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
123
|
-
|
|
124
|
-
# [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.6...@contentful/field-editor-checkbox@0.14.0) (2021-07-12)
|
|
125
|
-
|
|
126
|
-
### Features
|
|
127
|
-
|
|
128
|
-
- fix non-unique checkbox labels for multiple editors ([#775](https://github.com/contentful/field-editors/issues/775)) ([a5e09b3](https://github.com/contentful/field-editors/commit/a5e09b3359fb48a0b6d27629905df5fccc1a1b37))
|
|
129
|
-
|
|
130
|
-
## [0.13.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.3...@contentful/field-editor-checkbox@0.13.6) (2021-07-06)
|
|
131
|
-
|
|
132
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
133
|
-
|
|
134
|
-
## [0.13.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.3...@contentful/field-editor-checkbox@0.13.5) (2021-07-06)
|
|
135
|
-
|
|
136
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
137
|
-
|
|
138
|
-
## [0.13.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.3...@contentful/field-editor-checkbox@0.13.4) (2021-06-23)
|
|
139
|
-
|
|
140
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
141
|
-
|
|
142
|
-
## [0.13.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.2...@contentful/field-editor-checkbox@0.13.3) (2021-06-23)
|
|
143
|
-
|
|
144
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
145
|
-
|
|
146
|
-
## [0.13.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.1...@contentful/field-editor-checkbox@0.13.2) (2021-06-22)
|
|
147
|
-
|
|
148
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
149
|
-
|
|
150
|
-
## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.13.0...@contentful/field-editor-checkbox@0.13.1) (2021-03-05)
|
|
151
|
-
|
|
152
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
153
|
-
|
|
154
|
-
# [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.12.2...@contentful/field-editor-checkbox@0.13.0) (2021-02-19)
|
|
155
|
-
|
|
156
|
-
### Features
|
|
157
|
-
|
|
158
|
-
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
159
|
-
|
|
160
|
-
## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.12.1...@contentful/field-editor-checkbox@0.12.2) (2021-02-09)
|
|
161
|
-
|
|
162
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
163
|
-
|
|
164
|
-
## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.12.0...@contentful/field-editor-checkbox@0.12.1) (2021-02-01)
|
|
165
|
-
|
|
166
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
167
|
-
|
|
168
|
-
# [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.11.0...@contentful/field-editor-checkbox@0.12.0) (2021-01-20)
|
|
169
|
-
|
|
170
|
-
### Features
|
|
171
|
-
|
|
172
|
-
- 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))
|
|
173
|
-
|
|
174
|
-
# [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.10.6...@contentful/field-editor-checkbox@0.11.0) (2021-01-12)
|
|
175
|
-
|
|
176
|
-
### Features
|
|
177
|
-
|
|
178
|
-
- 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))
|
|
179
|
-
|
|
180
|
-
## [0.10.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.10.5...@contentful/field-editor-checkbox@0.10.6) (2020-12-16)
|
|
181
|
-
|
|
182
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
183
|
-
|
|
184
|
-
## [0.10.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.10.4...@contentful/field-editor-checkbox@0.10.5) (2020-11-06)
|
|
185
|
-
|
|
186
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
187
|
-
|
|
188
|
-
## [0.10.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.10.3...@contentful/field-editor-checkbox@0.10.4) (2020-11-06)
|
|
189
|
-
|
|
190
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
191
|
-
|
|
192
|
-
## [0.10.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.10.2...@contentful/field-editor-checkbox@0.10.3) (2020-10-28)
|
|
193
|
-
|
|
194
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
195
|
-
|
|
196
|
-
## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-checkbox@0.10.1...@contentful/field-editor-checkbox@0.10.2) (2020-08-24)
|
|
197
|
-
|
|
198
|
-
**Note:** Version bump only for package @contentful/field-editor-checkbox
|
|
@@ -1,151 +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 emotion = require('emotion');
|
|
9
|
-
var get = _interopDefault(require('lodash/get'));
|
|
10
|
-
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
11
|
-
var f36Components = require('@contentful/f36-components');
|
|
12
|
-
var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
13
|
-
var nanoid = require('nanoid');
|
|
14
|
-
|
|
15
|
-
var form = /*#__PURE__*/emotion.css({
|
|
16
|
-
marginTop: tokens.spacingS
|
|
17
|
-
});
|
|
18
|
-
var rightToLeft = /*#__PURE__*/emotion.css({
|
|
19
|
-
direction: 'rtl'
|
|
20
|
-
});
|
|
21
|
-
var invalidText = /*#__PURE__*/emotion.css({
|
|
22
|
-
color: tokens.red500,
|
|
23
|
-
marginLeft: tokens.spacing2Xs
|
|
24
|
-
});
|
|
25
|
-
var removeBtn = /*#__PURE__*/emotion.css({
|
|
26
|
-
marginLeft: tokens.spacingL
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
function isEmptyListValue(value) {
|
|
30
|
-
return value === null || value.length === 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function getOptions(field, id) {
|
|
34
|
-
// Get first object that has a 'in' property
|
|
35
|
-
var validations = get(field, ['items', 'validations'], []);
|
|
36
|
-
var predefinedValues = validations.filter(function (validation) {
|
|
37
|
-
return validation["in"];
|
|
38
|
-
}).map(function (validation) {
|
|
39
|
-
return validation["in"];
|
|
40
|
-
});
|
|
41
|
-
var firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];
|
|
42
|
-
return firstPredefinedValues.map(function (value, index) {
|
|
43
|
-
return {
|
|
44
|
-
// Append a random id to distinguish between checkboxes opened in two editors (e.g. slide-in)
|
|
45
|
-
id: ['entity', field.id, field.locale, index, id].join('.'),
|
|
46
|
-
value: value,
|
|
47
|
-
label: value
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
var getInvalidValues = function getInvalidValues(field, values, options) {
|
|
53
|
-
var getValueFromOptions = options.map(function (item) {
|
|
54
|
-
return item.value;
|
|
55
|
-
});
|
|
56
|
-
var invalidValues = values.filter(function (value) {
|
|
57
|
-
return !getValueFromOptions.includes(value);
|
|
58
|
-
}).map(function (value, index) {
|
|
59
|
-
return {
|
|
60
|
-
id: ['entity', field.id, field.locale, index, 'invalid'].join('.'),
|
|
61
|
-
label: value,
|
|
62
|
-
invalid: true,
|
|
63
|
-
value: value
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
return invalidValues;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
function CheckboxEditor(props) {
|
|
70
|
-
var _useState = React.useState(function () {
|
|
71
|
-
return nanoid.nanoid(6);
|
|
72
|
-
}),
|
|
73
|
-
id = _useState[0];
|
|
74
|
-
|
|
75
|
-
var field = props.field,
|
|
76
|
-
locales = props.locales;
|
|
77
|
-
var options = getOptions(field, id);
|
|
78
|
-
var misconfigured = options.length === 0;
|
|
79
|
-
|
|
80
|
-
if (misconfigured) {
|
|
81
|
-
return React.createElement(fieldEditorShared.PredefinedValuesError, null);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
var direction = locales.direction[field.locale] || 'ltr';
|
|
85
|
-
return React.createElement(fieldEditorShared.FieldConnector, {
|
|
86
|
-
throttle: 0,
|
|
87
|
-
isEmptyValue: isEmptyListValue,
|
|
88
|
-
field: field,
|
|
89
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
90
|
-
}, function (_ref) {
|
|
91
|
-
var disabled = _ref.disabled,
|
|
92
|
-
value = _ref.value,
|
|
93
|
-
setValue = _ref.setValue;
|
|
94
|
-
var values = value || [];
|
|
95
|
-
|
|
96
|
-
var addValue = function addValue(value) {
|
|
97
|
-
var newValues = [].concat(values.filter(function (item) {
|
|
98
|
-
return item !== value;
|
|
99
|
-
}), [value]);
|
|
100
|
-
setValue(newValues);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
var removeValue = function removeValue(value) {
|
|
104
|
-
var newValues = values.filter(function (item) {
|
|
105
|
-
return item !== value;
|
|
106
|
-
});
|
|
107
|
-
setValue(newValues);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
var invalidValues = getInvalidValues(field, values, options);
|
|
111
|
-
var mergedOptions = [].concat(options, invalidValues);
|
|
112
|
-
return React.createElement(f36Components.Form, {
|
|
113
|
-
testId: "checkbox-editor",
|
|
114
|
-
className: emotion.cx(form, direction === 'rtl' ? rightToLeft : '')
|
|
115
|
-
}, mergedOptions.map(function (item) {
|
|
116
|
-
return React.createElement(f36Components.Box, {
|
|
117
|
-
key: item.id,
|
|
118
|
-
marginBottom: "spacingS"
|
|
119
|
-
}, React.createElement(f36Components.Checkbox, {
|
|
120
|
-
key: item.id,
|
|
121
|
-
id: item.id,
|
|
122
|
-
isChecked: values.includes(item.value),
|
|
123
|
-
isDisabled: disabled,
|
|
124
|
-
value: item.value,
|
|
125
|
-
name: field.id + "." + field.locale,
|
|
126
|
-
onChange: function onChange(e) {
|
|
127
|
-
if (e.target.checked) {
|
|
128
|
-
addValue(item.value);
|
|
129
|
-
} else {
|
|
130
|
-
removeValue(item.value);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}, item.label), item.invalid && React.createElement(React.Fragment, null, React.createElement("span", {
|
|
134
|
-
"data-test-id": "invalid-text",
|
|
135
|
-
className: invalidText
|
|
136
|
-
}, "(invalid)"), React.createElement(f36Components.TextLink, {
|
|
137
|
-
as: "button",
|
|
138
|
-
className: removeBtn,
|
|
139
|
-
onClick: function onClick() {
|
|
140
|
-
return removeValue(item.value);
|
|
141
|
-
}
|
|
142
|
-
}, "Remove")));
|
|
143
|
-
}));
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
CheckboxEditor.defaultProps = {
|
|
147
|
-
isInitiallyDisabled: true
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
exports.CheckboxEditor = CheckboxEditor;
|
|
151
|
-
//# sourceMappingURL=field-editor-checkbox.cjs.development.js.map
|