Skip to content

Commit 2ec8a43

Browse files
authored
Merge pull request #26 from opendexnetwork/refactor/components
refactor: inputs
2 parents 3c4dcfa + 709ff5a commit 2ec8a43

23 files changed

+343
-271
lines changed

src/common/components/data-display/table/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import FileCopyOutlinedIcon from "@material-ui/icons/FileCopyOutlined";
1010
import React, { ReactElement } from "react";
1111
import { copyToClipboard } from "../../../utils/appUtil";
1212
import IconButton from "../../input/buttons/IconButton";
13-
import CenterEllipsis from "../CenterEllipsis";
13+
import CenterEllipsis from "../text/CenterEllipsis";
1414

1515
export type TableRow = {
1616
[key: string]: string | number | boolean | Date | ReactElement | undefined;
File renamed without changes.
File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
CheckboxProps as MaterialCheckboxProps,
3+
Checkbox as MaterialCheckbox,
4+
FormControlLabel,
5+
} from "@material-ui/core";
6+
import React, { ReactElement } from "react";
7+
8+
type CheckboxProps = MaterialCheckboxProps & {
9+
label: string;
10+
};
11+
12+
const Checkbox = (props: CheckboxProps): ReactElement => {
13+
const { label, ...checkboxProps } = props;
14+
15+
return (
16+
<FormControlLabel
17+
control={<MaterialCheckbox color="default" {...checkboxProps} />}
18+
label={label}
19+
/>
20+
);
21+
};
22+
23+
export default Checkbox;

src/common/components/input/Password.tsx

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import {
2-
FormControl,
3-
InputAdornment,
4-
InputLabel,
5-
OutlinedInput,
6-
} from "@material-ui/core";
1+
import { InputAdornment } from "@material-ui/core";
72
import Visibility from "@material-ui/icons/Visibility";
83
import VisibilityOff from "@material-ui/icons/VisibilityOff";
94
import React, { ChangeEvent, ReactElement, useState } from "react";
105
import IconButton from "./buttons/IconButton";
6+
import TextField from "./text/TextField";
117

