2021-03-30 07:40:18 +00:00
|
|
|
import { makeStyles } from "@saleor/theme";
|
2019-11-20 15:58:17 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
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-26 14:34:56 +00:00
|
|
|
: mode === "catalog"
|
|
|
|
? intl.formatMessage({
|
|
|
|
defaultMessage: "Search in Catalog",
|
|
|
|
description: "navigator placeholder"
|
|
|
|
})
|
|
|
|
: mode === "customers"
|
|
|
|
? intl.formatMessage({
|
|
|
|
defaultMessage: "Search Customer",
|
2019-11-21 12:13:41 +00:00
|
|
|
description: "navigator placeholder"
|
|
|
|
})
|
2019-11-26 14:34:56 +00:00
|
|
|
: mode === "default"
|
|
|
|
? intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "Type {key} to see available actions",
|
|
|
|
description: "navigator placeholder"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "'?'"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: null
|
2019-11-21 12:13:41 +00:00
|
|
|
}
|
|
|
|
ref={ref}
|
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2019-11-20 15:58:17 +00:00
|
|
|
|
|
|
|
NavigatorInput.displayName = "NavigatorInput";
|
|
|
|
export default NavigatorInput;
|