File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed
packages/dev/sharedUiComponents/src/fluent Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change
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 > ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type { BaseComponentProps } from "../hoc/propertyLine";
7
7
const useInputStyles = makeStyles ( {
8
8
text : {
9
9
height : "auto" ,
10
+ textAlign : "right" ,
10
11
} ,
11
12
float : {
12
13
height : "auto" ,
@@ -15,10 +16,9 @@ const useInputStyles = makeStyles({
15
16
} ,
16
17
} ) ;
17
18
18
- type InputProps = BaseComponentProps < string | number > & {
19
+ export type InputProps < T extends string | number > = BaseComponentProps < T > & {
19
20
step ?: number ;
20
21
placeholder ?: string ;
21
- type ?: "number" | "text" ;
22
22
min ?: number ;
23
23
max ?: number ;
24
24
} ;
@@ -27,7 +27,7 @@ type InputProps = BaseComponentProps<string | number> & {
27
27
* @param props
28
28
* @returns
29
29
*/
30
- export const Input : FunctionComponent < InputProps > = ( props ) => {
30
+ export const Input : FunctionComponent < InputProps < string | number > > = ( props ) => {
31
31
const classes = useInputStyles ( ) ;
32
32
const [ value , setValue ] = useState ( props . value ?? "" ) ;
33
33
@@ -48,9 +48,10 @@ export const Input: FunctionComponent<InputProps> = (props) => {
48
48
return (
49
49
< FluentInput
50
50
{ ...props }
51
+ type = { typeof props . value === "number" ? "number" : "text" }
51
52
size = "small"
52
53
value = { value . toString ( ) }
53
- className = { props . type === "number" ? classes . float : classes . text }
54
+ className = { typeof props . value === "number" ? classes . float : classes . text }
54
55
onChange = { handleChange }
55
56
onKeyDown = { handleKeyDown }
56
57
/>
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export const SyncedSliderInput: FunctionComponent<SyncedSliderProps> = (props) =
59
59
{ props . min != undefined && props . max != undefined && (
60
60
< Slider { ...props } size = "small" className = { classes . slider } value = { value } onChange = { handleSliderChange } step = { undefined } />
61
61
) }
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 } />
63
63
</ div >
64
64
) ;
65
65
} ;
You can’t perform that action at this time.
0 commit comments