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

86 lines
1.8 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-28 16:16:49 +00:00
import { createStyles, withStyles, WithStyles } 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-10-28 16:16:49 +00:00
const styles = theme =>
2019-06-19 14:40:52 +00:00
createStyles({
currencySymbol: {
fontSize: "0.875rem"
},
inputContainer: {
display: "grid",
gridTemplateColumns: "1fr 2rem 1fr"
},
pullDown: {
2019-10-28 16:16:49 +00:00
marginTop: theme.spacing(2)
2019-06-19 14:40:52 +00:00
},
separator: {
2019-10-28 16:16:49 +00:00
marginTop: theme.spacing(3),
2019-06-19 14:40:52 +00:00
textAlign: "center",
width: "100%"
},
widgetContainer: {
2019-10-28 16:16:49 +00:00
marginTop: theme.spacing(2)
2019-06-19 14:40:52 +00:00
}
});
interface PriceFieldProps extends WithStyles<typeof styles> {
className?: string;
currencySymbol?: string;
disabled?: boolean;
error?: boolean;
hint?: string;
label?: string;
name?: string;
value?: string | number;
InputProps?: InputProps;
onChange(event: any);
}
export const PriceField = withStyles(styles, { name: "PriceField" })(
({
className,
disabled,
error,
label,
hint,
currencySymbol,
name,
classes,
onChange,
value,
InputProps
}: PriceFieldProps) => (
<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 />
),
type: "number"
}}
name={name}
disabled={disabled}
onChange={onChange}
/>
)
);
PriceField.defaultProps = {
name: "price"
};
PriceField.displayName = "PriceField";
export default PriceField;