@contentful/field-editor-boolean 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.
@@ -0,0 +1,116 @@
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 _BooleanEditor = require("./BooleanEditor");
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('BooleanEditor', ()=>{
53
+ afterEach(_react1.cleanup);
54
+ it('renders inputs for true and false values', ()=>{
55
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)();
56
+ const { container , getByLabelText } = (0, _react1.render)(_react.createElement(_BooleanEditor.BooleanEditor, {
57
+ field: field,
58
+ isInitiallyDisabled: false
59
+ }));
60
+ const $inputs = container.querySelectorAll('input[type="radio"]');
61
+ expect($inputs).toHaveLength(2);
62
+ [
63
+ {
64
+ value: 'true',
65
+ label: 'Yes'
66
+ },
67
+ {
68
+ value: 'false',
69
+ label: 'No'
70
+ }
71
+ ].forEach((item, index)=>{
72
+ expect($inputs[index].value).toEqual(item.value);
73
+ getByLabelText(item.label);
74
+ });
75
+ });
76
+ it('calls setValue and removeValue properly', ()=>{
77
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
78
+ jest.spyOn(field, 'setValue');
79
+ jest.spyOn(field, 'removeValue');
80
+ return {
81
+ ...field
82
+ };
83
+ });
84
+ const { getByLabelText , queryByText , getByText } = (0, _react1.render)(_react.createElement(_BooleanEditor.BooleanEditor, {
85
+ field: field,
86
+ isInitiallyDisabled: false,
87
+ parameters: {
88
+ installation: {},
89
+ instance: {
90
+ trueLabel: 'Yeah, obviously',
91
+ falseLabel: 'No, of course'
92
+ }
93
+ }
94
+ }));
95
+ expect(queryByText('Clear')).not.toBeInTheDocument();
96
+ _react1.fireEvent.click(getByLabelText('Yeah, obviously'));
97
+ expect(field.setValue).toHaveBeenCalledWith(true);
98
+ _react1.fireEvent.click(getByLabelText('No, of course'));
99
+ expect(field.setValue).toHaveBeenCalledWith(false);
100
+ expect(field.removeValue).toHaveBeenCalledTimes(0);
101
+ _react1.fireEvent.click(getByText('Clear'));
102
+ expect(field.removeValue).toHaveBeenCalledTimes(1);
103
+ });
104
+ it('all interactive elements are disabled if field is disabled', ()=>{
105
+ const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
106
+ return field;
107
+ }, true);
108
+ const { getByTestId , getByLabelText } = (0, _react1.render)(_react.createElement(_BooleanEditor.BooleanEditor, {
109
+ field: field,
110
+ isInitiallyDisabled: true
111
+ }));
112
+ expect(getByLabelText('Yes')).toBeDisabled();
113
+ expect(getByLabelText('No')).toBeDisabled();
114
+ expect(getByTestId('boolean-editor-clear')).toBeDisabled();
115
+ });
116
+ });
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "BooleanEditor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return BooleanEditor;
9
+ }
10
+ });
11
+ const _react = _interop_require_wildcard(require("react"));
12
+ const _f36components = require("@contentful/f36-components");
13
+ const _fieldeditorshared = require("@contentful/field-editor-shared");
14
+ const _get = _interop_require_default(require("lodash/get"));
15
+ const _nanoid = require("nanoid");
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
20
+ }
21
+ function _getRequireWildcardCache(nodeInterop) {
22
+ if (typeof WeakMap !== "function") return null;
23
+ var cacheBabelInterop = new WeakMap();
24
+ var cacheNodeInterop = new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop) {
26
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) {
31
+ return obj;
32
+ }
33
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
+ return {
35
+ default: obj
36
+ };
37
+ }
38
+ var cache = _getRequireWildcardCache(nodeInterop);
39
+ if (cache && cache.has(obj)) {
40
+ return cache.get(obj);
41
+ }
42
+ var newObj = {};
43
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
44
+ for(var key in obj){
45
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
46
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
47
+ if (desc && (desc.get || desc.set)) {
48
+ Object.defineProperty(newObj, key, desc);
49
+ } else {
50
+ newObj[key] = obj[key];
51
+ }
52
+ }
53
+ }
54
+ newObj.default = obj;
55
+ if (cache) {
56
+ cache.set(obj, newObj);
57
+ }
58
+ return newObj;
59
+ }
60
+ function BooleanEditor(props) {
61
+ const { field } = props;
62
+ const options = [
63
+ {
64
+ value: true,
65
+ label: (0, _get.default)(props.parameters, [
66
+ 'instance',
67
+ 'trueLabel'
68
+ ], 'Yes'),
69
+ id: (0, _nanoid.nanoid)(6)
70
+ },
71
+ {
72
+ value: false,
73
+ label: (0, _get.default)(props.parameters, [
74
+ 'instance',
75
+ 'falseLabel'
76
+ ], 'No'),
77
+ id: (0, _nanoid.nanoid)(6)
78
+ }
79
+ ];
80
+ return _react.createElement(_fieldeditorshared.FieldConnector, {
81
+ throttle: 0,
82
+ field: field,
83
+ isInitiallyDisabled: props.isInitiallyDisabled
84
+ }, ({ disabled , value , setValue })=>{
85
+ const setOption = (value)=>{
86
+ setValue(value === 'true' ? true : false);
87
+ };
88
+ const clearOption = ()=>{
89
+ setValue(null);
90
+ };
91
+ return _react.createElement(_f36components.Flex, {
92
+ testId: "boolean-editor",
93
+ alignItems: "center",
94
+ marginTop: "spacingS"
95
+ }, options.map((item)=>{
96
+ const id = [
97
+ 'entity',
98
+ field.id,
99
+ field.locale,
100
+ item.value,
101
+ item.id
102
+ ].join('.');
103
+ const checked = value === item.value;
104
+ return _react.createElement(_f36components.Flex, {
105
+ marginRight: "spacingM",
106
+ key: id
107
+ }, _react.createElement(_f36components.Radio, {
108
+ id: id,
109
+ isDisabled: disabled,
110
+ value: item.value === undefined ? '' : String(item.value),
111
+ isChecked: checked,
112
+ onChange: (e)=>{
113
+ if (e.target.checked) {
114
+ setOption(e.target.value);
115
+ }
116
+ }
117
+ }, item.label));
118
+ }), value !== undefined && _react.createElement(_f36components.TextLink, {
119
+ as: "button",
120
+ testId: "boolean-editor-clear",
121
+ isDisabled: disabled,
122
+ onClick: clearOption
123
+ }, "Clear"));
124
+ });
125
+ }
126
+ BooleanEditor.defaultProps = {
127
+ isInitiallyDisabled: true
128
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "BooleanEditor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _BooleanEditor.BooleanEditor;
9
+ }
10
+ });
11
+ const _BooleanEditor = require("./BooleanEditor");
@@ -0,0 +1,73 @@
1
+ import * as React from 'react';
2
+ import { createFakeFieldAPI } 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 { BooleanEditor } from './BooleanEditor';
6
+ configure({
7
+ testIdAttribute: 'data-test-id'
8
+ });
9
+ describe('BooleanEditor', ()=>{
10
+ afterEach(cleanup);
11
+ it('renders inputs for true and false values', ()=>{
12
+ const [field] = createFakeFieldAPI();
13
+ const { container , getByLabelText } = render(React.createElement(BooleanEditor, {
14
+ field: field,
15
+ isInitiallyDisabled: false
16
+ }));
17
+ const $inputs = container.querySelectorAll('input[type="radio"]');
18
+ expect($inputs).toHaveLength(2);
19
+ [
20
+ {
21
+ value: 'true',
22
+ label: 'Yes'
23
+ },
24
+ {
25
+ value: 'false',
26
+ label: 'No'
27
+ }
28
+ ].forEach((item, index)=>{
29
+ expect($inputs[index].value).toEqual(item.value);
30
+ getByLabelText(item.label);
31
+ });
32
+ });
33
+ it('calls setValue and removeValue properly', ()=>{
34
+ const [field] = createFakeFieldAPI((field)=>{
35
+ jest.spyOn(field, 'setValue');
36
+ jest.spyOn(field, 'removeValue');
37
+ return {
38
+ ...field
39
+ };
40
+ });
41
+ const { getByLabelText , queryByText , getByText } = render(React.createElement(BooleanEditor, {
42
+ field: field,
43
+ isInitiallyDisabled: false,
44
+ parameters: {
45
+ installation: {},
46
+ instance: {
47
+ trueLabel: 'Yeah, obviously',
48
+ falseLabel: 'No, of course'
49
+ }
50
+ }
51
+ }));
52
+ expect(queryByText('Clear')).not.toBeInTheDocument();
53
+ fireEvent.click(getByLabelText('Yeah, obviously'));
54
+ expect(field.setValue).toHaveBeenCalledWith(true);
55
+ fireEvent.click(getByLabelText('No, of course'));
56
+ expect(field.setValue).toHaveBeenCalledWith(false);
57
+ expect(field.removeValue).toHaveBeenCalledTimes(0);
58
+ fireEvent.click(getByText('Clear'));
59
+ expect(field.removeValue).toHaveBeenCalledTimes(1);
60
+ });
61
+ it('all interactive elements are disabled if field is disabled', ()=>{
62
+ const [field] = createFakeFieldAPI((field)=>{
63
+ return field;
64
+ }, true);
65
+ const { getByTestId , getByLabelText } = render(React.createElement(BooleanEditor, {
66
+ field: field,
67
+ isInitiallyDisabled: true
68
+ }));
69
+ expect(getByLabelText('Yes')).toBeDisabled();
70
+ expect(getByLabelText('No')).toBeDisabled();
71
+ expect(getByTestId('boolean-editor-clear')).toBeDisabled();
72
+ });
73
+ });
@@ -0,0 +1,74 @@
1
+ import * as React from 'react';
2
+ import { TextLink, Flex, Radio } from '@contentful/f36-components';
3
+ import { FieldConnector } from '@contentful/field-editor-shared';
4
+ import get from 'lodash/get';
5
+ import { nanoid } from 'nanoid';
6
+ export function BooleanEditor(props) {
7
+ const { field } = props;
8
+ const options = [
9
+ {
10
+ value: true,
11
+ label: get(props.parameters, [
12
+ 'instance',
13
+ 'trueLabel'
14
+ ], 'Yes'),
15
+ id: nanoid(6)
16
+ },
17
+ {
18
+ value: false,
19
+ label: get(props.parameters, [
20
+ 'instance',
21
+ 'falseLabel'
22
+ ], 'No'),
23
+ id: nanoid(6)
24
+ }
25
+ ];
26
+ return React.createElement(FieldConnector, {
27
+ throttle: 0,
28
+ field: field,
29
+ isInitiallyDisabled: props.isInitiallyDisabled
30
+ }, ({ disabled , value , setValue })=>{
31
+ const setOption = (value)=>{
32
+ setValue(value === 'true' ? true : false);
33
+ };
34
+ const clearOption = ()=>{
35
+ setValue(null);
36
+ };
37
+ return React.createElement(Flex, {
38
+ testId: "boolean-editor",
39
+ alignItems: "center",
40
+ marginTop: "spacingS"
41
+ }, options.map((item)=>{
42
+ const id = [
43
+ 'entity',
44
+ field.id,
45
+ field.locale,
46
+ item.value,
47
+ item.id
48
+ ].join('.');
49
+ const checked = value === item.value;
50
+ return React.createElement(Flex, {
51
+ marginRight: "spacingM",
52
+ key: id
53
+ }, React.createElement(Radio, {
54
+ id: id,
55
+ isDisabled: disabled,
56
+ value: item.value === undefined ? '' : String(item.value),
57
+ isChecked: checked,
58
+ onChange: (e)=>{
59
+ if (e.target.checked) {
60
+ setOption(e.target.value);
61
+ }
62
+ }
63
+ }, item.label));
64
+ }), value !== undefined && React.createElement(TextLink, {
65
+ as: "button",
66
+ testId: "boolean-editor-clear",
67
+ isDisabled: disabled,
68
+ onClick: clearOption
69
+ }, "Clear"));
70
+ });
71
+ }
72
+ BooleanEditor.defaultProps = {
73
+ isInitiallyDisabled: true
74
+ };
@@ -0,0 +1 @@
1
+ export { BooleanEditor } from './BooleanEditor';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -1,27 +1,27 @@
1
- /// <reference types="react" />
2
- import { FieldAPI, ParametersAPI } from '@contentful/field-editor-shared';
3
- export interface BooleanEditorProps {
4
- /**
5
- * is the field disabled initially
6
- */
7
- isInitiallyDisabled: boolean;
8
- /**
9
- * sdk.field
10
- */
11
- field: FieldAPI;
12
- /**
13
- * sdk.parameters
14
- */
15
- parameters?: ParametersAPI & {
16
- instance: {
17
- trueLabel?: string;
18
- falseLabel?: string;
19
- };
20
- };
21
- }
22
- export declare function BooleanEditor(props: BooleanEditorProps): JSX.Element;
23
- export declare namespace BooleanEditor {
24
- var defaultProps: {
25
- isInitiallyDisabled: boolean;
26
- };
27
- }
1
+ import * as React from 'react';
2
+ import { FieldAPI, ParametersAPI } from '@contentful/field-editor-shared';
3
+ export interface BooleanEditorProps {
4
+ /**
5
+ * is the field disabled initially
6
+ */
7
+ isInitiallyDisabled: boolean;
8
+ /**
9
+ * sdk.field
10
+ */
11
+ field: FieldAPI;
12
+ /**
13
+ * sdk.parameters
14
+ */
15
+ parameters?: ParametersAPI & {
16
+ instance: {
17
+ trueLabel?: string;
18
+ falseLabel?: string;
19
+ };
20
+ };
21
+ }
22
+ export declare function BooleanEditor(props: BooleanEditorProps): React.JSX.Element;
23
+ export declare namespace BooleanEditor {
24
+ var defaultProps: {
25
+ isInitiallyDisabled: boolean;
26
+ };
27
+ }
@@ -1 +1 @@
1
- export { BooleanEditor } from './BooleanEditor';
1
+ export { BooleanEditor } from './BooleanEditor';
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-boolean",
3
- "version": "1.2.0",
4
- "main": "dist/index.js",
5
- "module": "dist/field-editor-boolean.esm.js",
6
- "typings": "dist/index.d.ts",
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,26 +22,32 @@
14
22
  "url": "https://github.com/contentful/field-editors"
