Skip to content

Commit 0a4ed0c

Browse files
georginahalpernGeorgina
andauthored
[Fluent/InspectorV2] Fix bugs in number/text input; Add input validation UX; Refactor colorPicker to use new components (#16998)
- Separate out the input.tsx component into spinButton.tsx and textInput.tsx since spinButton is more appropriate for handling numerical values - Introduce forceInt param to NumerInputPropertyLine - Both spinButton and textInput now have input validation UX as the user types - if the input is valid, it will automatically propagate to parent. If not, it will display as red background and won't notify parent of change <img width="378" height="330" alt="image" src="https://github.com/user-attachments/assets/7d3c42e1-65c7-45ec-8534-d2cda00ef82e" /> - ColorPicker.tsx refactored to use the new textInput/spinButtons directly, - InfoLabel now an optional param to PrimitiveProps so that primitives can optionally display an infoLabel (with or without the info popup) directly on the primitive value (distinct from the propertyline's label) -- colorpicker usage is refactored accordingly - Add units to spinbutton with inputvalidation as well - minor styling <img width="411" height="128" alt="image" src="https://github.com/user-attachments/assets/ad7072ba-054c-4c5d-9b2b-77f3612631dd" /> <img width="508" height="174" alt="image" src="https://github.com/user-attachments/assets/7421bab0-442f-40fd-b213-8bdad68ed9da" /> <img width="408" height="489" alt="image" src="https://github.com/user-attachments/assets/ceb08ef3-6f0d-4417-9b52-48a15e53a950" /> --------- Co-authored-by: Georgina <[email protected]>
1 parent c2c62d7 commit 0a4ed0c

File tree

11 files changed

+407
-271
lines changed

11 files changed

+407
-271
lines changed

