@contentful/field-editor-boolean 1.1.11 → 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.1.11",
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.1.8",
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.2.7"
47
+ "@contentful/field-editor-test-utils": "^1.4.0"
34
48
  },
35
49
  "peerDependencies": {
36
50
  "react": ">=16.8.0"
37
51
  },
38
- "gitHead": "4fff7b9534374dcc44cb477240d369fc34f46415"
52
+ "gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
39
53
  }
package/CHANGELOG.md DELETED
@@ -1,192 +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.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)
7
-
8
- **Note:** Version bump only for package @contentful/field-editor-boolean
9
-
10
- ## [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)
11
-
12
- **Note:** Version bump only for package @contentful/field-editor-boolean
13
-
14
- ## [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)
15
-
16
- **Note:** Version bump only for package @contentful/field-editor-boolean
17
-
18
- ## [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)
19
-
20
- **Note:** Version bump only for package @contentful/field-editor-boolean
21
-
22
- ## [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)
23
-
24
- **Note:** Version bump only for package @contentful/field-editor-boolean
25
-
26
- ## [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)
27
-
28
- **Note:** Version bump only for package @contentful/field-editor-boolean
29
-
30
- ## [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)
31
-
32
- **Note:** Version bump only for package @contentful/field-editor-boolean
33
-
34
- ## [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)
35
-
36
- **Note:** Version bump only for package @contentful/field-editor-boolean
37
-
38
- ## [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)
39
-
40
- **Note:** Version bump only for package @contentful/field-editor-boolean
41
-
42
- ## [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)
43
-
44
- ### Bug Fixes
45
-
46
- - bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
47
-
48
- ## [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)
49
-
50
- **Note:** Version bump only for package @contentful/field-editor-boolean
51
-
52
- # [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)
53
-
54
- ### Features
55
-
56
- - 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))
57
-
58
- ## [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)
59
-
60
- ### Bug Fixes
61
-
62
- - markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
63
-
64
- ## [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)
65
-
66
- **Note:** Version bump only for package @contentful/field-editor-boolean
67
-
68
- ## [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)
69
-
70
- ### Bug Fixes
71
-
72
- - **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))
73
-
74
- # [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)
75
-
76
- **Note:** Version bump only for package @contentful/field-editor-boolean
77
-
78
- # [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)
79
-
80
- ### Features
81
-
82
- - Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
83
-
84
- ### BREAKING CHANGES
85
-
86
- - adopts a new Forma v4 beta
87
-
88
- ## [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)
89
-
90
- **Note:** Version bump only for package @contentful/field-editor-boolean
91
-
92
- ## [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)
93
-
94
- **Note:** Version bump only for package @contentful/field-editor-boolean
95
-
96
- ## [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)
97
-
98
- **Note:** Version bump only for package @contentful/field-editor-boolean
99
-
100
- ## [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)
101
-
102
- **Note:** Version bump only for package @contentful/field-editor-boolean
103
-
104
- ## [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)
105
-
106
- **Note:** Version bump only for package @contentful/field-editor-boolean
107
-
108
- ## [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)
109
-
110
- **Note:** Version bump only for package @contentful/field-editor-boolean
111
-
112
- # [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)
113
-
114
- ### Features
115
-
116
- - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
117
-
118
- ## [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)
119
-
120
- **Note:** Version bump only for package @contentful/field-editor-boolean
121
-
122
- ## [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)
123
-
124
- **Note:** Version bump only for package @contentful/field-editor-boolean
125
-
126
- ## [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)
127
-
128
- **Note:** Version bump only for package @contentful/field-editor-boolean
129
-
130
- ## [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)
131
-
132
- **Note:** Version bump only for package @contentful/field-editor-boolean
133
-
134
- ## [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)
135
-
136
- **Note:** Version bump only for package @contentful/field-editor-boolean
137
-
138
- ## [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)
139
-
140
- **Note:** Version bump only for package @contentful/field-editor-boolean
141
-
142
- # [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)
143
-
144
- ### Features
145
-
146
- - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
147
-
148
- ## [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)
149
-
150
- **Note:** Version bump only for package @contentful/field-editor-boolean
151
-
152
- ## [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)
153
-
154
- **Note:** Version bump only for package @contentful/field-editor-boolean
155
-
156
- # [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)
157
-
158
- ### Features
159
-
160
- - 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))
161
-
162
- # [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)
163
-
164
- ### Features
165
-
166
- - 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))
167
-
168
- ## [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)
169
-
170
- ### Bug Fixes
171
-
172
- - clear button should respect disabled state ([#551](https://github.com/contentful/field-editors/issues/551)) ([a33c3ec](https://github.com/contentful/field-editors/commit/a33c3ec1f88753dfcea09fb62f5c1725fe379120))
173
-
174
- ## [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)
175
-
176
- **Note:** Version bump only for package @contentful/field-editor-boolean
177
-
178
- ## [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)
179
-
180
- **Note:** Version bump only for package @contentful/field-editor-boolean
181
-
182
- ## [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)
183
-
184
- **Note:** Version bump only for package @contentful/field-editor-boolean
185
-
186
- ## [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)
187
-
188
- **Note:** Version bump only for package @contentful/field-editor-boolean
189
-
190
- ## [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)
191
-
192
- **Note:** Version bump only for package @contentful/field-editor-boolean
@@ -1,75 +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 get = _interopDefault(require('lodash/get'));
9
- var nanoid = require('nanoid');
10
- var fieldEditorShared = require('@contentful/field-editor-shared');
11
- var f36Components = require('@contentful/f36-components');
12
-
13
- function BooleanEditor(props) {
14
- var field = props.field;
15
- var options = [{
16
- value: true,
17
- label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'),
18
- id: nanoid.nanoid(6)
19
- }, {
20
- value: false,
21
- label: get(props.parameters, ['instance', 'falseLabel'], 'No'),
22
- id: nanoid.nanoid(6)
23
- }];
24
- return React.createElement(fieldEditorShared.FieldConnector, {
25
- throttle: 0,
26
- field: field,
27
- isInitiallyDisabled: props.isInitiallyDisabled
28
- }, function (_ref) {
29
- var disabled = _ref.disabled,
30
- value = _ref.value,
31
- setValue = _ref.setValue;
32
-
33
- var setOption = function setOption(value) {
34
- setValue(value === 'true' ? true : false);
35
- };
36
-
37
- var clearOption = function clearOption() {
38
- setValue(null);
39
- };
40
-
41
- return React.createElement(f36Components.Flex, {
42
- testId: "boolean-editor",
43
- alignItems: "center",
44
- marginTop: "spacingS"
45
- }, options.map(function (item) {
46
- var id = ['entity', field.id, field.locale, item.value, item.id].join('.');
47
- var checked = value === item.value;
48
- return React.createElement(f36Components.Flex, {
49
- marginRight: "spacingM",
50
- key: id
51
- }, React.createElement(f36Components.Radio, {
52
- id: id,
53
- isDisabled: disabled,
54
- value: item.value === undefined ? '' : String(item.value),
55
- isChecked: checked,
56
- onChange: function onChange(e) {
57
- if (e.target.checked) {
58
- setOption(e.target.value);
59
- }
60
- }
61
- }, item.label));
62
- }), value !== undefined && React.createElement(f36Components.TextLink, {
63
- as: "button",
64
- testId: "boolean-editor-clear",
65
- isDisabled: disabled,
66
- onClick: clearOption
67
- }, "Clear"));
68
- });
69
- }
70
- BooleanEditor.defaultProps = {
71
- isInitiallyDisabled: true
72
- };
73
-
74
- exports.BooleanEditor = BooleanEditor;
75
- //# 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';\nimport get from 'lodash/get';\nimport { nanoid } from 'nanoid';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\n\nimport { TextLink, Flex, Radio } from '@contentful/f36-components';\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":";;;;;;;;;;;;SA6BgBA,cAAcC;AAC5B,MAAQC,KAAR,GAAkBD,KAAlB,CAAQC,KAAR;AAEA,MAAMC,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;QAAGC,gBAAAA;QAAUV,aAAAA;QAAOW,gBAAAA;;AACnB,QAAMC,SAAS,GAAG,SAAZA,SAAY,CAACZ,KAAD;AAChBW,MAAAA,QAAQ,CAACX,KAAK,KAAK,MAAV,GAAmB,IAAnB,GAA0B,KAA3B,CAAR;AACD,KAFD;;AAIA,QAAMa,WAAW,GAAG,SAAdA,WAAc;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,CAAY,UAACC,IAAD;AACX,UAAMf,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,UAAMC,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,EAAE,kBAACC,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=(e=require("lodash/get"))&&"object"==typeof e&&"default"in e?e.default:e,i=require("nanoid"),l=require("@contentful/field-editor-shared"),n=require("@contentful/f36-components");function r(e){var r=e.field,o=[{value:!0,label:a(e.parameters,["instance","trueLabel"],"Yes"),id:i.nanoid(6)},{value:!1,label:a(e.parameters,["instance","falseLabel"],"No"),id:i.nanoid(6)}];return t.createElement(l.FieldConnector,{throttle:0,field:r,isInitiallyDisabled:e.isInitiallyDisabled},(function(e){var a=e.disabled,i=e.value,l=e.setValue;return t.createElement(n.Flex,{testId:"boolean-editor",alignItems:"center",marginTop:"spacingS"},o.map((function(e){var o=["entity",r.id,r.locale,e.value,e.id].join("."),d=i===e.value;return t.createElement(n.Flex,{marginRight:"spacingM",key:o},t.createElement(n.Radio,{id:o,isDisabled:a,value:void 0===e.value?"":String(e.value),isChecked:d,onChange:function(e){e.target.checked&&function(e){l("true"===e)}(e.target.value)}},e.label))})),void 0!==i&&t.createElement(n.TextLink,{as:"button",testId:"boolean-editor-clear",isDisabled:a,onClick:function(){l(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';\nimport get from 'lodash/get';\nimport { nanoid } from 'nanoid';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\n\nimport { TextLink, Flex, Radio } from '@contentful/f36-components';\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":"0RA6BgBA,EAAcC,OACpBC,EAAUD,EAAVC,MAEFC,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,sBAC1B,gBAAGC,IAAAA,SAAUV,IAAAA,MAAOW,IAAAA,gBAUjBL,gBAACM,QAAKC,OAAO,iBAAiBC,WAAW,SAASC,UAAU,YACzDhB,EAAQiB,KAAI,SAACC,OACNb,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,SAAU,SAACC,GACLA,EAAEC,OAAOV,SArBT,SAACpB,GACjBW,EAAmB,SAAVX,GAqBK+B,CAAUF,EAAEC,OAAO9B,SAGtBiB,EAAKhB,gBAKHwB,IAAVzB,GACCM,gBAAC0B,YACCC,GAAG,SACHpB,OAAO,uBACPW,WAAYd,EACZwB,QA/BY,WAClBvB,EAAS,qBAyCnBf,EAAcuC,aAAe,CAC3B1B,qBAAqB"}
@@ -1,69 +0,0 @@
1
- import { createElement } from 'react';
2
- import get from 'lodash-es/get';
3
- import { nanoid } from 'nanoid';
4
- import { FieldConnector } from '@contentful/field-editor-shared';
5
- import { Flex, Radio, TextLink } from '@contentful/f36-components';
6
-
7
- function BooleanEditor(props) {
8
- var field = props.field;
9
- var options = [{
10
- value: true,
11
- label: get(props.parameters, ['instance', 'trueLabel'], 'Yes'),
12
- id: nanoid(6)
13
- }, {
14
- value: false,
15
- label: get(props.parameters, ['instance', 'falseLabel'], 'No'),
16
- id: nanoid(6)
17
- }];
18
- return createElement(FieldConnector, {
19
- throttle: 0,
20
- field: field,
21
- isInitiallyDisabled: props.isInitiallyDisabled
22
- }, function (_ref) {
23
- var disabled = _ref.disabled,
24
- value = _ref.value,
25
- setValue = _ref.setValue;
26
-
27
- var setOption = function setOption(value) {
28
- setValue(value === 'true' ? true : false);
29
- };
30
-
31
- var clearOption = function clearOption() {
32
- setValue(null);
33
- };
34
-
35
- return createElement(Flex, {
36
- testId: "boolean-editor",
37
- alignItems: "center",
38
- marginTop: "spacingS"
39
- }, options.map(function (item) {
40
- var id = ['entity', field.id, field.locale, item.value, item.id].join('.');
41
- var checked = value === item.value;
42
- return createElement(Flex, {
43
- marginRight: "spacingM",
44
- key: id
45
- }, createElement(Radio, {
46
- id: id,
47
- isDisabled: disabled,
48
- value: item.value === undefined ? '' : String(item.value),
49
- isChecked: checked,
50
- onChange: function onChange(e) {
51
- if (e.target.checked) {
52
- setOption(e.target.value);
53
- }
54
- }
55
- }, item.label));
56
- }), value !== undefined && createElement(TextLink, {
57
- as: "button",
58
- testId: "boolean-editor-clear",
59
- isDisabled: disabled,
60
- onClick: clearOption
61
- }, "Clear"));
62
- });
63
- }
64
- BooleanEditor.defaultProps = {
65
- isInitiallyDisabled: true
66
- };
67
-
68
- export { BooleanEditor };
69
- //# 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';\nimport get from 'lodash/get';\nimport { nanoid } from 'nanoid';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\n\nimport { TextLink, Flex, Radio } from '@contentful/f36-components';\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":";;;;;;SA6BgBA,cAAcC;AAC5B,MAAQC,KAAR,GAAkBD,KAAlB,CAAQC,KAAR;AAEA,MAAMC,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;QAAGC,gBAAAA;QAAUV,aAAAA;QAAOW,gBAAAA;;AACnB,QAAMC,SAAS,GAAG,SAAZA,SAAY,CAACZ,KAAD;AAChBW,MAAAA,QAAQ,CAACX,KAAK,KAAK,MAAV,GAAmB,IAAnB,GAA0B,KAA3B,CAAR;AACD,KAFD;;AAIA,QAAMa,WAAW,GAAG,SAAdA,WAAc;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,CAAY,UAACC,IAAD;AACX,UAAMf,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,UAAMC,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,EAAE,kBAACC,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
- }