saleor-dashboard/src/components/Navigator/NavigatorInput.tsx
Dominik Żegleń 7d9441a7ec
Use esbuild-loader (#1983)
* Minor fixes for intl messages

* Add esbuild-loader
* switch from babel to esbuild-loader
* use formatjs enforce-id linter

* Generate ids for intl messages

* id format defined by idInterpolationPattern

* Modify intl messages extraction

* remove react-intl-translations-manager
* remove transpile-tx.js
* use formatjs cli

* Modify defaultMessages.json

* modify ids in defaultMessages.json with defined idInterpolationPattern

* Fix errors

* Fix page crash

* Use babel to transpile tests

* Fix useStateFromProps

* Improve render count

* Add test to useStateFromProps

* Fix reloading state buh

* Do not check if form with channels is dirty

* Stop blocking save if form has not changed

* Remove debug code

* Fix form disabling

* Fix variant selection checkbox onClick

* Update translations

* Update messages

* Use esbuild to build storybook

Co-authored-by: Bartłomiej Wiaduch <tukan2can@gmail.com>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-05-05 09:54:28 +02:00

134 lines
3.5 KiB
TypeScript

import { makeStyles, SearchLargeIcon } from "@saleor/macaw-ui";
import React from "react";
import { useIntl } from "react-intl";
import { QuickSearchMode } from "./types";
const useStyles = makeStyles(
theme => {
const typography = {
...theme.typography.body1,
color: theme.palette.saleor.main[1],
fontWeight: 500,
letterSpacing: "0.02rem"
};
return {
adornment: {
...typography,
alignSelf: "center",
color: theme.palette.text.secondary,
marginRight: theme.spacing(1),
textAlign: "center",
width: 32
},
input: {
"&::placeholder": {
color: theme.palette.saleor.main[3]
},
...typography,
background: "transparent",
border: "none",
outline: 0,
padding: 0,
width: "100%"
},
root: {
background: theme.palette.background.paper,
display: "flex",
padding: theme.spacing(2, 3),
height: 72
},
searchIcon: {
alignSelf: "center",
width: 32,
height: 32,
marginRight: theme.spacing(1)
}
};
},
{
name: "NavigatorInput"
}
);
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}>
{mode !== "default" ? (
<span className={classes.adornment}>
{mode === "orders"
? "#"
: mode === "customers"
? "@"
: mode === "catalog"
? "$"
: mode === "help"
? "?"
: ">"}
</span>
) : (
<SearchLargeIcon className={classes.searchIcon} />
)}
<input
autoFocus
autoComplete="off"
className={classes.input}
placeholder={
mode === "orders"
? intl.formatMessage({
id: "8B8E+3",
defaultMessage: "Order Number",
description: "navigator placeholder"
})
: mode === "commands"
? intl.formatMessage({
id: "NqxvFh",
defaultMessage: "Type Command",
description: "navigator placeholder"
})
: mode === "catalog"
? intl.formatMessage({
id: "AOI4LW",
defaultMessage: "Search in Catalog",
description: "navigator placeholder"
})
: mode === "customers"
? intl.formatMessage({
id: "TpPx7V",
defaultMessage: "Search Customer",
description: "navigator placeholder"
})
: mode === "default"
? intl.formatMessage(
{
id: "BooQvo",
defaultMessage: "Type {key} to see available actions",
description: "navigator placeholder"
},
{
key: "'?'"
}
)
: null
}
ref={ref}
{...rest}
/>
</div>
);
}
);
NavigatorInput.displayName = "NavigatorInput";
export default NavigatorInput;