packages/dev/inspector-v2/src/components/properties/animation/animationGroupProperties.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ export const AnimationGroupControlProperties: FunctionComponent<{ animationGroup
7878
/>
7979
<BoundProperty component={SwitchPropertyLine} label="Is Additive" target={animationGroup} propertyKey="isAdditive" />
8080
<BoundProperty component={NumberInputPropertyLine} label="Weight" target={animationGroup} propertyKey="weight" step={0.1} />
81-
<BoundProperty component={NumberInputPropertyLine} label="Play Order" target={animationGroup} propertyKey="playOrder" step={0} />
82-
{/* TODO: Hey georgie :<Play order> should be integer (even when typing)*/}
81+
<BoundProperty component={NumberInputPropertyLine} label="Play order" target={animationGroup} propertyKey="playOrder" forceInt />
8382
</>
8483
</Collapse>
8584
</>
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
import { PropertyLine } from "./propertyLine";
22
import type { PropertyLineProps } from "./propertyLine";
33
import type { FunctionComponent } from "react";
4-
import { NumberInput, TextInput } from "../../primitives/input";
5-
import type { InputProps } from "../../primitives/input";
6-
4+
import type { TextInputProps } from "../../primitives/textInput";
5+
import { TextInput } from "../../primitives/textInput";
6+
import type { SpinButtonProps } from "../../primitives/spinButton";
7+
import { SpinButton } from "../../primitives/spinButton";
78
/**
89
* Wraps a text input in a property line
910
* @param props - PropertyLineProps and InputProps
1011
* @returns property-line wrapped input component
1112
*/
12-
export const TextInputPropertyLine: FunctionComponent<InputProps<string> & PropertyLineProps<string>> = (props) => (
13+
export const TextInputPropertyLine: FunctionComponent<TextInputProps & PropertyLineProps<string>> = (props) => (
1314
<PropertyLine {...props}>
1415
<TextInput {...props} />
1516
</PropertyLine>
1617
);
1718

1819
/**
1920
* Wraps a number input in a property line
21+
* To force integer values, use forceInt param (this is distinct from the 'step' param, which will still allow submitting an integer value. forceInt will not)
2022
* @param props - PropertyLineProps and InputProps
2123
* @returns property-line wrapped input component
2224
*/
23-
export const NumberInputPropertyLine: FunctionComponent<InputProps<number> & PropertyLineProps<number>> = (props) => (
24-
<PropertyLine {...props}>
25-
<NumberInput {...props} />
26-
</PropertyLine>
27-
);
25+
export const NumberInputPropertyLine: FunctionComponent<SpinButtonProps & PropertyLineProps<number> & { forceInt?: boolean }> = (props) => {
26+
return (
27+
<PropertyLine {...props}>
28+
<SpinButton {...props} />
29+
</PropertyLine>
30+
);
31+
};

packages/dev/sharedUiComponents/src/fluent/hoc/propertyLines/vectorPropertyLine.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export type TensorPropertyLineProps<V extends Vector2 | Vector3 | Vector4 | Quat
2121
* If passed, all sliders will use this for the max value
2222
*/
2323
max?: number;
24+
/**
25+
* Will be displayed in the input UI to indicate the unit of measurement
26+
*/
27+
unit?: string;
2428
/**
2529
* If passed, the UX will use the conversion functions to display/update values
2630
*/
@@ -66,10 +70,14 @@ const TensorPropertyLine: FunctionComponent<TensorPropertyLineProps<Vector2 | Ve
6670
{...props}
6771
expandedContent={
6872
<>
69-
<SyncedSliderPropertyLine label="X" value={converted(vector.x)} min={min} max={max} onChange={(val) => onChange(val, "x")} />
70-
<SyncedSliderPropertyLine label="Y" value={converted(vector.y)} min={min} max={max} onChange={(val) => onChange(val, "y")} />
71-
{HasZ(vector) && <SyncedSliderPropertyLine label="Z" value={converted(vector.z)} min={min} max={max} onChange={(val) => onChange(val, "z")} />}
72-
{HasW(vector) && <SyncedSliderPropertyLine label="W" value={converted(vector.w)} min={min} max={max} onChange={(val) => onChange(val, "w")} />}
73+
<SyncedSliderPropertyLine label="X" value={converted(vector.x)} min={min} max={max} onChange={(val) => onChange(val, "x")} unit={props.unit} />
74+
<SyncedSliderPropertyLine label="Y" value={converted(vector.y)} min={min} max={max} onChange={(val) => onChange(val, "y")} unit={props.unit} />
75+
{HasZ(vector) && (
76+
<SyncedSliderPropertyLine label="Z" value={converted(vector.z)} min={min} max={max} onChange={(val) => onChange(val, "z")} unit={props.unit} />
77+
)}
78+
{HasW(vector) && (
79+
<SyncedSliderPropertyLine label="W" value={converted(vector.w)} min={min} max={max} onChange={(val) => onChange(val, "w")} unit={props.unit} />
80+
)}
7381
</>
7482
}
7583
>
@@ -89,7 +97,7 @@ const ToDegreesConverter = { from: Tools.ToDegrees, to: Tools.ToRadians };
8997
export const RotationVectorPropertyLine: FunctionComponent<RotationVectorPropertyLineProps> = (props) => {
9098
const min = props.useDegrees ? 0 : undefined;
9199
const max = props.useDegrees ? 360 : undefined;
92-
return <Vector3PropertyLine {...props} valueConverter={props.useDegrees ? ToDegreesConverter : undefined} min={min} max={max} />;
100+
return <Vector3PropertyLine {...props} unit={props.useDegrees ? "deg" : "rad"} valueConverter={props.useDegrees ? ToDegreesConverter : undefined} min={min} max={max} />;
93101
};
94102

95103
type QuaternionPropertyLineProps = TensorPropertyLineProps<Quaternion> & {
@@ -118,7 +126,7 @@ export const QuaternionPropertyLine: FunctionComponent<QuaternionPropertyLinePro
118126
props.onChange(quat);
119127
};
120128

121-
return props.useDegrees ? (
129+
return useDegrees ? (
122130
<Vector3PropertyLine
123131
{...restProps}
124132
nullable={false}
@@ -128,9 +136,10 @@ export const QuaternionPropertyLine: FunctionComponent<QuaternionPropertyLinePro
128136
min={min}
129137
max={max}
130138
onChange={onEulerChange}
139+
unit="deg"
131140
/>
132141
) : (
133-
<QuaternionPropertyLineInternal {...props} nullable={false} value={quat} min={min} max={max} onChange={onQuatChange} />
142+
<QuaternionPropertyLineInternal {...props} unit={"rad"} nullable={false} value={quat} min={min} max={max} onChange={onQuatChange} />
134143
);
135144
};
136145
export const Vector2PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector2>>;

0 commit comments

Comments
 (0)