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 { Alignment } from "@blueprintjs/core";
|
|
|
|
|
import type { IconName } from "@blueprintjs/icons";
|
|
|
|
|
import type { ButtonPlacement, ButtonVariant } from "components/constants";
|
|
|
|
|
import { ButtonPlacementTypes, ButtonVariantTypes } from "components/constants";
|
2023-03-04 07:25:54 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
|
|
|
|
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 { get } from "lodash";
|
|
|
|
|
import React from "react";
|
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 "widgets/BaseWidget";
|
|
|
|
|
import BaseWidget from "widgets/BaseWidget";
|
2022-02-24 08:21:45 +00:00
|
|
|
import { MinimumPopupRows } from "widgets/constants";
|
2023-03-04 07:25:54 +00:00
|
|
|
import ButtonGroupComponent from "../component";
|
2022-05-04 09:45:57 +00:00
|
|
|
import { getStylesheetValue } from "./helpers";
|
2023-04-14 06:27:49 +00:00
|
|
|
import { DefaultAutocompleteDefinitions } from "widgets/WidgetUtils";
|
|
|
|
|
import type { AutocompletionDefinitions } from "widgets/constants";
|
2021-11-11 06:41:05 +00:00
|
|
|
|
|
|
|
|
class ButtonGroupWidget extends BaseWidget<
|
|
|
|
|
ButtonGroupWidgetProps,
|
|
|
|
|
WidgetState
|
|
|
|
|
> {
|
2023-04-14 06:27:49 +00:00
|
|
|
static getAutocompleteDefinitions(): AutocompletionDefinitions {
|
|
|
|
|
return {
|
|
|
|
|
"!doc":
|
|
|
|
|
"The Button group widget represents a set of buttons in a group. Group can have simple buttons or menu buttons with drop-down items.",
|
|
|
|
|
"!url": "https://docs.appsmith.com/widget-reference/button-group",
|
|
|
|
|
isVisible: DefaultAutocompleteDefinitions.isVisible,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 08:05:46 +00:00
|
|
|
static getPropertyPaneContentConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Data",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText: "Group Buttons",
|
|
|
|
|
propertyName: "groupButtons",
|
|
|
|
|
controlType: "GROUP_BUTTONS",
|
|
|
|
|
label: "Buttons",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
dependencies: ["childStylesheet"],
|
|
|
|
|
panelConfig: {
|
|
|
|
|
editableTitle: true,
|
|
|
|
|
titlePropertyName: "label",
|
|
|
|
|
panelIdPropertyName: "id",
|
|
|
|
|
updateHook: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
propertyValue: string,
|
|
|
|
|
) => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
propertyPath,
|
|
|
|
|
propertyValue,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
contentChildren: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Data",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "buttonType",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Button type",
|
2022-10-20 14:06:32 +00:00
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText: "Sets button type",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Simple",
|
|
|
|
|
value: "SIMPLE",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Menu",
|
|
|
|
|
value: "MENU",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-07 11:03:22 +00:00
|
|
|
defaultValue: "SIMPLE",
|
2022-08-15 08:05:46 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: ["SIMPLE", "MENU"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
hidden: (
|
|
|
|
|
props: ButtonGroupWidgetProps,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
) => {
|
|
|
|
|
const buttonType = get(
|
|
|
|
|
props,
|
|
|
|
|
`${propertyPath.split(".", 2).join(".")}.buttonType`,
|
|
|
|
|
"",
|
|
|
|
|
);
|
|
|
|
|
return buttonType !== "MENU";
|
|
|
|
|
},
|
|
|
|
|
dependencies: ["groupButtons"],
|
2023-05-19 18:37:06 +00:00
|
|
|
helpText: "Menu items",
|
2022-08-15 08:05:46 +00:00
|
|
|
propertyName: "menuItems",
|
|
|
|
|
controlType: "MENU_ITEMS",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Menu items",
|
2022-08-15 08:05:46 +00:00
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
panelConfig: {
|
|
|
|
|
editableTitle: true,
|
|
|
|
|
titlePropertyName: "label",
|
|
|
|
|
panelIdPropertyName: "id",
|
|
|
|
|
updateHook: (
|
|
|
|
|
props: any,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
propertyValue: string,
|
|
|
|
|
) => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
propertyPath,
|
|
|
|
|
propertyValue,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
contentChildren: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Label",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
helpText: "Sets the label of a menu item",
|
|
|
|
|
label: "Text",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Enter label",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText:
|
|
|
|
|
"Controls the visibility of menu item",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.BOOLEAN,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
helpText: "Disables menu item",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.BOOLEAN,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Events",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2023-04-06 16:49:12 +00:00
|
|
|
helpText: "when the menu item is clicked",
|
2022-08-15 08:05:46 +00:00
|
|
|
propertyName: "onClick",
|
|
|
|
|
label: "onClick",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
styleChildren: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Icon",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconName",
|
|
|
|
|
label: "Icon",
|
|
|
|
|
helpText:
|
|
|
|
|
"Sets the icon to be used for a menu item",
|
|
|
|
|
controlType: "ICON_SELECT",
|
2022-10-26 09:45:30 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconAlign",
|
|
|
|
|
label: "Position",
|
|
|
|
|
helpText:
|
|
|
|
|
"Sets the icon alignment of a menu item",
|
|
|
|
|
controlType: "ICON_TABS",
|
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: "skip-left-line",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: "left",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
startIcon: "skip-right-line",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: "right",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-07 11:03:22 +00:00
|
|
|
defaultValue: "left",
|
2022-08-15 08:05:46 +00:00
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Color",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "backgroundColor",
|
|
|
|
|
helpText:
|
|
|
|
|
"Sets the background color of a menu item",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Background color",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconColor",
|
|
|
|
|
helpText: "Sets the icon color of a menu item",
|
|
|
|
|
label: "Icon Color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "textColor",
|
|
|
|
|
helpText: "Sets the text color of a menu item",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Text color",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Label",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "label",
|
|
|
|
|
helpText: "Sets the label of a menu item",
|
|
|
|
|
label: "Text",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
placeholderText: "Enter label",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
helpText: "Disables input to the widget",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Events",
|
|
|
|
|
hidden: (
|
|
|
|
|
props: ButtonGroupWidgetProps,
|
|
|
|
|
propertyPath: string,
|
|
|
|
|
) => {
|
|
|
|
|
const buttonType = get(
|
|
|
|
|
props,
|
|
|
|
|
`${propertyPath}.buttonType`,
|
|
|
|
|
"",
|
|
|
|
|
);
|
|
|
|
|
return buttonType === "MENU";
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2023-04-06 16:49:12 +00:00
|
|
|
helpText: "when the button is clicked",
|
2022-08-15 08:05:46 +00:00
|
|
|
propertyName: "onClick",
|
|
|
|
|
label: "onClick",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
styleChildren: [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Icon",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconName",
|
|
|
|
|
label: "Icon",
|
|
|
|
|
helpText: "Sets the icon to be used for a button",
|
|
|
|
|
controlType: "ICON_SELECT",
|
2022-12-06 17:32:43 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "iconAlign",
|
|
|
|
|
label: "Position",
|
|
|
|
|
helpText: "Sets the icon alignment of a button",
|
|
|
|
|
controlType: "ICON_TABS",
|
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: "skip-left-line",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: "left",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-05-19 18:37:06 +00:00
|
|
|
startIcon: "skip-right-line",
|
2022-08-15 08:05:46 +00:00
|
|
|
value: "right",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-07 11:03:22 +00:00
|
|
|
defaultValue: "left",
|
2022-08-15 08:05:46 +00:00
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "placement",
|
|
|
|
|
label: "Placement",
|
|
|
|
|
controlType: "DROP_DOWN",
|
|
|
|
|
helpText: "Sets the space between items",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Start",
|
|
|
|
|
value: ButtonPlacementTypes.START,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Between",
|
|
|
|
|
value: ButtonPlacementTypes.BETWEEN,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Center",
|
|
|
|
|
value: ButtonPlacementTypes.CENTER,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
defaultValue: ButtonPlacementTypes.CENTER,
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: [
|
|
|
|
|
ButtonPlacementTypes.START,
|
|
|
|
|
ButtonPlacementTypes.BETWEEN,
|
|
|
|
|
ButtonPlacementTypes.CENTER,
|
|
|
|
|
],
|
|
|
|
|
default: ButtonPlacementTypes.CENTER,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Color",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
getStylesheetValue,
|
|
|
|
|
propertyName: "buttonColor",
|
|
|
|
|
helpText: "Changes the color of the button",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Button color",
|
2022-08-15 08:05:46 +00:00
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
helpText: "Controls the visibility of the widget",
|
|
|
|
|
propertyName: "isVisible",
|
|
|
|
|
label: "Visible",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "isDisabled",
|
|
|
|
|
label: "Disabled",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Disables clicks 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 },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getPropertyPaneStyleConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "buttonVariant",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Button variant",
|
2022-10-20 14:06:32 +00:00
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText: "Sets the variant of the button",
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Primary",
|
|
|
|
|
value: ButtonVariantTypes.PRIMARY,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Secondary",
|
|
|
|
|
value: ButtonVariantTypes.SECONDARY,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Tertiary",
|
|
|
|
|
value: ButtonVariantTypes.TERTIARY,
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-07 11:03:22 +00:00
|
|
|
defaultValue: ButtonVariantTypes.PRIMARY,
|
2022-08-15 08:05:46 +00:00
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.TEXT,
|
|
|
|
|
params: {
|
|
|
|
|
allowedValues: [
|
|
|
|
|
ButtonVariantTypes.PRIMARY,
|
|
|
|
|
ButtonVariantTypes.SECONDARY,
|
|
|
|
|
ButtonVariantTypes.TERTIARY,
|
|
|
|
|
],
|
|
|
|
|
default: ButtonVariantTypes.PRIMARY,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Controls widget orientation",
|
|
|
|
|
propertyName: "orientation",
|
|
|
|
|
label: "Orientation",
|
2022-10-20 14:06:32 +00:00
|
|
|
controlType: "ICON_TABS",
|
|
|
|
|
fullWidth: true,
|
2022-08-15 08:05:46 +00:00
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: "Horizontal",
|
|
|
|
|
value: "horizontal",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Vertical",
|
|
|
|
|
value: "vertical",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-07 11:03:22 +00:00
|
|
|
defaultValue: "horizontal",
|
2022-08-15 08:05:46 +00:00
|
|
|
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 },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "boxShadow",
|
2023-05-19 18:37:06 +00:00
|
|
|
label: "Box shadow",
|
2022-08-15 08:05:46 +00:00
|
|
|
helpText:
|
|
|
|
|
"Enables you to cast a drop shadow from the frame of the widget",
|
|
|
|
|
controlType: "BOX_SHADOW_OPTIONS",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.TEXT },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 04:44:31 +00:00
|
|
|
static getStylesheetConfig(): Stylesheet {
|
|
|
|
|
return {
|
|
|
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
boxShadow: "none",
|
|
|
|
|
childStylesheet: {
|
|
|
|
|
button: {
|
|
|
|
|
buttonColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-20 08:51:54 +00:00
|
|
|
handleClick = (onClick: string | undefined, callback: () => void): void => {
|
2021-11-11 06:41:05 +00:00
|
|
|
if (onClick) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
dynamicString: onClick,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_CLICK,
|
2022-07-20 08:51:54 +00:00
|
|
|
callback,
|
2021-11-11 06:41:05 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
2022-02-24 08:21:45 +00:00
|
|
|
const { componentWidth } = this.getComponentDimensions();
|
2022-03-28 07:14:40 +00:00
|
|
|
const minPopoverWidth = MinimumPopupRows * this.props.parentColumnSpace;
|
2022-02-24 08:21:45 +00:00
|
|
|
|
2021-11-11 06:41:05 +00:00
|
|
|
return (
|
|
|
|
|
<ButtonGroupComponent
|
|
|
|
|
borderRadius={this.props.borderRadius}
|
|
|
|
|
boxShadow={this.props.boxShadow}
|
|
|
|
|
buttonClickHandler={this.handleClick}
|
2023-07-04 14:12:00 +00:00
|
|
|
buttonMinWidth={this.isAutoLayoutMode ? 120 : undefined}
|
2021-11-11 06:41:05 +00:00
|
|
|
buttonVariant={this.props.buttonVariant}
|
|
|
|
|
groupButtons={this.props.groupButtons}
|
|
|
|
|
isDisabled={this.props.isDisabled}
|
2023-07-04 14:12:00 +00:00
|
|
|
minHeight={this.isAutoLayoutMode ? this.props.minHeight : undefined}
|
2022-03-28 07:14:40 +00:00
|
|
|
minPopoverWidth={minPopoverWidth}
|
2021-11-11 06:41:05 +00:00
|
|
|
orientation={this.props.orientation}
|
2022-03-13 17:21:04 +00:00
|
|
|
renderMode={this.props.renderMode}
|
2022-03-28 07:14:40 +00:00
|
|
|
widgetId={this.props.widgetId}
|
2022-02-24 08:21:45 +00:00
|
|
|
width={componentWidth}
|
2021-11-11 06:41:05 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getWidgetType(): string {
|
|
|
|
|
return "BUTTON_GROUP_WIDGET";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ButtonGroupWidgetProps extends WidgetProps {
|
|
|
|
|
orientation: string;
|
|
|
|
|
isDisabled: boolean;
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius?: string;
|
|
|
|
|
boxShadow?: string;
|
2021-11-11 06:41:05 +00:00
|
|
|
buttonVariant: ButtonVariant;
|
|
|
|
|
groupButtons: Record<
|
|
|
|
|
string,
|
|
|
|
|
{
|
|
|
|
|
widgetId: string;
|
|
|
|
|
id: string;
|
|
|
|
|
index: number;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
label?: string;
|
|
|
|
|
buttonType?: string;
|
|
|
|
|
buttonColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Alignment;
|
2021-12-08 13:11:13 +00:00
|
|
|
placement?: ButtonPlacement;
|
2021-11-11 06:41:05 +00:00
|
|
|
onClick?: string;
|
|
|
|
|
menuItems: Record<
|
|
|
|
|
string,
|
|
|
|
|
{
|
|
|
|
|
widgetId: string;
|
|
|
|
|
id: string;
|
|
|
|
|
index: number;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
label?: string;
|
|
|
|
|
backgroundColor?: string;
|
|
|
|
|
textColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconColor?: string;
|
|
|
|
|
iconAlign?: Alignment;
|
|
|
|
|
onClick?: string;
|
|
|
|
|
}
|
|
|
|
|
>;
|
|
|
|
|
}
|
|
|
|
|
>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ButtonGroupWidget;
|