15
23
  },
16
24
  "scripts": {
17
- "watch": "tsdx watch",
18
- "build": "tsdx build",
19
- "test": "tsdx test --env=jsdom --watch",
20
- "test:ci": "tsdx test --env=jsdom --ci",
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-shared": "^1.2.0",
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
  "nanoid": "^3.1.3"
31
45
  },
32
46
  "devDependencies": {
33
- "@contentful/field-editor-test-utils": "^1.3.0"
47
+ "@contentful/field-editor-test-utils": "^1.4.0"
34
48
  },
35
49
  "peerDependencies": {
36
50
  "react": ">=16.8.0"
37
51
  },
38
- "gitHead": "de7e74e3485dd69c240cfe9c545e6e50e41fb295"
52
+ "gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
39
53
  }
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.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.11...@contentful/field-editor-boolean@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.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.10...@contentful/field-editor-boolean@1.1.11) (2023-03-14)
13
-
14
- **Note:** Version bump only for package @contentful/field-editor-boolean
15
-
16
- ## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.9...@contentful/field-editor-boolean@1.1.10) (2023-03-10)
17
-
18
- **Note:** Version bump only for package @contentful/field-editor-boolean
19
-
20
- ## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.8...@contentful/field-editor-boolean@1.1.9) (2023-02-21)
21
-
22
- **Note:** Version bump only for package @contentful/field-editor-boolean
23
-
24
- ## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.7...@contentful/field-editor-boolean@1.1.8) (2023-02-07)
25
-
26
- **Note:** Version bump only for package @contentful/field-editor-boolean
27
-
28
- ## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.6...@contentful/field-editor-boolean@1.1.7) (2022-12-08)
29
-
30
- **Note:** Version bump only for package @contentful/field-editor-boolean
31
-
32
- ## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.5...@contentful/field-editor-boolean@1.1.6) (2022-07-29)
33
-
34
- **Note:** Version bump only for package @contentful/field-editor-boolean
35
-
36
- ## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.4...@contentful/field-editor-boolean@1.1.5) (2022-07-29)
37
-
38
- **Note:** Version bump only for package @contentful/field-editor-boolean
39
-
40
- ## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.3...@contentful/field-editor-boolean@1.1.4) (2022-07-11)
41
-
42
- **Note:** Version bump only for package @contentful/field-editor-boolean
43
-
44
- ## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.2...@contentful/field-editor-boolean@1.1.3) (2022-06-22)
45
-
46
- **Note:** Version bump only for package @contentful/field-editor-boolean
47
-
48
- ## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.1.1...@contentful/field-editor-boolean@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-boolean@1.1.0...@contentful/field-editor-boolean@1.1.1) (2022-02-14)
55
-
56
- **Note:** Version bump only for package @contentful/field-editor-boolean
57
-
58
- # [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.0.3...@contentful/field-editor-boolean@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-boolean@1.0.2...@contentful/field-editor-boolean@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-boolean@1.0.1...@contentful/field-editor-boolean@1.0.2) (2021-12-20)
71
-
72
- **Note:** Version bump only for package @contentful/field-editor-boolean
73
-
74
- ## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@1.0.0...@contentful/field-editor-boolean@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-boolean@0.13.0...@contentful/field-editor-boolean@1.0.0) (2021-11-04)
81
-
82
- **Note:** Version bump only for package @contentful/field-editor-boolean
83
-
84
- # [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.6...@contentful/field-editor-boolean@0.13.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.12.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.5...@contentful/field-editor-boolean@0.12.6) (2021-10-14)
95
-
96
- **Note:** Version bump only for package @contentful/field-editor-boolean
97
-
98
- ## [0.12.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.4...@contentful/field-editor-boolean@0.12.5) (2021-10-06)
99
-
100
- **Note:** Version bump only for package @contentful/field-editor-boolean
101
-
102
- ## [0.12.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.3...@contentful/field-editor-boolean@0.12.4) (2021-09-17)
103
-
104
- **Note:** Version bump only for package @contentful/field-editor-boolean
105
-
106
- ## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.2...@contentful/field-editor-boolean@0.12.3) (2021-09-16)
107
-
108
- **Note:** Version bump only for package @contentful/field-editor-boolean
109
-
110
- ## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.1...@contentful/field-editor-boolean@0.12.2) (2021-08-19)
111
-
112
- **Note:** Version bump only for package @contentful/field-editor-boolean
113
-
114
- ## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.12.0...@contentful/field-editor-boolean@0.12.1) (2021-07-29)
115
-
116
- **Note:** Version bump only for package @contentful/field-editor-boolean
117
-
118
- # [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.6...@contentful/field-editor-boolean@0.12.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.11.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.3...@contentful/field-editor-boolean@0.11.6) (2021-07-06)
125
-
126
- **Note:** Version bump only for package @contentful/field-editor-boolean
127
-
128
- ## [0.11.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.3...@contentful/field-editor-boolean@0.11.5) (2021-07-06)
129
-
130
- **Note:** Version bump only for package @contentful/field-editor-boolean
131
-
132
- ## [0.11.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.3...@contentful/field-editor-boolean@0.11.4) (2021-06-23)
133
-
134
- **Note:** Version bump only for package @contentful/field-editor-boolean
135
-
136
- ## [0.11.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.2...@contentful/field-editor-boolean@0.11.3) (2021-06-23)
137
-
138
- **Note:** Version bump only for package @contentful/field-editor-boolean
139
-
140
- ## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.1...@contentful/field-editor-boolean@0.11.2) (2021-06-22)
141
-
142
- **Note:** Version bump only for package @contentful/field-editor-boolean
143
-
144
- ## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.11.0...@contentful/field-editor-boolean@0.11.1) (2021-03-05)
145
-
146
- **Note:** Version bump only for package @contentful/field-editor-boolean
147
-
148
- # [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.10.2...@contentful/field-editor-boolean@0.11.0) (2021-02-19)
149
-
150
- ### Features
151
-
152
- - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
153
-
154
- ## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.10.1...@contentful/field-editor-boolean@0.10.2) (2021-02-09)
155
-
156
- **Note:** Version bump only for package @contentful/field-editor-boolean
157
-
158
- ## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.10.0...@contentful/field-editor-boolean@0.10.1) (2021-02-01)
159
-
160
- **Note:** Version bump only for package @contentful/field-editor-boolean
161
-
162
- # [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.9.0...@contentful/field-editor-boolean@0.10.0) (2021-01-20)
163
-
164
- ### Features
165
-
166
- - 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))
167
-
168
- # [0.9.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.6...@contentful/field-editor-boolean@0.9.0) (2021-01-12)
169
-
170
- ### Features
171
-
172
- - 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))
173
-
174
- ## [0.8.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.5...@contentful/field-editor-boolean@0.8.6) (2021-01-11)
175
-
176
- ### Bug Fixes
177
-
178
- - clear button should respect disabled state ([#551](https://github.com/contentful/field-editors/issues/551)) ([a33c3ec](https://github.com/contentful/field-editors/commit/a33c3ec1f88753dfcea09fb62f5c1725fe379120))
179
-
180
- ## [0.8.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.4...@contentful/field-editor-boolean@0.8.5) (2020-12-16)
181
-
182
- **Note:** Version bump only for package @contentful/field-editor-boolean
183
-
184
- ## [0.8.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.3...@contentful/field-editor-boolean@0.8.4) (2020-11-06)
185
-
186
- **Note:** Version bump only for package @contentful/field-editor-boolean
187
-
188
- ## [0.8.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.2...@contentful/field-editor-boolean@0.8.3) (2020-11-06)
189
-
190
- **Note:** Version bump only for package @contentful/field-editor-boolean
191
-
192
- ## [0.8.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.1...@contentful/field-editor-boolean@0.8.2) (2020-10-28)
193
-
194
- **Note:** Version bump only for package @contentful/field-editor-boolean
195
-
196
- ## [0.8.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-boolean@0.8.0...@contentful/field-editor-boolean@0.8.1) (2020-08-24)
197
-
198
- **Note:** Version bump only for package @contentful/field-editor-boolean
@@ -1,77 +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 fieldEditorShared = require('@contentful/field-editor-shared');
10
- var get = _interopDefault(require('lodash/get'));
11
- var nanoid = require('nanoid');
12
-
13
- function BooleanEditor(props) {
14
- const {
15
- field
16
- } = props;
17
- const options = [{
18
- value: true,
19
- label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'),
20
- id: nanoid.nanoid(6)
21
- }, {
22
- value: false,
23
- label: get(props.parameters, ['instance', 'falseLabel'], 'No'),
24
- id: nanoid.nanoid(6)
25
- }];
26
- return React.createElement(fieldEditorShared.FieldConnector, {
27
- throttle: 0,
28
- field: field,
29
- isInitiallyDisabled: props.isInitiallyDisabled
30
- }, ({
31
- disabled,
32
- value,
33
- setValue
34
- }) => {
35
- const setOption = value => {
36
- setValue(value === 'true' ? true : false);
37
- };
38
-
39
- const clearOption = () => {
40
- setValue(null);
41
- };
42
-
43
- return React.createElement(f36Components.Flex, {
44
- testId: "boolean-editor",
45
- alignItems: "center",
46
- marginTop: "spacingS"
47
- }, options.map(item => {
48
- const id = ['entity', field.id, field.locale, item.value, item.id].join('.');
49
- const checked = value === item.value;
50
- return React.createElement(f36Components.Flex, {
51
- marginRight: "spacingM",
52
- key: id
53
- }, React.createElement(f36Components.Radio, {
54
- id: id,
55
- isDisabled: disabled,
56
- value: item.value === undefined ? '' : String(item.value),
57
- isChecked: checked,
58
- onChange: e => {
59
- if (e.target.checked) {
60
- setOption(e.target.value);
61
- }
62
- }
63
- }, item.label));
64
- }), value !== undefined && React.createElement(f36Components.TextLink, {
65
- as: "button",
66
- testId: "boolean-editor-clear",
67
- isDisabled: disabled,
68
- onClick: clearOption
69
- }, "Clear"));
70
- });
71
- }
72
- BooleanEditor.defaultProps = {
73
- isInitiallyDisabled: true
74
- };
75
-
76
- exports.BooleanEditor = BooleanEditor;
77
- //# sourceMappingURL=field-editor-boolean.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-boolean.cjs.development.js","sources":["../src/BooleanEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { TextLink, Flex, Radio } from '@contentful/f36-components';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport get from 'lodash/get';\nimport { nanoid } from 'nanoid';\n\n\nexport interface BooleanEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n trueLabel?: string;\n falseLabel?: string;\n };\n };\n}\n\nexport function BooleanEditor(props: BooleanEditorProps) {\n const { field } = props;\n\n const options = [\n { value: true, label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'), id: nanoid(6) },\n { value: false, label: get(props.parameters, ['instance', 'falseLabel'], 'No'), id: nanoid(6) },\n ];\n\n return (\n <FieldConnector<boolean>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const setOption = (value: string) => {\n setValue(value === 'true' ? true : false);\n };\n\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"boolean-editor\" alignItems=\"center\" marginTop=\"spacingS\">\n {options.map((item) => {\n const id = ['entity', field.id, field.locale, item.value, item.id].join('.');\n const checked = value === item.value;\n return (\n <Flex marginRight=\"spacingM\" key={id}>\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 </Flex>\n );\n })}\n {value !== undefined && (\n <TextLink\n as=\"button\"\n testId=\"boolean-editor-clear\"\n isDisabled={disabled}\n onClick={clearOption}>\n Clear\n </TextLink>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nBooleanEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["BooleanEditor","props","field","options","value","label","get","parameters","id","nanoid","React","FieldConnector","throttle","isInitiallyDisabled","disabled","setValue","setOption","clearOption","Flex","testId","alignItems","marginTop","map","item","locale","join","checked","marginRight","key","Radio","isDisabled","undefined","String","isChecked","onChange","e","target","TextLink","as","onClick","defaultProps"],"mappings":";;;;;;;;;;;;SA8BgBA,cAAcC;AAC5B,QAAM;AAAEC,IAAAA;AAAF,MAAYD,KAAlB;AAEA,QAAME,OAAO,GAAG,CACd;AAAEC,IAAAA,KAAK,EAAE,IAAT;AAAeC,IAAAA,KAAK,EAAEC,GAAG,CAACL,KAAK,CAACM,UAAP,EAAmB,CAAC,UAAD,EAAa,WAAb,CAAnB,EAA8C,KAA9C,CAAzB;AAA+EC,IAAAA,EAAE,EAAEC,aAAM,CAAC,CAAD;AAAzF,GADc,EAEd;AAAEL,IAAAA,KAAK,EAAE,KAAT;AAAgBC,IAAAA,KAAK,EAAEC,GAAG,CAACL,KAAK,CAACM,UAAP,EAAmB,CAAC,UAAD,EAAa,YAAb,CAAnB,EAA+C,IAA/C,CAA1B;AAAgFC,IAAAA,EAAE,EAAEC,aAAM,CAAC,CAAD;AAA1F,GAFc,CAAhB;AAKA,SACEC,mBAAA,CAACC,gCAAD;AACEC,IAAAA,QAAQ,EAAE;AACVV,IAAAA,KAAK,EAAEA;AACPW,IAAAA,mBAAmB,EAAEZ,KAAK,CAACY;GAH7B,EAIG,CAAC;AAAEC,IAAAA,QAAF;AAAYV,IAAAA,KAAZ;AAAmBW,IAAAA;AAAnB,GAAD;AACC,UAAMC,SAAS,GAAIZ,KAAD;AAChBW,MAAAA,QAAQ,CAACX,KAAK,KAAK,MAAV,GAAmB,IAAnB,GAA0B,KAA3B,CAAR;AACD,KAFD;;AAIA,UAAMa,WAAW,GAAG;AAClBF,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;;AAIA,WACEL,mBAAA,CAACQ,kBAAD;AAAMC,MAAAA,MAAM,EAAC;AAAiBC,MAAAA,UAAU,EAAC;AAASC,MAAAA,SAAS,EAAC;KAA5D,EACGlB,OAAO,CAACmB,GAAR,CAAaC,IAAD;AACX,YAAMf,EAAE,GAAG,CAAC,QAAD,EAAWN,KAAK,CAACM,EAAjB,EAAqBN,KAAK,CAACsB,MAA3B,EAAmCD,IAAI,CAACnB,KAAxC,EAA+CmB,IAAI,CAACf,EAApD,EAAwDiB,IAAxD,CAA6D,GAA7D,CAAX;AACA,YAAMC,OAAO,GAAGtB,KAAK,KAAKmB,IAAI,CAACnB,KAA/B;AACA,aACEM,mBAAA,CAACQ,kBAAD;AAAMS,QAAAA,WAAW,EAAC;AAAWC,QAAAA,GAAG,EAAEpB;OAAlC,EACEE,mBAAA,CAACmB,mBAAD;AACErB,QAAAA,EAAE,EAAEA;AACJsB,QAAAA,UAAU,EAAEhB;AACZV,QAAAA,KAAK,EAAEmB,IAAI,CAACnB,KAAL,KAAe2B,SAAf,GAA2B,EAA3B,GAAgCC,MAAM,CAACT,IAAI,CAACnB,KAAN;AAC7C6B,QAAAA,SAAS,EAAEP;AACXQ,QAAAA,QAAQ,EAAGC,CAAD;AACR,cAAIA,CAAC,CAACC,MAAF,CAASV,OAAb,EAAsB;AACpBV,YAAAA,SAAS,CAACmB,CAAC,CAACC,MAAF,CAAShC,KAAV,CAAT;AACD;AACF;OATH,EAUGmB,IAAI,CAAClB,KAVR,CADF,CADF;AAgBD,KAnBA,CADH,EAqBGD,KAAK,KAAK2B,SAAV,IACCrB,mBAAA,CAAC2B,sBAAD;AACEC,MAAAA,EAAE,EAAC;AACHnB,MAAAA,MAAM,EAAC;AACPW,MAAAA,UAAU,EAAEhB;AACZyB,MAAAA,OAAO,EAAEtB;KAJX,SAAA,CAtBJ,CADF;AAiCD,GA9CH,CADF;AAkDD;AAEDjB,aAAa,CAACwC,YAAd,GAA6B;AAC3B3B,EAAAA,mBAAmB,EAAE;AADM,CAA7B;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=require("@contentful/f36-components"),l=require("@contentful/field-editor-shared"),i=(e=require("lodash/get"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("nanoid");function r(e){const{field:r}=e,o=[{value:!0,label:i(e.parameters,["instance","trueLabel"],"Yes"),id:n.nanoid(6)},{value:!1,label:i(e.parameters,["instance","falseLabel"],"No"),id:n.nanoid(6)}];return t.createElement(l.FieldConnector,{throttle:0,field:r,isInitiallyDisabled:e.isInitiallyDisabled},({disabled:e,value:l,setValue:i})=>t.createElement(a.Flex,{testId:"boolean-editor",alignItems:"center",marginTop:"spacingS"},o.map(n=>{const o=["entity",r.id,r.locale,n.value,n.id].join("."),d=l===n.value;return t.createElement(a.Flex,{marginRight:"spacingM",key:o},t.createElement(a.Radio,{id:o,isDisabled:e,value:void 0===n.value?"":String(n.value),isChecked:d,onChange:e=>{e.target.checked&&(e=>{i("true"===e)})(e.target.value)}},n.label))}),void 0!==l&&t.createElement(a.TextLink,{as:"button",testId:"boolean-editor-clear",isDisabled:e,onClick:()=>{i(null)}},"Clear")))}r.defaultProps={isInitiallyDisabled:!0},exports.BooleanEditor=r;
2
- //# sourceMappingURL=field-editor-boolean.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-boolean.cjs.production.min.js","sources":["../src/BooleanEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { TextLink, Flex, Radio } from '@contentful/f36-components';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport get from 'lodash/get';\nimport { nanoid } from 'nanoid';\n\n\nexport interface BooleanEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n trueLabel?: string;\n falseLabel?: string;\n };\n };\n}\n\nexport function BooleanEditor(props: BooleanEditorProps) {\n const { field } = props;\n\n const options = [\n { value: true, label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'), id: nanoid(6) },\n { value: false, label: get(props.parameters, ['instance', 'falseLabel'], 'No'), id: nanoid(6) },\n ];\n\n return (\n <FieldConnector<boolean>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const setOption = (value: string) => {\n setValue(value === 'true' ? true : false);\n };\n\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"boolean-editor\" alignItems=\"center\" marginTop=\"spacingS\">\n {options.map((item) => {\n const id = ['entity', field.id, field.locale, item.value, item.id].join('.');\n const checked = value === item.value;\n return (\n <Flex marginRight=\"spacingM\" key={id}>\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 </Flex>\n );\n })}\n {value !== undefined && (\n <TextLink\n as=\"button\"\n testId=\"boolean-editor-clear\"\n isDisabled={disabled}\n onClick={clearOption}>\n Clear\n </TextLink>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nBooleanEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["BooleanEditor","props","field","options","value","label","get","parameters","id","nanoid","React","FieldConnector","throttle","isInitiallyDisabled","disabled","setValue","Flex","testId","alignItems","marginTop","map","item","locale","join","checked","marginRight","key","Radio","isDisabled","undefined","String","isChecked","onChange","e","target","setOption","TextLink","as","onClick","defaultProps"],"mappings":"0RA8BgBA,EAAcC,SACtBC,MAAEA,GAAUD,EAEZE,EAAU,CACd,CAAEC,OAAO,EAAMC,MAAOC,EAAIL,EAAMM,WAAY,CAAC,WAAY,aAAc,OAAQC,GAAIC,SAAO,IAC1F,CAAEL,OAAO,EAAOC,MAAOC,EAAIL,EAAMM,WAAY,CAAC,WAAY,cAAe,MAAOC,GAAIC,SAAO,YAI3FC,gBAACC,kBACCC,SAAU,EACVV,MAAOA,EACPW,oBAAqBZ,EAAMY,qBAC1B,EAAGC,SAAAA,EAAUV,MAAAA,EAAOW,SAAAA,KAUjBL,gBAACM,QAAKC,OAAO,iBAAiBC,WAAW,SAASC,UAAU,YACzDhB,EAAQiB,IAAKC,UACNb,EAAK,CAAC,SAAUN,EAAMM,GAAIN,EAAMoB,OAAQD,EAAKjB,MAAOiB,EAAKb,IAAIe,KAAK,KAClEC,EAAUpB,IAAUiB,EAAKjB,aAE7BM,gBAACM,QAAKS,YAAY,WAAWC,IAAKlB,GAChCE,gBAACiB,SACCnB,GAAIA,EACJoB,WAAYd,EACZV,WAAsByB,IAAfR,EAAKjB,MAAsB,GAAK0B,OAAOT,EAAKjB,OACnD2B,UAAWP,EACXQ,SAAWC,IACLA,EAAEC,OAAOV,SArBRpB,CAAAA,IACjBW,EAAmB,SAAVX,IAqBK+B,CAAUF,EAAEC,OAAO9B,SAGtBiB,EAAKhB,eAKHwB,IAAVzB,GACCM,gBAAC0B,YACCC,GAAG,SACHpB,OAAO,uBACPW,WAAYd,EACZwB,QA/BY,KAClBvB,EAAS,mBAyCnBf,EAAcuC,aAAe,CAC3B1B,qBAAqB"}
@@ -1,71 +0,0 @@
1
- import { createElement } from 'react';
2
- import { Flex, Radio, TextLink } from '@contentful/f36-components';
3
- import { FieldConnector } from '@contentful/field-editor-shared';
4
- import get from 'lodash-es/get';
5
- import { nanoid } from 'nanoid';
6
-
7
- function BooleanEditor(props) {
8
- const {
9
- field
10
- } = props;
11
- const options = [{
12
- value: true,
13
- label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'),
14
- id: nanoid(6)
15
- }, {
16
- value: false,
17
- label: get(props.parameters, ['instance', 'falseLabel'], 'No'),
18
- id: nanoid(6)
19
- }];
20
- return createElement(FieldConnector, {
21
- throttle: 0,
22
- field: field,
23
- isInitiallyDisabled: props.isInitiallyDisabled
24
- }, ({
25
- disabled,
26
- value,
27
- setValue
28
- }) => {
29
- const setOption = value => {
30
- setValue(value === 'true' ? true : false);
31
- };
32
-
33
- const clearOption = () => {
34
- setValue(null);
35
- };
36
-
37
- return createElement(Flex, {
38
- testId: "boolean-editor",
39
- alignItems: "center",
40
- marginTop: "spacingS"
41
- }, options.map(item => {
42
- const id = ['entity', field.id, field.locale, item.value, item.id].join('.');
43
- const checked = value === item.value;
44
- return createElement(Flex, {
45
- marginRight: "spacingM",
46
- key: id
47
- }, createElement(Radio, {
48
- id: id,
49
- isDisabled: disabled,
50
- value: item.value === undefined ? '' : String(item.value),
51
- isChecked: checked,
52
- onChange: e => {
53
- if (e.target.checked) {
54
- setOption(e.target.value);
55
- }
56
- }
57
- }, item.label));
58
- }), value !== undefined && createElement(TextLink, {
59
- as: "button",
60
- testId: "boolean-editor-clear",
61
- isDisabled: disabled,
62
- onClick: clearOption
63
- }, "Clear"));
64
- });
65
- }
66
- BooleanEditor.defaultProps = {
67
- isInitiallyDisabled: true
68
- };
69
-
70
- export { BooleanEditor };
71
- //# sourceMappingURL=field-editor-boolean.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-boolean.esm.js","sources":["../src/BooleanEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { TextLink, Flex, Radio } from '@contentful/f36-components';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport get from 'lodash/get';\nimport { nanoid } from 'nanoid';\n\n\nexport interface BooleanEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n trueLabel?: string;\n falseLabel?: string;\n };\n };\n}\n\nexport function BooleanEditor(props: BooleanEditorProps) {\n const { field } = props;\n\n const options = [\n { value: true, label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'), id: nanoid(6) },\n { value: false, label: get(props.parameters, ['instance', 'falseLabel'], 'No'), id: nanoid(6) },\n ];\n\n return (\n <FieldConnector<boolean>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const setOption = (value: string) => {\n setValue(value === 'true' ? true : false);\n };\n\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"boolean-editor\" alignItems=\"center\" marginTop=\"spacingS\">\n {options.map((item) => {\n const id = ['entity', field.id, field.locale, item.value, item.id].join('.');\n const checked = value === item.value;\n return (\n <Flex marginRight=\"spacingM\" key={id}>\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 </Flex>\n );\n })}\n {value !== undefined && (\n <TextLink\n as=\"button\"\n testId=\"boolean-editor-clear\"\n isDisabled={disabled}\n onClick={clearOption}>\n Clear\n </TextLink>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nBooleanEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["BooleanEditor","props","field","options","value","label","get","parameters","id","nanoid","React","FieldConnector","throttle","isInitiallyDisabled","disabled","setValue","setOption","clearOption","Flex","testId","alignItems","marginTop","map","item","locale","join","checked","marginRight","key","Radio","isDisabled","undefined","String","isChecked","onChange","e","target","TextLink","as","onClick","defaultProps"],"mappings":";;;;;;SA8BgBA,cAAcC;AAC5B,QAAM;AAAEC,IAAAA;AAAF,MAAYD,KAAlB;AAEA,QAAME,OAAO,GAAG,CACd;AAAEC,IAAAA,KAAK,EAAE,IAAT;AAAeC,IAAAA,KAAK,EAAEC,GAAG,CAACL,KAAK,CAACM,UAAP,EAAmB,CAAC,UAAD,EAAa,WAAb,CAAnB,EAA8C,KAA9C,CAAzB;AAA+EC,IAAAA,EAAE,EAAEC,MAAM,CAAC,CAAD;AAAzF,GADc,EAEd;AAAEL,IAAAA,KAAK,EAAE,KAAT;AAAgBC,IAAAA,KAAK,EAAEC,GAAG,CAACL,KAAK,CAACM,UAAP,EAAmB,CAAC,UAAD,EAAa,YAAb,CAAnB,EAA+C,IAA/C,CAA1B;AAAgFC,IAAAA,EAAE,EAAEC,MAAM,CAAC,CAAD;AAA1F,GAFc,CAAhB;AAKA,SACEC,aAAA,CAACC,cAAD;AACEC,IAAAA,QAAQ,EAAE;AACVV,IAAAA,KAAK,EAAEA;AACPW,IAAAA,mBAAmB,EAAEZ,KAAK,CAACY;GAH7B,EAIG,CAAC;AAAEC,IAAAA,QAAF;AAAYV,IAAAA,KAAZ;AAAmBW,IAAAA;AAAnB,GAAD;AACC,UAAMC,SAAS,GAAIZ,KAAD;AAChBW,MAAAA,QAAQ,CAACX,KAAK,KAAK,MAAV,GAAmB,IAAnB,GAA0B,KAA3B,CAAR;AACD,KAFD;;AAIA,UAAMa,WAAW,GAAG;AAClBF,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;;AAIA,WACEL,aAAA,CAACQ,IAAD;AAAMC,MAAAA,MAAM,EAAC;AAAiBC,MAAAA,UAAU,EAAC;AAASC,MAAAA,SAAS,EAAC;KAA5D,EACGlB,OAAO,CAACmB,GAAR,CAAaC,IAAD;AACX,YAAMf,EAAE,GAAG,CAAC,QAAD,EAAWN,KAAK,CAACM,EAAjB,EAAqBN,KAAK,CAACsB,MAA3B,EAAmCD,IAAI,CAACnB,KAAxC,EAA+CmB,IAAI,CAACf,EAApD,EAAwDiB,IAAxD,CAA6D,GAA7D,CAAX;AACA,YAAMC,OAAO,GAAGtB,KAAK,KAAKmB,IAAI,CAACnB,KAA/B;AACA,aACEM,aAAA,CAACQ,IAAD;AAAMS,QAAAA,WAAW,EAAC;AAAWC,QAAAA,GAAG,EAAEpB;OAAlC,EACEE,aAAA,CAACmB,KAAD;AACErB,QAAAA,EAAE,EAAEA;AACJsB,QAAAA,UAAU,EAAEhB;AACZV,QAAAA,KAAK,EAAEmB,IAAI,CAACnB,KAAL,KAAe2B,SAAf,GAA2B,EAA3B,GAAgCC,MAAM,CAACT,IAAI,CAACnB,KAAN;AAC7C6B,QAAAA,SAAS,EAAEP;AACXQ,QAAAA,QAAQ,EAAGC,CAAD;AACR,cAAIA,CAAC,CAACC,MAAF,CAASV,OAAb,EAAsB;AACpBV,YAAAA,SAAS,CAACmB,CAAC,CAACC,MAAF,CAAShC,KAAV,CAAT;AACD;AACF;OATH,EAUGmB,IAAI,CAAClB,KAVR,CADF,CADF;AAgBD,KAnBA,CADH,EAqBGD,KAAK,KAAK2B,SAAV,IACCrB,aAAA,CAAC2B,QAAD;AACEC,MAAAA,EAAE,EAAC;AACHnB,MAAAA,MAAM,EAAC;AACPW,MAAAA,UAAU,EAAEhB;AACZyB,MAAAA,OAAO,EAAEtB;KAJX,SAAA,CAtBJ,CADF;AAiCD,GA9CH,CADF;AAkDD;AAEDjB,aAAa,CAACwC,YAAd,GAA6B;AAC3B3B,EAAAA,mBAAmB,EAAE;AADM,CAA7B;;;;"}
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./field-editor-boolean.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./field-editor-boolean.cjs.development.js')
8
- }