saleor-dashboard/src/components/PriceField/PriceField.tsx

95 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import { InputProps } from "@material-ui/core/Input";
import InputAdornment from "@material-ui/core/InputAdornment";
2019-10-30 14:34:24 +00:00
import { makeStyles } from "@material-ui/core/styles";
2019-06-19 14:40:52 +00:00
import TextField from "@material-ui/core/TextField";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
currencySymbol: {
fontSize: "0.875rem"
},
inputContainer: {
display: "grid",
gridTemplateColumns: "1fr 2rem 1fr"
},
pullDown: {
marginTop: theme.spacing(2)
},
separator: {
marginTop: theme.spacing(3),
textAlign: "center",
width: "100%"
},
widgetContainer: {
marginTop: theme.spacing(2)
}
}),
{ name: "PriceField" }
);
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
interface PriceFieldProps {
2019-06-19 14:40:52 +00:00
className?: string;
currencySymbol?: string;
disabled?: boolean;
error?: boolean;
hint?: string;
label?: string;
name?: string;
value?: string | number;
InputProps?: InputProps;
onChange(event: any);
}
2019-10-30 14:34:24 +00:00
export const PriceField: React.FC<PriceFieldProps> = props => {
const {
2019-06-19 14:40:52 +00:00
className,
disabled,
error,
label,
hint,
currencySymbol,
name,
onChange,
value,
InputProps
2019-10-30 14:34:24 +00:00
} = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<TextField
className={className}
error={error}
helperText={hint}
label={label}
fullWidth
value={value}
InputProps={{
...InputProps,
endAdornment: currencySymbol ? (
<InputAdornment position="end" className={classes.currencySymbol}>
{currencySymbol}
</InputAdornment>
) : (
<span />
),
inputProps: {
min: 0,
...InputProps?.inputProps
},
2019-06-19 14:40:52 +00:00
type: "number"
}}
name={name}
disabled={disabled}
onChange={onChange}
/>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
PriceField.defaultProps = {
name: "price"
};
PriceField.displayName = "PriceField";
export default PriceField;