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

104 lines
2.4 KiB
TypeScript
Raw Normal View History

import { MenuItem, Typography } from "@material-ui/core";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import { makeStyles } from "@saleor/macaw-ui";
2019-11-20 15:58:17 +00:00
import { GetItemPropsOptions } from "downshift";
import React from "react";
import Hr from "../Hr";
import { QuickSearchAction } from "./types";
interface NavigatorSectionProps {
getItemProps: (options: GetItemPropsOptions) => any;
highlightedIndex: number;
label: string;
items: QuickSearchAction[];
offset: number;
}
const useStyles = makeStyles(
theme => ({
item: {
"&&&&": {
color: theme.palette.text.secondary,
fontWeight: 400
},
2019-11-25 13:51:46 +00:00
display: "flex",
2019-11-20 15:58:17 +00:00
margin: theme.spacing(1, 0)
},
2019-11-25 13:51:46 +00:00
itemLabel: {
display: "inline-block"
},
2019-11-20 15:58:17 +00:00
label: {
paddingLeft: theme.spacing(2),
textTransform: "uppercase"
},
root: {
2019-11-26 14:14:21 +00:00
"&:last-child": {
marginBottom: 0
2019-11-20 15:58:17 +00:00
},
margin: theme.spacing(2, 0),
padding: theme.spacing(0, 1)
2019-11-25 13:51:46 +00:00
},
spacer: {
flex: 1
2019-11-26 14:14:21 +00:00
},
symbol: {
display: "inline-block",
fontWeight: 600,
width: theme.spacing(4)
2019-11-20 15:58:17 +00:00
}
}),
{
name: "NavigatorSection"
}
);
const NavigatorSection: React.FC<NavigatorSectionProps> = props => {
const { getItemProps, highlightedIndex, label, items, offset } = props;
const classes = useStyles(props);
return (
<div className={classes.root}>
<Typography
className={classes.label}
variant="body2"
color="textSecondary"
>
{label}
</Typography>
<Hr />
{items.map((item, itemIndex) => {
const index = offset + itemIndex;
const itemProps = getItemProps({
index,
item
});
return (
<MenuItem
{...itemProps}
className={classes.item}
selected={highlightedIndex === index}
key={[item.label, item.type].join(":")}
>
2019-11-25 13:51:46 +00:00
<span className={classes.itemLabel}>
2019-11-26 14:14:21 +00:00
{item.symbol && (
<span className={classes.symbol}>{item.symbol}</span>
)}
2019-11-25 13:51:46 +00:00
<span>{item.label}</span>
{item.caption && (
<Typography variant="caption">{item.caption}</Typography>
)}
</span>
<span className={classes.spacer} />
{item.extraInfo}
2019-11-20 15:58:17 +00:00
</MenuItem>
);
})}
</div>
);
};
NavigatorSection.displayName = "NavigatorSection";
export default NavigatorSection;