feat: Consistent styling for widgets disabled state (#6983)
* checkbox and button default styling * rate widget disabled styling * added cursor: not-allowed to disable css
This commit is contained in:
parent
61eaaf1aab
commit
39aa4e6d8d
|
|
@ -1,10 +1,10 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { Checkbox } from "@blueprintjs/core";
|
|
||||||
|
|
||||||
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
||||||
import { ThemeProp } from "components/ads/common";
|
|
||||||
import { generateReactKey } from "utils/generators";
|
import { generateReactKey } from "utils/generators";
|
||||||
|
import { StyledCheckbox } from "components/designSystems/blueprint/CheckboxComponent";
|
||||||
|
import { ThemeProp } from "components/ads/common";
|
||||||
|
|
||||||
export interface CheckboxGroupContainerProps {
|
export interface CheckboxGroupContainerProps {
|
||||||
inline?: boolean;
|
inline?: boolean;
|
||||||
|
|
@ -33,25 +33,6 @@ const CheckboxGroupContainer = styled.div<
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export interface StyledCheckboxProps {
|
|
||||||
disabled?: boolean;
|
|
||||||
rowspace: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const StyledCheckbox = styled(Checkbox)<ThemeProp & StyledCheckboxProps>`
|
|
||||||
height: ${({ rowspace }) => rowspace}px;
|
|
||||||
|
|
||||||
&.bp3-control input:checked ~ .bp3-control-indicator {
|
|
||||||
box-shadow: none;
|
|
||||||
background-image: none;
|
|
||||||
background-color: #03b365;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.bp3-control.bp3-checkbox .bp3-control-indicator {
|
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export interface OptionProps {
|
export interface OptionProps {
|
||||||
/** Label text for this option. If omitted, `value` is used as the label. */
|
/** Label text for this option. If omitted, `value` is used as the label. */
|
||||||
label?: string;
|
label?: string;
|
||||||
|
|
@ -70,7 +51,6 @@ export interface CheckboxGroupComponentProps extends ComponentProps {
|
||||||
rowSpace: number;
|
rowSpace: number;
|
||||||
selectedValues: string[];
|
selectedValues: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckboxGroupComponent(props: CheckboxGroupComponentProps) {
|
function CheckboxGroupComponent(props: CheckboxGroupComponentProps) {
|
||||||
const {
|
const {
|
||||||
isDisabled,
|
isDisabled,
|
||||||
|
|
@ -94,7 +74,7 @@ function CheckboxGroupComponent(props: CheckboxGroupComponentProps) {
|
||||||
key={generateReactKey()}
|
key={generateReactKey()}
|
||||||
label={option.label}
|
label={option.label}
|
||||||
onChange={onChange(option.value)}
|
onChange={onChange(option.value)}
|
||||||
rowspace={rowSpace}
|
rowSpace={rowSpace}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</CheckboxGroupContainer>
|
</CheckboxGroupContainer>
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,65 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
|
||||||
import { Alignment, Checkbox, Classes } from "@blueprintjs/core";
|
import { Alignment, Checkbox, Classes } from "@blueprintjs/core";
|
||||||
import { BlueprintControlTransform } from "constants/DefaultTheme";
|
|
||||||
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
||||||
import { AlignWidget } from "widgets/SwitchWidget";
|
import { AlignWidget } from "widgets/SwitchWidget";
|
||||||
|
|
||||||
const CheckboxContainer = styled.div<{ isValid: boolean }>`
|
type StyledCheckboxProps = {
|
||||||
|
rowSpace: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type StyledCheckboxContainerProps = {
|
||||||
|
isValid: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const CheckboxContainer = styled.div<StyledCheckboxContainerProps>`
|
||||||
&& {
|
&& {
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-start;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: flex-start;
|
||||||
|
width: 100%;
|
||||||
&.${Alignment.RIGHT} {
|
&.${Alignment.RIGHT} {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
.bp3-control-indicator {
|
|
||||||
|
& .bp3-control-indicator {
|
||||||
border: ${(props) =>
|
border: ${(props) =>
|
||||||
!props.isValid
|
!props.isValid && `1px solid ${props.theme.colors.error} !important`};
|
||||||
? `1px solid ${props.theme.colors.error} !important`
|
}
|
||||||
: `1px solid transparent`};
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const StyledCheckbox = styled(Checkbox)<StyledCheckboxProps>`
|
||||||
|
height: ${({ rowSpace }) => rowSpace}px;
|
||||||
|
|
||||||
|
&.bp3-control input:checked ~ .bp3-control-indicator {
|
||||||
|
background-color: #03b365;
|
||||||
|
background-image: none;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
&.bp3-control input:disabled ~ .bp3-control-indicator {
|
||||||
margin: 0;
|
opacity: 0.5;
|
||||||
color: ${(props) =>
|
|
||||||
!props.isValid ? `${props.theme.colors.error}` : `inherit`};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.bp3-control.bp3-checkbox .bp3-control-indicator {
|
||||||
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
${BlueprintControlTransform}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
class CheckboxComponent extends React.Component<CheckboxComponentProps> {
|
class CheckboxComponent extends React.Component<CheckboxComponentProps> {
|
||||||
render() {
|
render() {
|
||||||
const checkboxAlignClass =
|
const checkboxAlignClass =
|
||||||
this.props.alignWidget === "RIGHT" ? Alignment.RIGHT : Alignment.LEFT;
|
this.props.alignWidget === "RIGHT" ? Alignment.RIGHT : Alignment.LEFT;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CheckboxContainer
|
<CheckboxContainer
|
||||||
className={checkboxAlignClass}
|
className={checkboxAlignClass}
|
||||||
isValid={!(this.props.isRequired && !this.props.isChecked)}
|
isValid={!(this.props.isRequired && !this.props.isChecked)}
|
||||||
>
|
>
|
||||||
<Checkbox
|
<StyledCheckbox
|
||||||
alignIndicator={checkboxAlignClass}
|
alignIndicator={checkboxAlignClass}
|
||||||
checked={this.props.isChecked}
|
checked={this.props.isChecked}
|
||||||
className={
|
className={
|
||||||
|
|
@ -48,7 +68,7 @@ class CheckboxComponent extends React.Component<CheckboxComponentProps> {
|
||||||
disabled={this.props.isDisabled}
|
disabled={this.props.isDisabled}
|
||||||
label={this.props.label}
|
label={this.props.label}
|
||||||
onChange={this.onCheckChange}
|
onChange={this.onCheckChange}
|
||||||
style={{ borderRadius: 0 }}
|
rowSpace={this.props.rowSpace}
|
||||||
/>
|
/>
|
||||||
</CheckboxContainer>
|
</CheckboxContainer>
|
||||||
);
|
);
|
||||||
|
|
@ -60,12 +80,13 @@ class CheckboxComponent extends React.Component<CheckboxComponentProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CheckboxComponentProps extends ComponentProps {
|
export interface CheckboxComponentProps extends ComponentProps {
|
||||||
label: string;
|
alignWidget?: AlignWidget;
|
||||||
isChecked: boolean;
|
isChecked: boolean;
|
||||||
onCheckChange: (isChecked: boolean) => void;
|
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isRequired?: boolean;
|
isRequired?: boolean;
|
||||||
alignWidget?: AlignWidget;
|
label: string;
|
||||||
|
onCheckChange: (isChecked: boolean) => void;
|
||||||
|
rowSpace: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CheckboxComponent;
|
export default CheckboxComponent;
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ import styled from "styled-components";
|
||||||
import Rating from "react-rating";
|
import Rating from "react-rating";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
|
import TooltipComponent from "components/ads/Tooltip";
|
||||||
|
import { disable } from "constants/DefaultTheme";
|
||||||
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
||||||
import { RateSize, RATE_SIZES } from "constants/WidgetConstants";
|
import { RateSize, RATE_SIZES } from "constants/WidgetConstants";
|
||||||
import TooltipComponent from "components/ads/Tooltip";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Note:
|
Note:
|
||||||
|
|
@ -18,6 +19,7 @@ import TooltipComponent from "components/ads/Tooltip";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface RateContainerProps {
|
interface RateContainerProps {
|
||||||
|
isDisabled: boolean;
|
||||||
scrollable: boolean;
|
scrollable: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,6 +34,8 @@ export const RateContainer = styled.div<RateContainerProps>`
|
||||||
> span {
|
> span {
|
||||||
align-self: ${(props) => (props.scrollable ? "flex-start" : "center")};
|
align-self: ${(props) => (props.scrollable ? "flex-start" : "center")};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${({ isDisabled }) => isDisabled && disable}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Star = styled(Icon)`
|
export const Star = styled(Icon)`
|
||||||
|
|
@ -97,6 +101,7 @@ function RateComponent(props: RateComponentProps) {
|
||||||
bottomRow,
|
bottomRow,
|
||||||
inactiveColor,
|
inactiveColor,
|
||||||
isAllowHalf,
|
isAllowHalf,
|
||||||
|
isDisabled,
|
||||||
leftColumn,
|
leftColumn,
|
||||||
maxCount,
|
maxCount,
|
||||||
onValueChanged,
|
onValueChanged,
|
||||||
|
|
@ -122,7 +127,11 @@ function RateComponent(props: RateComponentProps) {
|
||||||
}, [leftColumn, rightColumn, topRow, bottomRow, maxCount, size]);
|
}, [leftColumn, rightColumn, topRow, bottomRow, maxCount, size]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RateContainer ref={rateContainerRef} scrollable={scrollable}>
|
<RateContainer
|
||||||
|
isDisabled={Boolean(isDisabled)}
|
||||||
|
ref={rateContainerRef}
|
||||||
|
scrollable={scrollable}
|
||||||
|
>
|
||||||
<Rating
|
<Rating
|
||||||
emptySymbol={
|
emptySymbol={
|
||||||
<Star
|
<Star
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ export const Colors = {
|
||||||
BOX_SHADOW_DEFAULT_VARIANT5: "rgba(0, 0, 0, 0.25)",
|
BOX_SHADOW_DEFAULT_VARIANT5: "rgba(0, 0, 0, 0.25)",
|
||||||
|
|
||||||
BUTTON_CUSTOM_SOLID_DARK_TEXT_COLOR: "#333",
|
BUTTON_CUSTOM_SOLID_DARK_TEXT_COLOR: "#333",
|
||||||
|
BUTTON_DISABLED: "#c2c5c7",
|
||||||
|
|
||||||
SELECT_DISABLED: "#ced9e080",
|
SELECT_DISABLED: "#ced9e080",
|
||||||
SELECT_PLACEHOLDER: "#bfbfbf",
|
SELECT_PLACEHOLDER: "#bfbfbf",
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,17 @@ export const invisible = css`
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const disable = css`
|
||||||
|
& {
|
||||||
|
cursor: not-allowed;
|
||||||
|
|
||||||
|
& > * {
|
||||||
|
opacity: 0.5;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export const BlueprintCSSTransform = css`
|
export const BlueprintCSSTransform = css`
|
||||||
&&&& {
|
&&&& {
|
||||||
.${Classes.BUTTON} {
|
.${Classes.BUTTON} {
|
||||||
|
|
@ -1460,7 +1471,7 @@ export const dark: ColorType = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
bgColor: Colors.DARK_GRAY,
|
bgColor: Colors.BUTTON_DISABLED,
|
||||||
textColor: Colors.WHITE,
|
textColor: Colors.WHITE,
|
||||||
},
|
},
|
||||||
primary: {
|
primary: {
|
||||||
|
|
@ -2045,7 +2056,7 @@ export const light: ColorType = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
bgColor: Colors.DARK_GRAY,
|
bgColor: Colors.BUTTON_DISABLED,
|
||||||
textColor: Colors.WHITE,
|
textColor: Colors.WHITE,
|
||||||
},
|
},
|
||||||
primary: {
|
primary: {
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ class CheckboxWidget extends BaseWidget<CheckboxWidgetProps, WidgetState> {
|
||||||
key={this.props.widgetId}
|
key={this.props.widgetId}
|
||||||
label={this.props.label}
|
label={this.props.label}
|
||||||
onCheckChange={this.onCheckChange}
|
onCheckChange={this.onCheckChange}
|
||||||
|
rowSpace={this.props.parentRowSpace}
|
||||||
widgetId={this.props.widgetId}
|
widgetId={this.props.widgetId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user