2023-03-04 07:25:54 +00:00
|
|
|
import { LabelPosition } from "components/constants";
|
2021-03-30 05:29:03 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { WidgetType } from "constants/WidgetConstants";
|
2021-07-26 05:50:46 +00:00
|
|
|
import { ValidationTypes } from "constants/WidgetValidation";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { Stylesheet } from "entities/AppTheming";
|
2023-03-04 07:25:54 +00:00
|
|
|
import React from "react";
|
2023-04-07 13:51:35 +00:00
|
|
|
import { isAutoLayout } from "utils/autoLayout/flexWidgetUtils";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { DerivedPropertiesMap } from "utils/WidgetFactory";
|
2022-05-25 11:33:33 +00:00
|
|
|
import { AlignWidgetTypes } from "widgets/constants";
|
2023-04-14 06:27:49 +00:00
|
|
|
import {
|
|
|
|
|
isAutoHeightEnabledForWidget,
|
|
|
|
|
DefaultAutocompleteDefinitions,
|
|
|
|
|
} from "widgets/WidgetUtils";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { WidgetProps, WidgetState } from "../../BaseWidget";
|
|
|
|
|
import BaseWidget from "../../BaseWidget";
|
2023-03-04 07:25:54 +00:00
|
|
|
import CheckboxComponent from "../component";
|
2023-04-14 06:27:49 +00:00
|
|
|
import type { AutocompletionDefinitions } from "widgets/constants";
|
2019-03-21 12:10:32 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
class CheckboxWidget extends BaseWidget<CheckboxWidgetProps, WidgetState> {
|
2023-04-14 06:27:49 +00:00
|
|
|
static getAutocompleteDefinitions(): AutocompletionDefinitions {
|
|
|
|
|
return {
|
|
|
|
|
"!doc":
|
|
|
|
|
"Checkbox is a simple UI widget you can use when you want users to make a binary choice",
|
|
|
|
|
"!url": "https://docs.appsmith.com/widget-reference/checkbox",
|
|
|
|
|
isVisible: DefaultAutocompleteDefinitions.isVisible,
|
|
|
|
|
isChecked: "bool",
|
|
|
|
|
isDisabled: "bool",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 08:05:46 +00:00
|
|
|
static getPropertyPaneContentConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Label",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
label: "Text",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
helpText: "Displays a label next to the widget",
|
|
|
|
|
placeholderText: "I agree to the T&C",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Sets the label position of the widget",
|
|
|
|
|
propertyName: "labelPosition",
|
|
|
|
|
label: "Position",
|
2022-10-20 14:06:32 +00:00
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{ label: "Left", value: LabelPosition.Left },
|
|
|
|
|
{ label: "Right", value: LabelPosition.Right },
|
|
|
|
|
],
|
2022-11-23 09:48:23 +00:00
|
|
|
defaultValue: LabelPosition.Left,
|
2022-08-15 08:05:46 +00:00
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "alignWidget",
|
|
|
|
|
helpText: "Sets the alignment of the widget",
|
|
|
|
|
label: "Alignment",
|
|
|
|
|
controlType: "LABEL_ALIGNMENT_OPTIONS",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2023-05-19 18:37:06 +00:00
|
|
|
fullWidth: false,
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
startIcon: "align-left",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: AlignWidgetTypes.LEFT,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
startIcon: "align-right",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: AlignWidgetTypes.RIGHT,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Validations",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isRequired",
|
|
|
|
|
label: "Required",
|
|
|
|
|
helpText: "Makes input to the widget mandatory",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "defaultCheckedState",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Default state",
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText: "Sets the default checked state of the widget",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Disables input to this widget",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "animateLoading",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Animate loading",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Controls the loading of the widget",
|
|
|
|
|
defaultValue: true,
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Events",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2023-04-06 16:49:12 +00:00
|
|
|
helpText: "when the check state is changed",
|
2022-08-15 08:05:46 +00:00
|
|
|
propertyName: "onCheckChange",
|
|
|
|
|
label: "onCheckChange",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getPropertyPaneStyleConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
sectionName: "Label styles",
|
2022-08-15 08:05:46 +00:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "labelTextColor",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Font color",
|
2022-10-20 14:06:32 +00:00
|
|
|
helpText: "Control the color of the label associated",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
regex: /^(?![<|{{]).+/,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "labelTextSize",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Font size",
|
2022-10-20 14:06:32 +00:00
|
|
|
helpText: "Control the font size of the label associated",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
defaultValue: "0.875rem",
|
2023-04-07 13:51:35 +00:00
|
|
|
hidden: isAutoLayout,
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "S",
|
|
|
|
|
value: "0.875rem",
|
|
|
|
|
subText: "0.875rem",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "M",
|
|
|
|
|
value: "1rem",
|
|
|
|
|
subText: "1rem",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "L",
|
|
|
|
|
value: "1.25rem",
|
|
|
|
|
subText: "1.25rem",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "XL",
|
|
|
|
|
value: "1.875rem",
|
|
|
|
|
subText: "1.875rem",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "XXL",
|
|
|
|
|
value: "3rem",
|
|
|
|
|
subText: "3rem",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "3XL",
|
|
|
|
|
value: "3.75rem",
|
|
|
|
|
subText: "3.75rem",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "labelStyle",
|
|
|
|
|
label: "Emphasis",
|
2022-10-20 14:06:32 +00:00
|
|
|
helpText: "Control if the label should be bold or italics",
|
2022-12-29 11:08:13 +00:00
|
|
|
controlType: "BUTTON_GROUP",
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
icon: "text-bold",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: "BOLD",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
icon: "text-italic",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: "ITALIC",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Color",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "accentColor",
|
|
|
|
|
helpText: "Sets the checked state color of the checkbox",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Accent color",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
sectionName: "Border and shadow",
|
2022-08-15 08:05:46 +00:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "borderRadius",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Border radius",
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText:
|
|
|
|
|
"Rounds the corners of the icon button's outer border edge",
|
|
|
|
|
controlType: "BORDER_RADIUS_OPTIONS",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 16:15:09 +00:00
|
|
|
static getDefaultPropertiesMap(): Record<string, string> {
|
|
|
|
|
return {
|
|
|
|
|
isChecked: "defaultCheckedState",
|
|
|
|
|
};
|
2020-03-13 07:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 12:04:38 +00:00
|
|
|
static getDerivedPropertiesMap(): DerivedPropertiesMap {
|
|
|
|
|
return {
|
2021-02-16 12:15:17 +00:00
|
|
|
value: `{{!!this.isChecked}}`,
|
2020-11-26 11:21:23 +00:00
|
|
|
isValid: `{{ this.isRequired ? !!this.isChecked : true }}`,
|
2020-06-09 12:04:38 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 16:15:09 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {
|
2020-04-21 07:54:23 +00:00
|
|
|
isChecked: undefined,
|
2022-03-01 19:02:10 +00:00
|
|
|
isDirty: false,
|
2020-04-17 16:15:09 +00:00
|
|
|
};
|
2020-03-13 07:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-28 04:44:31 +00:00
|
|
|
static getStylesheetConfig(): Stylesheet {
|
|
|
|
|
return {
|
|
|
|
|
accentColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
feat: Internal property to detect changes in a form
-- Implement dirty check logic for a form
-- Expose an form property, hasChanges for checking if the user has changed any values in the form
-- Add isDirty derived property for the following widgets: AudioRecorderWidget, CameraWidget, CheckboxGroupWidget, CheckboxWidget, CurrencyInputWidget, DatePickerWidget2, FilePickerWidgetV2, InputWidgetV2, MultiSelectTreeWidget, MultiSelectWidgetV2, PhoneInputWidget, RadioGroupWidget, RichTextEditorWidget, SelectWidget, SingleSelectTreeWidget, SwitchGroupWidget, SwitchWidget
2022-02-23 08:03:51 +00:00
|
|
|
componentDidUpdate(prevProps: CheckboxWidgetProps) {
|
2022-03-01 19:02:10 +00:00
|
|
|
if (
|
|
|
|
|
this.props.defaultCheckedState !== prevProps.defaultCheckedState &&
|
|
|
|
|
this.props.isDirty
|
|
|
|
|
) {
|
feat: Internal property to detect changes in a form
-- Implement dirty check logic for a form
-- Expose an form property, hasChanges for checking if the user has changed any values in the form
-- Add isDirty derived property for the following widgets: AudioRecorderWidget, CameraWidget, CheckboxGroupWidget, CheckboxWidget, CurrencyInputWidget, DatePickerWidget2, FilePickerWidgetV2, InputWidgetV2, MultiSelectTreeWidget, MultiSelectWidgetV2, PhoneInputWidget, RadioGroupWidget, RichTextEditorWidget, SelectWidget, SingleSelectTreeWidget, SwitchGroupWidget, SwitchWidget
2022-02-23 08:03:51 +00:00
|
|
|
this.props.updateWidgetMetaProperty("isDirty", false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 12:10:32 +00:00
|
|
|
getPageView() {
|
|
|
|
|
return (
|
|
|
|
|
<CheckboxComponent
|
2022-05-04 09:45:57 +00:00
|
|
|
accentColor={this.props.accentColor}
|
2021-02-16 12:15:17 +00:00
|
|
|
alignWidget={this.props.alignWidget}
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius={this.props.borderRadius}
|
2021-04-28 10:28:39 +00:00
|
|
|
isChecked={!!this.props.isChecked}
|
2019-10-31 09:04:19 +00:00
|
|
|
isDisabled={this.props.isDisabled}
|
2022-11-23 09:48:23 +00:00
|
|
|
isDynamicHeightEnabled={isAutoHeightEnabledForWidget(this.props)}
|
2023-07-04 14:12:00 +00:00
|
|
|
isLabelInline={this.isAutoLayoutMode}
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading={this.props.isLoading}
|
2021-04-28 10:28:39 +00:00
|
|
|
isRequired={this.props.isRequired}
|
|
|
|
|
key={this.props.widgetId}
|
|
|
|
|
label={this.props.label}
|
2022-05-25 11:33:33 +00:00
|
|
|
labelPosition={this.props.labelPosition}
|
|
|
|
|
labelStyle={this.props.labelStyle}
|
|
|
|
|
labelTextColor={this.props.labelTextColor}
|
|
|
|
|
labelTextSize={this.props.labelTextSize}
|
2023-07-04 14:12:00 +00:00
|
|
|
minHeight={this.props.minHeight}
|
2021-04-28 10:28:39 +00:00
|
|
|
onCheckChange={this.onCheckChange}
|
|
|
|
|
widgetId={this.props.widgetId}
|
2019-03-21 12:10:32 +00:00
|
|
|
/>
|
2019-09-09 09:08:54 +00:00
|
|
|
);
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-31 09:04:19 +00:00
|
|
|
onCheckChange = (isChecked: boolean) => {
|
2022-03-01 19:02:10 +00:00
|
|
|
if (!this.props.isDirty) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("isDirty", true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 16:47:16 +00:00
|
|
|
this.props.updateWidgetMetaProperty("isChecked", isChecked, {
|
2021-04-23 13:50:55 +00:00
|
|
|
triggerPropertyName: "onCheckChange",
|
2020-10-06 16:47:16 +00:00
|
|
|
dynamicString: this.props.onCheckChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CHECK_CHANGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
2019-10-31 09:04:19 +00:00
|
|
|
};
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
static getWidgetType(): WidgetType {
|
2019-09-13 10:45:49 +00:00
|
|
|
return "CHECKBOX_WIDGET";
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
export interface CheckboxWidgetProps extends WidgetProps {
|
2019-09-13 10:45:49 +00:00
|
|
|
label: string;
|
|
|
|
|
defaultCheckedState: boolean;
|
2019-10-31 09:04:19 +00:00
|
|
|
isChecked?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
2020-02-18 10:41:52 +00:00
|
|
|
onCheckChange?: string;
|
2020-11-26 11:21:23 +00:00
|
|
|
isRequired?: boolean;
|
2022-05-04 09:45:57 +00:00
|
|
|
accentColor: string;
|
|
|
|
|
borderRadius: string;
|
2022-05-25 11:33:33 +00:00
|
|
|
alignWidget: AlignWidgetTypes;
|
|
|
|
|
labelPosition: LabelPosition;
|
|
|
|
|
labelTextColor?: string;
|
|
|
|
|
labelTextSize?: string;
|
|
|
|
|
labelStyle?: string;
|
2019-03-21 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default CheckboxWidget;
|