Skip to content

Commit cd21261

Browse files
author
Gianmarco Manni
committed
x
1 parent 6a91cf5 commit cd21261

7 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/lib/AsyncTypeaheadInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
127127
name={name}
128128
label={useBootstrapStyle ? label : undefined}
129129
labelStyle={useBootstrapStyle ? { color: "#8493A5", fontSize: 14 } : undefined}
130-
layout="typeahead"
130+
layout="muiInput"
131131
>
132132
<Autocomplete<TypeaheadOption, boolean, boolean, boolean>
133133
{...autocompleteProps}

src/lib/ColorPickerInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ interface ColorPickerInputProps<T extends FieldValues>
1616
}
1717

1818
const ColorPickerInput = <T extends FieldValues>(props: ColorPickerInputProps<T>) => {
19-
const { label, helpText, inputGroupStyle, labelToolTip, hideValidationMessage = false } = props;
19+
const { label, helpText, inputGroupStyle, labelToolTip, hideValidationMessage = false, useBootstrapStyle } = props;
2020
const { name, id } = useSafeNameId(props.name, props.id);
2121

2222
return (
2323
<FormGroupLayout
2424
helpText={helpText}
2525
name={name}
2626
id={id}
27-
label={label}
2827
labelToolTip={labelToolTip}
2928
inputGroupStyle={inputGroupStyle}
3029
hideValidationMessage={hideValidationMessage}
30+
label={useBootstrapStyle ? label : undefined}
31+
labelStyle={useBootstrapStyle ? { color: "#8493A5", fontSize: 14 } : undefined}
32+
layout="muiInput"
3133
>
3234
<ColorPicker {...props} name={name} id={id} />
3335
</FormGroupLayout>

src/lib/FormGroupLayout.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface FormGroupLayoutProps<T extends FieldValues, TRenderAddon>
1111
extends PropsWithChildren<
1212
Pick<CommonInputProps<T>, "helpText" | "label" | "name" | "id" | "labelToolTip" | "inputOnly" | "hideValidationMessage">
1313
> {
14-
layout?: "checkbox" | "switch" | "typeahead";
14+
layout?: "checkbox" | "switch" | "muiInput";
1515
addonLeft?: ReactNode | ((props: TRenderAddon) => ReactNode);
1616
addonRight?: ReactNode | ((props: TRenderAddon) => ReactNode);
1717
addonProps?: MergedAddonProps<TRenderAddon>;
@@ -47,7 +47,7 @@ const FormGroupLayout = <T extends FieldValues, TRenderAddon = unknown>(props: F
4747

4848
const switchLayout = layout === "switch";
4949
const checkboxLayout = layout === "checkbox";
50-
const typeaheadLayout = layout === "typeahead";
50+
const muiInputLayout = layout === "muiInput";
5151

5252
if (inputOnly && (switchLayout || checkboxLayout)) {
5353
throw "'inputOnly' is not possible with switches or checkboxes";
@@ -86,7 +86,7 @@ const FormGroupLayout = <T extends FieldValues, TRenderAddon = unknown>(props: F
8686
tooltip={labelToolTip}
8787
layout={layout}
8888
/>
89-
{switchLayout || checkboxLayout || typeaheadLayout ? (
89+
{switchLayout || checkboxLayout || muiInputLayout ? (
9090
children
9191
) : (
9292
<InputGroup
@@ -102,7 +102,7 @@ const FormGroupLayout = <T extends FieldValues, TRenderAddon = unknown>(props: F
102102
{effectiveAddonRight}
103103
</InputGroup>
104104
)}
105-
{!typeaheadLayout && (
105+
{!muiInputLayout && (
106106
<>
107107
{!hideErrorMessage && <FormFeedback>{errorMessage}</FormFeedback>}
108108
{helpText && <FormText>{helpText}</FormText>}

src/lib/FormGroupLayoutLabel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface FormGroupLayoutLabelProps<T extends FieldValues> {
88
tooltip?: ReactNode;
99
fieldName: FieldPath<T>;
1010
fieldId: string;
11-
layout?: "checkbox" | "switch" | "typeahead";
11+
layout?: "checkbox" | "switch" | "muiInput";
1212
labelStyle?: CSSProperties;
1313
}
1414

src/lib/StaticTypeaheadInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
9898
name={name}
9999
label={useBootstrapStyle ? label : undefined}
100100
labelStyle={useBootstrapStyle ? { color: "#8493A5", fontSize: 14 } : undefined}
101-
layout="typeahead"
101+
layout="muiInput"
102102
>
103103
<Autocomplete<TypeaheadOption, boolean, boolean, boolean>
104104
{...autocompleteProps}

src/lib/components/ColorPicker/ColorPicker.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import InputAdornment from "@mui/material/InputAdornment";
22
import TextField from "@mui/material/TextField";
3-
import PopupState, { bindPopover, bindTrigger } from "material-ui-popup-state";
3+
import PopupState, { bindPopover } from "material-ui-popup-state";
44
import { ColorPickerButton } from "./ColorPickerButton";
55
import { FieldError, FieldValues, get, useController } from "react-hook-form";
66
import { ColorPickerInputProps } from "../../ColorPickerInput";
@@ -87,15 +87,14 @@ const ColorPicker = <T extends FieldValues>(props: ColorPickerInputProps<T>) =>
8787
}
8888

8989
propsOnBlur && propsOnBlur(e);
90-
9190
field.onBlur();
9291
}}
9392
value={field.value}
9493
slotProps={{
9594
input: {
9695
startAdornment: (
9796
<InputAdornment position="start">
98-
<ColorPickerButton color={color} disabled={isDisabled} bindTrigger={bindTrigger(popupState)} />
97+
<ColorPickerButton color={color} disabled={isDisabled} popupState={popupState} />
9998
</InputAdornment>
10099
),
101100
},

src/lib/components/ColorPicker/ColorPickerButton.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { TinyColor } from "@ctrl/tinycolor";
22
import Button from "@mui/material/Button";
33
import { bindTrigger } from "material-ui-popup-state";
4+
import { PopupState } from "material-ui-popup-state/hooks";
45

56
interface ColorPickerButtonProps {
6-
bindTrigger: ReturnType<typeof bindTrigger>;
7+
popupState: PopupState;
78
color: TinyColor;
89
disabled?: boolean;
910
}
@@ -12,11 +13,11 @@ const BG_IMAGE_FALLBACK =
1213
"linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(135deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(135deg, transparent 75%, #ccc 75%) /*! @noflip */";
1314

1415
const ColorPickerButton = (props: ColorPickerButtonProps) => {
15-
const { bindTrigger, color, disabled } = props;
16+
const { popupState, color, disabled } = props;
1617

1718
return (
1819
<Button
19-
{...bindTrigger}
20+
{...bindTrigger(popupState)}
2021
variant="text"
2122
aria-describedby="color"
2223
style={{

0 commit comments

Comments
 (0)