Skip to content

Commit df22cdf

Browse files
georginahalpernGeorgina
andauthored
[Fluent] InputPropertyLine for text and number (#16786)
Simple helper to create a property line with either a text or number input --------- Co-authored-by: Georgina <[email protected]>
1 parent 9802c18 commit df22cdf

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { PropertyLine } from "./propertyLine";
2+
import type { PropertyLineProps } from "./propertyLine";
3+
import type { FunctionComponent } from "react";
4+
import { Input } from "../primitives/input";
5+
import type { InputProps } from "../primitives/input";
6+
7+
type InputPropertyLineProps = InputProps<string | number> & PropertyLineProps;
8+
9+
/**
10+
* Wraps an input in a property line
11+
* @param props - PropertyLineProps and InputProps
12+
* @returns property-line wrapped input component
13+
*/
14+
const InputPropertyLine: FunctionComponent<InputPropertyLineProps> = (props) => {
15+
return (
16+
<PropertyLine {...props}>
17+
<Input {...props} />
18+
</PropertyLine>
19+
);
20+
};
21+
22+
export const TextInputPropertyLine = InputPropertyLine as FunctionComponent<InputProps<string> & PropertyLineProps>;
23+
export const FloatInputPropertyLine = InputPropertyLine as FunctionComponent<InputProps<number> & PropertyLineProps>;

packages/dev/sharedUiComponents/src/fluent/primitives/input.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { BaseComponentProps } from "../hoc/propertyLine";
77
const useInputStyles = makeStyles({
88
text: {
99
height: "auto",
10+
textAlign: "right",
1011
},
1112
float: {
1213
height: "auto",
@@ -15,10 +16,9 @@ const useInputStyles = makeStyles({
1516
},
1617
});
1718

18-
type InputProps = BaseComponentProps<string | number> & {
19+
export type InputProps<T extends string | number> = BaseComponentProps<T> & {
1920
step?: number;
2021
placeholder?: string;
21-
type?: "number" | "text";
2222
min?: number;
2323
max?: number;
2424
};
@@ -27,7 +27,7 @@ type InputProps = BaseComponentProps<string | number> & {
2727
* @param props
2828
* @returns
2929
*/
30-
export const Input: FunctionComponent<InputProps> = (props) => {
30+
export const Input: FunctionComponent<InputProps<string | number>> = (props) => {
3131
const classes = useInputStyles();
3232
const [value, setValue] = useState(props.value ?? "");
3333

@@ -48,9 +48,10 @@ export const Input: FunctionComponent<InputProps> = (props) => {
4848
return (
4949
<FluentInput
5050
{...props}
51+
type={typeof props.value === "number" ? "number" : "text"}
5152
size="small"
5253
value={value.toString()}
53-
className={props.type === "number" ? classes.float : classes.text}
54+
className={typeof props.value === "number" ? classes.float : classes.text}
5455
onChange={handleChange}
5556
onKeyDown={handleKeyDown}
5657
/>

packages/dev/sharedUiComponents/src/fluent/primitives/syncedSlider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const SyncedSliderInput: FunctionComponent<SyncedSliderProps> = (props) =
5959
{props.min != undefined && props.max != undefined && (
6060
<Slider {...props} size="small" className={classes.slider} value={value} onChange={handleSliderChange} step={undefined} />
6161
)}
62-
<Input {...props} className={classes.input} type="number" value={value} onChange={handleInputChange} step={props.step} />
62+
<Input {...props} className={classes.input} value={value} onChange={handleInputChange} step={props.step} />
6363
</div>
6464
);
6565
};

0 commit comments

Comments
 (0)