From bd8c0de7b96345ef1b45d1ca26183637ff080844 Mon Sep 17 00:00:00 2001 From: Ilia Date: Mon, 2 Sep 2024 12:30:23 +0200 Subject: [PATCH] feat: add select widget (#35849) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description https://github.com/user-attachments/assets/7516bcd8-7746-485a-a49d-bd19b22833d0 Fixes #35824 > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.All" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 58d40f7826f125778734f5fda93499e3b78dfcfa > Cypress dashboard. > Tags: `@tag.All` > Spec: >
Mon, 02 Sep 2024 10:15:26 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Introduced the `WDSSelectWidget`, enhancing widget options within the application. - Added configuration files to support autocomplete, validation, and property management for the new select widget. - Added new icons and thumbnails for input fields, improving UI component availability. - **Improvements** - Streamlined the `Select` component for better usability and clarity. - Enhanced type definitions for better type safety and clarity in widget configuration. - Improved SVG structures for icons and thumbnails, enhancing visual representation. - Adjusted styles for the `Select` component, ensuring consistent sizing and improved icon alignment. - **Documentation** - Added central export for configuration modules, simplifying access to widget settings. - Updated stories to include new icons and thumbnails, enriching documentation resources. - **Bug Fixes** - Improved validation logic for default options and custom options to ensure data integrity. - **Chores** - Reorganized import statements for better readability and maintainability across widget files. - Updated TypeScript configuration for improved module handling. --------- Co-authored-by: vadim Co-authored-by: Pawan Kumar --- .../src/components/Select/src/Select.tsx | 22 +- .../src/components/Select/src/index.ts | 1 + .../components/Select/src/styles.module.css | 7 +- .../src/components/Select/src/types.ts | 6 +- .../propertyControls/KeyValueComponent.tsx | 2 + .../constants/PropertyControlConstants.tsx | 14 +- .../entityReducers/canvasWidgetsReducer.ts | 20 + app/client/src/widgets/index.ts | 2 + .../wds/WDSSelectWidget/config/anvilConfig.ts | 11 + .../config/autocompleteConfig.ts | 11 + .../WDSSelectWidget/config/defaultsConfig.ts | 20 + .../WDSSelectWidget/config/featuresConfig.ts | 6 + .../wds/WDSSelectWidget/config/index.ts | 7 + .../wds/WDSSelectWidget/config/metaConfig.ts | 8 + .../WDSSelectWidget/config/methodsConfig.ts | 21 + .../propertyPaneConfig/contentConfig.ts | 465 ++++++++++++++++++ .../config/propertyPaneConfig/index.ts | 1 + .../validations/defaultOptionValidation.ts | 67 +++ .../propertyPaneConfig/validations/index.ts | 2 + .../validations/optionsCustomValidation.ts | 127 +++++ .../WDSSelectWidget/config/settersConfig.ts | 16 + .../src/widgets/wds/WDSSelectWidget/index.ts | 3 + .../wds/WDSSelectWidget/widget/helpers.ts | 16 + .../wds/WDSSelectWidget/widget/index.tsx | 175 +++++++ .../wds/WDSSelectWidget/widget/types.ts | 13 + app/client/src/widgets/wds/constants.ts | 1 + 26 files changed, 1029 insertions(+), 15 deletions(-) create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/anvilConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/autocompleteConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/defaultsConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/featuresConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/index.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/metaConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/methodsConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/propertyPaneConfig/contentConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/propertyPaneConfig/index.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/propertyPaneConfig/validations/defaultOptionValidation.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/propertyPaneConfig/validations/index.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/propertyPaneConfig/validations/optionsCustomValidation.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/config/settersConfig.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/index.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/widget/helpers.ts create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/widget/index.tsx create mode 100644 app/client/src/widgets/wds/WDSSelectWidget/widget/types.ts diff --git a/app/client/packages/design-system/widgets/src/components/Select/src/Select.tsx b/app/client/packages/design-system/widgets/src/components/Select/src/Select.tsx index 50171e79909..4a7b3c7342c 100644 --- a/app/client/packages/design-system/widgets/src/components/Select/src/Select.tsx +++ b/app/client/packages/design-system/widgets/src/components/Select/src/Select.tsx @@ -1,19 +1,19 @@ -import React, { useRef } from "react"; -import clsx from "clsx"; +import { Icon, Label, Popover, Spinner, Text } from "@appsmith/wds"; import { getTypographyClassName } from "@appsmith/wds-theming"; +import clsx from "clsx"; +import React, { useRef } from "react"; import { Button, - ListBox, + FieldError, Select as HeadlessSelect, + ListBox, SelectValue, - FieldError, } from "react-aria-components"; -import { Text, Icon, Spinner, Popover, Label } from "@appsmith/wds"; import { ListBoxItem } from "./ListBoxItem"; import styles from "./styles.module.css"; import type { SelectProps } from "./types"; -export const Select = (props: SelectProps) => { +export const Select = (props: SelectProps) => { const { contextualHelp, description, @@ -53,7 +53,15 @@ export const Select = (props: SelectProps) => { styles.fieldValue, getTypographyClassName("body"), )} - /> + > + {({ defaultChildren, isPlaceholder }) => { + if (isPlaceholder) { + return props.placeholder; + } + + return defaultChildren; + }} + {!Boolean(isLoading) && } {Boolean(isLoading) && } diff --git a/app/client/packages/design-system/widgets/src/components/Select/src/index.ts b/app/client/packages/design-system/widgets/src/components/Select/src/index.ts index b6e8a07c267..b252bd3f677 100644 --- a/app/client/packages/design-system/widgets/src/components/Select/src/index.ts +++ b/app/client/packages/design-system/widgets/src/components/Select/src/index.ts @@ -1 +1,2 @@ export * from "./Select"; +export type { SelectProps } from "./types"; diff --git a/app/client/packages/design-system/widgets/src/components/Select/src/styles.module.css b/app/client/packages/design-system/widgets/src/components/Select/src/styles.module.css index 75f563e2eb3..10412f1d14a 100644 --- a/app/client/packages/design-system/widgets/src/components/Select/src/styles.module.css +++ b/app/client/packages/design-system/widgets/src/components/Select/src/styles.module.css @@ -8,6 +8,7 @@ display: flex; position: relative; padding: 0; + height: var(--sizing-9); border: none; align-items: center; border-radius: var(--border-radius-elevation-3); @@ -43,7 +44,7 @@ .textField [data-icon] { position: absolute; - right: var(--inner-spacing-2); + right: var(--inner-spacing-1); } .necessityIndicator { @@ -66,6 +67,10 @@ flex: 1; } +.fieldValue[data-placeholder] { + color: var(--color-fg-neutral-subtle); +} + .fieldValue [data-icon] { display: none; } diff --git a/app/client/packages/design-system/widgets/src/components/Select/src/types.ts b/app/client/packages/design-system/widgets/src/components/Select/src/types.ts index c3220aa5b05..4e88e56cac3 100644 --- a/app/client/packages/design-system/widgets/src/components/Select/src/types.ts +++ b/app/client/packages/design-system/widgets/src/components/Select/src/types.ts @@ -5,10 +5,10 @@ import type { } from "react-aria-components"; import type { IconProps, SIZES } from "@appsmith/wds"; -export interface SelectProps - extends Omit, "slot"> { +export interface SelectProps + extends Omit, "slot"> { /** Item objects in the collection. */ - items: Iterable; + items: SelectItem[]; /** The content to display as the label. */ label?: string; /** The content to display as the description. */ diff --git a/app/client/src/components/propertyControls/KeyValueComponent.tsx b/app/client/src/components/propertyControls/KeyValueComponent.tsx index 0ec815db0ec..a2f3add9a92 100644 --- a/app/client/src/components/propertyControls/KeyValueComponent.tsx +++ b/app/client/src/components/propertyControls/KeyValueComponent.tsx @@ -214,6 +214,8 @@ export function KeyValueComponent(props: KeyValueComponentProps) { />