128
type PasswordProps = {
139
label?: string;
@@ -23,29 +19,26 @@ const Password = (props: PasswordProps): ReactElement => {
2319
const [showPassword, setShowPassword] = useState(false);
2420

2521
return (
26-
<FormControl variant="outlined">
27-
<InputLabel htmlFor={label}>{label}</InputLabel>
28-
<OutlinedInput
29-
id={label}
30-
labelWidth={label.length * 9}
31-
value={value}
32-
onChange={(event) => {
33-
onChange(event);
34-
}}
35-
type={showPassword ? "text" : "password"}
36-
endAdornment={
37-
<InputAdornment position="end">
38-
<IconButton
39-
icon={showPassword ? <Visibility /> : <VisibilityOff />}
40-
tooltipTitle={""}
41-
aria-label="toggle password visibility"
42-
onClick={() => setShowPassword(!showPassword)}
43-
edge="end"
44-
/>
45-
</InputAdornment>
46-
}
47-
/>
48-
</FormControl>
22+
<TextField
23+
label={label}
24+
id={label}
25+
value={value}
26+
onChange={(event) => {
27+
onChange(event);
28+
}}
29+
type={showPassword ? "text" : "password"}
30+
endAdornment={
31+
<InputAdornment position="end">
32+
<IconButton
33+
icon={showPassword ? <Visibility /> : <VisibilityOff />}
34+
tooltipTitle={""}
35+
aria-label="toggle password visibility"
36+
onClick={() => setShowPassword(!showPassword)}
37+
edge="end"
38+
/>
39+
</InputAdornment>
40+
}
41+
/>
4942
);
5043
};
5144

src/common/components/input/buttons/ButtonWithLoading.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { CircularProgress, createStyles, makeStyles } from "@material-ui/core";
1+
import {
2+
CircularProgress,
3+
createStyles,
4+
FormControl,
5+
FormHelperText,
6+
makeStyles,
7+
} from "@material-ui/core";
28
import React, { ReactElement } from "react";
39
import Button from "./Button";
410

@@ -11,6 +17,8 @@ type ButtonWithLoadingProps = {
1117
fullWidth?: boolean;
1218
size?: "small" | "medium" | "large";
1319
color?: "primary" | "secondary";
20+
error?: boolean;
21+
helperText?: string;
1422
};
1523

1624
const useStyles = makeStyles(() =>
@@ -39,23 +47,32 @@ const ButtonWithLoading = (props: ButtonWithLoadingProps): ReactElement => {
3947
fullWidth,
4048
size,
4149
color,
50+
error,
51+
helperText,
4252
} = props;
4353

4454
return (
45-
<div className={classes.buttonWrapper}>
46-
<Button
47-
text={text}
48-
type={submitButton ? "submit" : "button"}
49-
color={color || "primary"}
50-
onClick={onClick}
51-
disabled={disabled}
52-
fullWidth={fullWidth}
53-
size={size}
54-
/>
55-
{loading && (
56-
<CircularProgress size={24} className={classes.buttonProgress} />
57-
)}
58-
</div>
55+
<FormControl fullWidth={fullWidth}>
56+
<div className={classes.buttonWrapper}>
57+
<Button
58+
text={text}
59+
type={submitButton ? "submit" : "button"}
60+
color={color || "primary"}
61+
onClick={onClick}
62+
disabled={disabled}
63+
fullWidth={fullWidth}
64+
size={size}
65+
/>
66+
{loading && (
67+
<CircularProgress
68+
size={24}
69+
className={classes.buttonProgress}
70+
color={color || "primary"}
71+
/>
72+
)}
73+
</div>
74+
<FormHelperText error={error}>{helperText}</FormHelperText>
75+
</FormControl>
5976
);
6077
};
6178

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { FormControl, NativeSelect } from "@material-ui/core";
1+
import {
2+
FormControl,
3+
NativeSelect as MaterialNativeSelect,
4+
} from "@material-ui/core";
25
import React, { ReactElement } from "react";
36

47
type SelectProps = {
@@ -8,10 +11,10 @@ type SelectProps = {
811
onChange: (value: string) => void;
912
};
1013

11-
const Select = (props: SelectProps): ReactElement => {
14+
const NativeSelect = (props: SelectProps): ReactElement => {
1215
return (
1316
<FormControl>
14-
<NativeSelect
17+
<MaterialNativeSelect
1518
value={props.value}
1619
onChange={(event) => props.onChange(event.target.value)}
1720
name={props.name}
@@ -21,9 +24,9 @@ const Select = (props: SelectProps): ReactElement => {
2124
{opt}
2225
</option>
2326
))}
24-
</NativeSelect>
27+
</MaterialNativeSelect>
2528
</FormControl>
2629
);
2730
};
2831

29-
export default Select;
32+
export default NativeSelect;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
FormControl,
3+
MenuItem,
4+
Select as MaterialSelect,
5+
SelectProps as MaterialSelectProps,
6+
} from "@material-ui/core";
7+
import React, { ReactElement } from "react";
8+
9+
type ValueType = string | number | undefined;
10+
11+
type SelectOption = {
12+
value: ValueType;
13+
text: string;
14+
};
15+
16+
type SelectProps = MaterialSelectProps & {
17+
id: string;
18+
value: ValueType;
19+
options: SelectOption[];
20+
};
21+
22+
const Select = (props: SelectProps): ReactElement => {
23+
const { value, options, id, ...selectProps } = props;
24+
25+
return (
26+
<FormControl variant="outlined" fullWidth>
27+
<MaterialSelect id={id} value={value} {...selectProps}>
28+
{options.map((opt) => (
29+
<MenuItem key={opt.value} value={opt.value}>
30+
{opt.text}
31+
</MenuItem>
32+
))}
33+
</MaterialSelect>
34+
</FormControl>
35+
);
36+
};
37+
38+
export default Select;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { ReactElement } from "react";
2+
import NumberInput from "./NumberInput";
3+
import TextField, { TextFieldProps } from "./TextField";
4+
5+
type NumberFieldProps = TextFieldProps & {
6+
decimalScale?: number;
7+
useTextInput?: boolean;
8+
};
9+
10+
const NumberField = (props: NumberFieldProps): ReactElement => {
11+
const { decimalScale, useTextInput: useDefaultInput, ...fieldProps } = props;
12+
13+
return (
14+
<TextField
15+
InputProps={{
16+
inputComponent: useDefaultInput ? undefined : (NumberInput as any),
17+
inputProps: useDefaultInput
18+
? { ...fieldProps.inputProps }
19+
: { decimalScale: decimalScale, ...fieldProps.inputProps },
20+
...props.InputProps,
21+
}}
22+
{...fieldProps}
23+
/>
24+
);
25+
};
26+
27+
export default NumberField;
File renamed without changes.

0 commit comments

Comments
 (0)