saleor-dashboard/src/components/Navigator/NavigatorInput.tsx

96 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-11-20 15:58:17 +00:00
import makeStyles from "@material-ui/core/styles/makeStyles";
import React from "react";
import { useIntl } from "react-intl";
2019-11-21 12:13:41 +00:00
import { QuickSearchMode } from "./types";
2019-11-20 15:58:17 +00:00
const useStyles = makeStyles(
2019-11-21 12:13:41 +00:00
theme => {
const typography = {
2019-11-20 15:58:17 +00:00
color: theme.palette.text.primary,
fontSize: 24,
2019-11-21 12:13:41 +00:00
lineHeight: 1.33
};
return {
adornment: {
...typography,
color: theme.palette.text.secondary,
paddingRight: theme.spacing(1)
},
input: {
...typography,
background: "transparent",
border: "none",
outline: 0,
padding: 0,
width: "100%"
},
root: {
background: theme.palette.background.default,
display: "flex",
padding: theme.spacing(2, 3)
}
};
},
2019-11-20 15:58:17 +00:00
{
name: "NavigatorInput"
}
);
2019-11-21 12:13:41 +00:00
interface NavigatorInputProps
extends React.InputHTMLAttributes<HTMLInputElement> {
mode: QuickSearchMode;
}
const NavigatorInput = React.forwardRef<HTMLInputElement, NavigatorInputProps>(
(props, ref) => {
const { mode, ...rest } = props;
const classes = useStyles(props);
const intl = useIntl();
return (
<div className={classes.root}>
2019-11-22 15:39:20 +00:00
{mode !== "default" && (
<span className={classes.adornment}>
2019-11-25 14:32:10 +00:00
{mode === "orders"
? "#"
: mode === "customers"
? "@"
: mode === "catalog"
? "$"
2019-11-26 14:14:21 +00:00
: mode === "help"
? "?"
2019-11-25 14:32:10 +00:00
: ">"}
2019-11-22 15:39:20 +00:00
</span>
)}
2019-11-21 12:13:41 +00:00
<input
autoFocus
autoComplete="off"
className={classes.input}
placeholder={
mode === "orders"
? intl.formatMessage({
defaultMessage: "Order Number",
description: "navigator placeholder"
})
2019-11-22 15:39:20 +00:00
: mode === "commands"
? intl.formatMessage({
defaultMessage: "Type Command",
description: "navigator placeholder"
})
2019-11-21 12:13:41 +00:00
: intl.formatMessage({
defaultMessage: "Use Navigator to move through Saleor",
description: "navigator placeholder"
})
}
ref={ref}
{...rest}
/>
</div>
);
}
);
2019-11-20 15:58:17 +00:00
NavigatorInput.displayName = "NavigatorInput";
export default NavigatorInput;