PromucFlow_constructor/app/client/src/components/propertyControls/StyledControls.tsx

406 lines
9.6 KiB
TypeScript
Raw Normal View History

import React, { RefObject, useEffect, useRef } from "react";
import { Classes, MenuItem, Menu } from "@blueprintjs/core";
2019-11-25 05:07:27 +00:00
import { ContainerOrientation } from "constants/WidgetConstants";
import { DateRangeInput } from "@blueprintjs/datetime";
2020-02-18 10:41:52 +00:00
import { Colors } from "constants/Colors";
import styled, { Skin } from "constants/DefaultTheme";
import { AnyStyledComponent } from "styled-components";
import { ControlIcons } from "icons/ControlIcons";
import { FormIcons } from "icons/FormIcons";
import Button from "components/ads/Button";
import TextInput, { TextInputProps } from "components/ads/TextInput";
import Dropdown from "components/ads/Dropdown";
import { InputWrapper } from "components/ads/TextInput";
2019-11-05 05:09:50 +00:00
type ControlWrapperProps = {
orientation?: ContainerOrientation;
isAction?: boolean;
2019-11-05 05:09:50 +00:00
};
export const ControlWrapper = styled.div<ControlWrapperProps>`
2020-12-24 04:32:25 +00:00
display: ${(props) =>
props.orientation === "HORIZONTAL" ? "flex" : "block"};
2019-11-07 10:33:04 +00:00
justify-content: space-between;
align-items: center;
2020-12-24 04:32:25 +00:00
flex-direction: ${(props) =>
2020-06-10 13:41:26 +00:00
props.orientation === "VERTICAL" ? "column" : "row"};
2020-12-24 04:32:25 +00:00
padding: ${(props) => (props.isAction ? "0" : "4px 0 ")};
& > label {
color: ${(props) => props.theme.colors.propertyPane.label};
2020-12-24 04:32:25 +00:00
margin-bottom: ${(props) => props.theme.spaces[1]}px;
font-size: ${(props) => props.theme.fontSizes[3]}px;
}
&&& > label:first-of-type {
display: block;
}
&&& > label {
display: inline-block;
2020-06-10 13:41:26 +00:00
}
feat: App Theming (#9714) * fix style bugs * fix select styles * test: fix font size issue for cypress tests * incorporate ashit feedback * test: addresed review comments for cypress tests * add analytics events * height issue in view mode * incorporate code review feedbacks * incorporate code review feedbacks * refactor: addressed review comments; removed border radius and box shadow for text widget; Updated migrations * feat: Makes shadow and radius controls keyboard accessible (#11547) * makes shadow and radius controls keyboard accessible * removes unused imports * moves options out of render method * fix: changed the misnomer background property name to the relevant property name * fix: border radius issue for the map widget * address qa bugs * address qa bugs * fix ux of theming pane when widget is selected * fix: * added backgroundColor to the video widget * restricted pop-over border radius to 0.375rem * added box shadow for the input group for select widget * fix: added delete icon in the delete theme modal * address qa bugs * change checkbox column size in config * add js convertible to button color * remove unused imports * test: fixed jest tests * fix primary color typo * fix: migrations for the theming * fix: * Removed background color from MultiTreeSelect and TreeSelect component. * grouped button's menu button pop over border radius restricting to 0.375rem. * test: updated Dsl migration UT * address qa bugs * address qa bugs * fix: address qa comments * address qa bugs * fix: * migration issue; * unit test cases; * fix rating widget scroll issue * fix youtube video border radius bug * fix select widget * fix select widgets styles * address qa bugs * merge conflicts * makes the reset button keyboard accessible (#12134) * -resolved merge conflicts * address qa bugs * fix: labelTextSize migration fixes * refactor: * made changes to the fontSizeUtils function * fixed the issue related to unit tests * fix button group widget * remove unused imports * fix: fixed the text size migration for the table widget * refactor: addressed review comments for the table widget theming migration * fix button group widget * add init calls for view mode * json form init theme changes * fix: added migration for boxShadow, borderRadius and textSizes for table widget * fix broken fields * test: fixed unit tests * wip * inconsistancy fixes and schemaItem update in updateHook/fieldConfiguration * feat: init json form migration theming * json form primaryColor -> accentColor * update table widget * update table widget * object field label styling * fix: migration related to the JSON form * fix: fixed labelTextSize migration for JSON form nested widgets * property control nested stylesheet lookup * JSONForm label styles form array items * show label for checkbox field array item * fix button group widget * wip * refactor: addressed table widget review comments * refactor: addressed ashit review comments; * added childStylesheet for widgets * feat: Keyboard navigable Color Picker control (#11797) * Makes ColorPicker keyboard accessible * seperate out keyboard and mouse interactions * fix issue with not focusing back to input * Adds test for Color picker * chore: added comment for the boxShadow property * fix: * added unit test cases for the widget and property utils * resolved warning messages * wip * theme config update * fix merge conflicts * refactor: moved theming migration inside the migrations folder * fix qa bugs * fix jest test * fix: unit test cases * fix table column creation logic * refactor: addressed review comments for migrations * fix: Overriding margin and padding for custom render in the dropdown component (#12875) * * fix for custom render padding and margin in ADS dropdown * * fix for removing padding from normal render options * refactor: moved the boxShadow condition to the variable * fix qa bugs * fix: migration QA callouts for audio recorder widget * refactor: added updated comments for boxShadow migration for table widget * fix theme binfings for JSONForm fields under Object * fix table widget theming bug * fix: addressed code review comments * fix: unit test cases * fix: qa migration callouts * fix table widget theming bug * fix JSONForm currency input dropdown not submit form * Added new tests - AppThemingSpec * fix qa bugs * fix unit test * fix JSONForm cellBorderWidth to have default value post migration * fix unit test * fix qa bugs * remove unused imports * fix qa bugs * fix JSONForm input height issue * fix qa bugs * Updating Theming spec * * dropdown color fixes (#13249) * fix caching issue ; * Fixed Theming tests * fix tests * fix tab widget tests * fix: json form children level migration issue * fix table widget tests * Updated test * updated tests * updated test * updated tests * updated tests * updated pageload * fix cypress tests * remove cypress created files * fix color picker issues * Failure fixes * Fixed some more tests * fix: cypress test failures * fix tests * remove consoles * fix table tests * fix qa bugs * updating snapshots for AppPageLayout_spec as per new UI * fix rating widget bug * fix qa bugs * fix: * cypress failing tests * Migration QA callouts * Removed unused imports * update constract check algo * fix color contrast issue * fix: cypress failure test cases * update font sizes labels * fix regression bugs * fix: * JSON form labelTextSize issue fix * Updated comment for the fontSizeUtility function * migrations issues related to table widget borderRadius and boxShadow * fix: default labelTextSize issue for the Input and Select families * fix regression bugs * fix regression bugs * PassingParams spec - added wait time * fix: font family default value issue on JS toggle * fix js toggle issue in text widget * fix tests * fix tests * fix tests * fix cypress tests * fix regression bugs * fix regression bugs * fix: * refactored table widget migration function as per review comments, * added default value to the widget * fix: failing unit test cases * fix theming spec * fix cypress tests * test: fixed failed cypress test * incorporate ashit feedback * fix cypress tests * fix: addressed review comments * comment out table cypress test * fix merge conflicts * comment out color picker tests Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: keyurparalkar <keyur@appsmith.com> Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: Nayan <nayan@appsmith.com> Co-authored-by: Ashit Rath <ashit@appsmith.com> Co-authored-by: balajisoundar <balaji@appsmith.com> Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: apple <nandan@thinkify.io> Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
2022-05-04 09:45:57 +00:00
&:focus-within .reset-button {
display: block;
}
`;
export const ControlPropertyLabelContainer = styled.div`
display: flex;
align-items: center;
2020-03-20 09:45:44 +00:00
label {
color: ${(props) => props.theme.colors.propertyPane.label};
2020-12-24 04:32:25 +00:00
margin-bottom: ${(props) => props.theme.spaces[1]}px;
font-size: ${(props) => props.theme.fontSizes[3]}px;
}
2020-03-20 09:45:44 +00:00
.underline {
2020-12-24 04:32:25 +00:00
color: ${(props) => props.theme.colors.paneTextUnderline};
2020-03-20 09:45:44 +00:00
}
`;
export const JSToggleButton = styled.button<{ active: boolean }>`
margin: 4px;
margin-top: 0px;
cursor: pointer;
height: auto;
width: 28px;
height: 16px;
border: 0.5px solid ${Colors.BLACK};
background-color: ${(props) =>
props.active ? Colors.GREY_10 : Colors.GREY_2};
&:hover {
background-color: ${(props) =>
props.active ? Colors.GREY_9 : Colors.GREY_3};
&&& svg {
path {
fill: ${(props) => (props.active ? Colors.GREY_2 : Colors.GREY_9)};
}
}
}
& > div {
display: flex;
align-items: center;
justify-content: center;
feat: Property pane dropdown overflow issues (#8236) * * hide subtext for date picker fix * EE clicking on entity, unfolding/folding added * * bug fixes in action dropdown * bug fix for cursor * fix: 8190 background api request and welcome helper button (#8281) * chore: Move action/js debugger tabs related logic to a common component (#8199) * removed background of api request textbox and added hover text on "no thanks" button Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> * fix: added scrolling in invited users more popup (#8226) * added scrolling in invited users more popup * always scrollbar displaying on invited users pan * fixed issue related with 8190 * updated cursor of invited users more * replace edit data source icon with remix icon (#8192) * * active text color * fix: dropdownlist props issue (#8322) * Commented failing JS tests (#8276) Co-authored-by: Yatin Chaubal <yatin.chaubal@gmail.com> * docs: Update ServerSetup.md (#8255) * Make port customizable from env variable (#8288) * fix: issue with string templates (#7848) * Remove bracket highlight on error * fix string template issue * using string template to join strings * fix breaking tests * fixed props pass issue Co-authored-by: yatinappsmith <84702014+yatinappsmith@users.noreply.github.com> Co-authored-by: Yatin Chaubal <yatin.chaubal@gmail.com> Co-authored-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com> Co-authored-by: Vinod <4994565+vnodecg@users.noreply.github.com> * * bug fixes * * bug fix * * test cases fix * - test case fix * * test fixes * * bug fix in test case Co-authored-by: haojin111 <63215848+haojin111@users.noreply.github.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: yatinappsmith <84702014+yatinappsmith@users.noreply.github.com> Co-authored-by: Yatin Chaubal <yatin.chaubal@gmail.com> Co-authored-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com> Co-authored-by: Vinod <4994565+vnodecg@users.noreply.github.com> Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2021-10-11 06:01:05 +00:00
cursor: pointer;
}
&&& svg {
width: 28px;
height: 16px;
transform: scale(1.4);
rect {
fill: transparent;
}
path {
2020-12-24 04:32:25 +00:00
fill: ${(props) =>
props.active ? props.theme.colors.GREY_2 : Colors.GREY_9};
}
}
`;
2020-02-18 10:41:52 +00:00
export const StyledDropDownContainer = styled.div`
width: 100%;
height: 100%;
`;
export const StyledDropDown = styled(Dropdown)`
background-color: ${(props) => props.theme.colors.propertyPane.buttonText};
box-shadow: none;
2020-02-18 10:41:52 +00:00
`;
2020-05-22 05:15:41 +00:00
export const StyledMenu = styled(Menu)`
&& {
background: ${(props) => props.theme.dropdown[Skin.LIGHT].background};
border-radius: unset;
2020-05-22 05:15:41 +00:00
}
.bp3-submenu .bp3-menu {
background: ${(props) => props.theme.dropdown[Skin.LIGHT].background};
2020-05-22 05:15:41 +00:00
}
`;
2020-02-20 15:03:14 +00:00
export const StyledMenuItem = styled(MenuItem)`
&&&&&& {
border-radius: 0;
background: ${(props) => props.theme.dropdown[Skin.LIGHT].background};
color: ${(props) => props.theme.dropdown[Skin.LIGHT].inActiveText};
2020-05-22 05:15:41 +00:00
padding: 4px 8px;
margin: 4px 0px;
2020-02-20 15:03:14 +00:00
&:hover {
background: ${(props) => props.theme.dropdown[Skin.LIGHT].hoverBG};
2020-04-22 09:15:24 +00:00
&&&.bp3-menu-item.bp3-intent-danger:hover {
color: ${(props) => props.theme.colors.error};
2020-04-22 09:15:24 +00:00
}
2020-02-20 15:03:14 +00:00
}
&.${Classes.ACTIVE} {
background: ${(props) => props.theme.dropdown[Skin.LIGHT].hoverBG};
2020-02-20 15:03:14 +00:00
position: relative;
&.single-select {
&:before {
left: 0;
top: -2px;
position: absolute;
content: "";
background: ${(props) => props.theme.dropdown[Skin.LIGHT].hoverBG};
border-radius: 0;
2020-02-20 15:03:14 +00:00
width: 4px;
height: 100%;
}
}
}
2020-05-22 05:15:41 +00:00
&&&& .${Classes.MENU} {
background: ${(props) => props.theme.dropdown[Skin.LIGHT].inActiveBG};
2020-05-22 05:15:41 +00:00
}
2020-02-20 15:03:14 +00:00
}
`;
2019-12-06 13:16:08 +00:00
export const StyledDynamicInput = styled.div`
2020-04-15 11:42:11 +00:00
width: 100%;
2019-12-06 13:16:08 +00:00
&&& {
input {
border: none;
2020-12-24 04:32:25 +00:00
color: ${(props) => props.theme.colors.textOnDarkBG};
background: ${(props) => props.theme.colors.paneInputBG};
2019-12-06 13:16:08 +00:00
&:focus {
border: none;
2020-12-24 04:32:25 +00:00
color: ${(props) => props.theme.colors.textOnDarkBG};
background: ${(props) => props.theme.colors.paneInputBG};
2019-12-06 13:16:08 +00:00
}
}
}
`;
const InputGroup = styled(TextInput)`
width: 100%;
border-radius: 0;
background-color: ${(props) => props.theme.colors.propertyPane.radioGroupBg};
color: ${(props) => props.theme.colors.propertyPane.radioGroupText};
&:focus {
box-shadow: none;
2020-03-20 11:03:50 +00:00
}
2019-11-07 10:33:04 +00:00
`;
const StyledInputWrapper = styled.div`
width: 100%;
&:focus ${InputWrapper} {
border: 1px solid var(--appsmith-input-focus-border-color);
}
`;
export const StyledInputGroup = React.forwardRef(
(props: TextInputProps, ref) => {
let inputRef = useRef<HTMLInputElement>(null);
const wrapperRef = useRef<HTMLInputElement>(null);
if (ref) inputRef = ref as RefObject<HTMLInputElement>;
useEffect(() => {
window.addEventListener("keydown", handleKeydown);
return () => {
window.removeEventListener("keydown", handleKeydown);
};
}, []);
const handleKeydown = (e: KeyboardEvent) => {
switch (e.key) {
case "Enter":
case " ":
if (document.activeElement === wrapperRef?.current) {
inputRef?.current?.focus();
e.preventDefault();
}
break;
case "Escape":
if (document.activeElement === inputRef?.current) {
wrapperRef?.current?.focus();
e.preventDefault();
}
break;
}
};
return (
<StyledInputWrapper ref={wrapperRef} tabIndex={0}>
<InputGroup ref={inputRef} {...props} tabIndex={-1} width="auto" />
</StyledInputWrapper>
);
},
);
StyledInputGroup.displayName = "StyledInputGroup";
export const StyledDateRangePicker = styled(DateRangeInput)`
> input {
2020-12-24 04:32:25 +00:00
color: ${(props) => props.theme.colors.textOnDarkBG};
background: ${(props) => props.theme.colors.paneInputBG};
border: 1px solid green;
}
`;
2020-05-22 05:15:41 +00:00
export const FieldWrapper = styled.div`
position: relative;
width: 100%;
`;
export const StyledEditIcon = styled(
ControlIcons.SETTINGS_CONTROL as AnyStyledComponent,
)`
padding: 0;
position: absolute;
margin-left: 0;
cursor: pointer;
right: 40px;
display: flex;
align-items: center;
&& svg {
width: 16px;
height: 16px;
position: relative;
path {
fill: ${(props) => props.theme.colors.propertyPane.iconColor};
}
}
`;
export const StyledDragIcon = styled(
ControlIcons.DRAG_CONTROL as AnyStyledComponent,
)`
padding: 0;
position: absolute;
margin-right: 15px;
cursor: move;
z-index: 1;
left: 4px;
&& svg {
width: 16px;
height: 16px;
position: relative;
top: 2px;
path {
fill: ${(props) => props.theme.colors.propertyPane.iconColor};
}
}
`;
export const StyledDeleteIcon = styled(
FormIcons.DELETE_ICON as AnyStyledComponent,
)`
padding: 0;
position: absolute;
margin-left: 15px;
cursor: pointer;
right: ${(props) => props.marginRight ?? 12}px;
display: flex;
align-items: center;
&& svg {
width: 16px;
height: 16px;
position: relative;
path {
fill: ${(props) => props.theme.colors.propertyPane.iconColor};
}
}
`;
export const FlexWrapper = styled.div`
display: flex;
`;
export const StyledVisibleIcon = styled(
ControlIcons.SHOW_COLUMN as AnyStyledComponent,
)`
padding: 0;
position: absolute;
margin-left: 15px;
cursor: pointer;
display: flex;
align-items: center;
right: ${(props) => props.marginRight ?? 12}px;
&& svg {
width: 16px;
height: 16px;
position: relative;
path {
fill: ${(props) => props.theme.colors.propertyPane.iconColor};
}
}
`;
export const StyledHiddenIcon = styled(
ControlIcons.HIDE_COLUMN as AnyStyledComponent,
)`
padding: 0;
position: absolute;
margin-left: 15px;
cursor: pointer;
right: ${(props) => props.marginRight ?? 12}px;
display: flex;
align-items: center;
&& svg {
width: 16px;
height: 16px;
position: relative;
path {
fill: ${(props) => props.theme.colors.propertyPane.iconColor};
}
}
`;
export const StyledPropertyPaneButton = styled(Button)`
margin-top: 4px;
margin-left: auto;
display: flex;
justify-content: flex-end;
border: 1px solid ${Colors.GREY_8};
&,
&:active {
border: 1px solid ${Colors.GREY_8};
color: ${Colors.GREY_8};
background-color: transparent;
}
&:hover {
border: 1px solid ${Colors.GREY_8};
color: ${Colors.GREY_8};
background-color: ${Colors};
}
&&& svg {
width: 14px;
height: 14px;
path {
fill: ${Colors.GREY_8};
stroke: ${Colors.GREY_8};
}
}
feat: JSON Form widget (#8472) * initial layout * updated parser to support nested array * array field rendering * changes * ts fix * minor revert FormWidget * modified schema structure * select and switch fields * added checkbox field * added RadioGroupField * partial DateField and defaults, typing refactoring * added label and field type change * minor ts changes * changes * modified widget/utils for nested panelConfig, modified schema to object approach * array/object label support * hide field configuration when children not present * added tooltip * field visibility option * disabled state * upgraded tslib, form initial values * custom field configuration - add/hide/edit * field configuration - label change * return input when field configuration reaches max depth * minor changes * form - scroll, fixedfooter, enitity defn and other minior changes * form title * unregister on unmount * fixes * zero state * fix field padding * patched updating form values, removed linting warnings * configured action buttons * minor fix * minor change * property pane - sort fields in field configuration * refactor include all properties * checkbox properties * date properties * refactor typings and radio group properties * switch, multselect, select, array, object properties * minor changes * default value * ts fixes * checkbox field properties implementation * date field prop implementation * switch field * select field and fix deep nested meta properties * multiselect implementation * minor change * input field implementation * fix position jump on field type change * initial accordian * field state property and auto-complete of JSONFormComputeControl * merge fixes * renamed FormBuilder to JSONForm * source data validation minor change * custom field default value fix * Editable keys for custom field * minor fixes * replaced useFieldArray with custom logic, added widget icon * array and object accordian with border/background styling * minor change * disabled states for array and objects * default value minor fix * form level styles * modified logic for isDisabled for array and object, added disabledWhenInvalid, exposed isValid to fieldState for text input, removed useDisableChildren * added isValid for all field types * fixed reset to default values * debounce form values update * minor change * minor change * fix crash - source data change multi-select to array, fix crash - change of options * fix positioning * detect date type in source data * fix crash - when object is passed to regex input field * fixed default sourceData path for fields * accodion keep children mounted on collapse * jest test for schemaParser * widget/helper and useRegisterFieldInvalid test * tests for property config helper and generatePanelPropertyConfig * fix input field validation not appearing * fix date field type detection * rename data -> formData * handle null/undefined field value change in sourceData * added null/undefined as valid values for defaultValue text field * auto detect email field * set formData default value on initial load * switch field inline positioning * field margin fix for row direction * select full width * fiex date field default value - out of range * fix any field type to array * array default value logic change * base cypress test changes * initial json form render cy test * key sanitization * fix fieldState update logic * required design, object/array background color, accordion changes, fix - add new custom field * minor change * cypress tests * fix date formatted value, field state cypress test * cypress - field properties test and fixes * rename test file * fix accessort change to blank value, cypress tests * fix array field default value for modified accessor * minor fix * added animate loading * fix empty state, add new custom field * test data fix * fix warnings * fix timePrecision visibility * button styling * ported input v2 * fix jest tests * fix cypress tests * perf changes * perf improvement * added comments * multiselect changes * input field perf refactor * array field, object field refactor performance * checkbox field refactor * refectored date, radio, select and switch * fixes * test fixes * fixes * minor fix * rename field renderer * remove tracked fieldRenderer field * cypress test fixes * cypress changes * array default value fixes * arrayfield passedDefaultValue * auto enabled JS mode for few properties, reverted swith and date property controls * cypress changes * added widget sniping mode and fixed object passedDefaultValue * multiselect v2 * select v2 * fix jest tests * test fixes * field limit * rename field type dropdown texts * field type changes fixes * jest fixes * loading state submit button * default source data for new widget * modify limit message * multiseelct default value changes and cypress fix * select default value * keep default value intact on field type change * TextTable cypress text fix * review changes * fixed footer changes * collapse styles section by default * fixed footer changes * form modes * custom field key rentention * fixed footer fix in view mode * non ascii characters * fix meta merge in dataTreeWidget * minor fixes * rename useRegisterFieldInvalid.ts -> useRegisterFieldValidity.ts * modified dependency injection into evaluated values * refactored fixedfooter logic * minor change * accessor update * minor change * fixes * QA fixes date field, scroll content * fix phone number field, removed visiblity option from array item * fix sourceData autocomplete * reset logic * fix multiselect reset * form values hydration on widget drag * code review changes * reverted order of merge dataTreeWidget * fixes * added button titles, fixed hydration issue * default value fixes * upgraded react hook form, modified array-level/field-level default value logic * fixed select validation * added icon entity explorer, modified icon align control * modify accessor validation for mongo db _id * update email field regex * review changes * explicitly handle empty source data validation
2022-03-24 07:13:25 +00:00
&:disabled {
background-color: ${Colors.GREY_1};
color: var(--appsmith-color-black-400);
border-color: ${Colors.MERCURY};
}
`;
export const StyledOptionControlInputGroup = styled(StyledInputGroup)`
width: 100%;
padding-left: 20px;
padding-right: 60px;
padding-bottom: 4px;
text-overflow: ellipsis;
background: inherit;
&&& {
input {
padding-left: 24px;
border: none;
color: ${(props) => props.theme.colors.textOnDarkBG};
&:focus {
border: none;
color: ${(props) => props.theme.colors.textOnDarkBG};
}
}
}
`;