Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add IconButtonTableCell component

dominik-zeglen7331622100cd
diff --git a/saleor/static/dashboard-next/components/IconButtonTableCell/IconButtonTableCell.tsx b/saleor/static/dashboard-next/components/IconButtonTableCell/IconButtonTableCell.tsx
new file mode 100644
index 0000000000..558891746a
--- /dev/null
+++ b/saleor/static/dashboard-next/components/IconButtonTableCell/IconButtonTableCell.tsx
@@ -0,0 +1,49 @@
+import IconButton from "@material-ui/core/IconButton";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+import TableCell from "@material-ui/core/TableCell";
+import * as React from "react";
+
+import { stopPropagation } from "../../misc";
+import { ICONBUTTON_SIZE } from "../../theme";
+
+export interface IconButtonTableCellProps {
+ children: React.ReactNode;
+ disabled?: boolean;
+ onClick: () => void;
+}
+
+const styles = (theme: Theme) =>
+ createStyles({
+ root: {
+ "&:last-child": {
+ paddingRight: 0
+ },
+ paddingRight: 0,
+ width: ICONBUTTON_SIZE + theme.spacing.unit / 2
+ }
+ });
+const IconButtonTableCell = withStyles(styles, { name: "IconButtonTableCell" })(
+ ({
+ children,
+ classes,
+ disabled,
+ onClick
+ }: IconButtonTableCellProps & WithStyles<typeof styles>) => (
+ <TableCell className={classes.root}>
+ <IconButton
+ color="primary"
+ disabled={disabled}
+ onClick={stopPropagation(onClick)}
+ >
+ {children}
+ </IconButton>
+ </TableCell>
+ )
+);
+IconButtonTableCell.displayName = "IconButtonTableCell";
+export default IconButtonTableCell;
diff --git a/saleor/static/dashboard-next/components/IconButtonTableCell/index.ts b/saleor/static/dashboard-next/components/IconButtonTableCell/index.ts
new file mode 100644
index 0000000000..ec9027bd49
--- /dev/null
+++ b/saleor/static/dashboard-next/components/IconButtonTableCell/index.ts
@@ -0,0 +1,2 @@
+export { default } from './IconButtonTableCell';
+export * from './IconButtonTableCell';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index 6f4d6f2606..c41a3b0e76 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -226,3 +226,13 @@ export function getUserInitials(user?: User) {
export function createHref(url: string) {
return urlJoin(APP_MOUNT_URI, url);
}
+
+interface AnyEvent {
+ stopPropagation: () => void;
+}
+export function stopPropagation(cb: () => void) {
+ return (event: AnyEvent) => {
+ event.stopPropagation();
+ cb();
+ };
+}
diff --git a/saleor/static/dashboard-next/shipping/components/ShippingZoneRates/ShippingZoneRates.tsx b/saleor/static/dashboard-next/shipping/components/ShippingZoneRates/ShippingZoneRates.tsx
index f092c68217..c71046d75f 100644
--- a/saleor/static/dashboard-next/shipping/components/ShippingZoneRates/ShippingZoneRates.tsx
+++ b/saleor/static/dashboard-next/shipping/components/ShippingZoneRates/ShippingZoneRates.tsx
@@ -25,6 +25,7 @@ import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
import { ICONBUTTON_SIZE } from "../../../theme";
import { ShippingZoneDetailsFragment_shippingMethods } from "../../types/ShippingZoneDetailsFragment";
+import IconButtonTableCell from "../../../components/IconButtonTableCell";
export interface ShippingZoneRatesProps {
disabled: boolean;
@@ -132,30 +133,18 @@ const ShippingZoneRates = withStyles(styles, { name: "ShippingZoneRates" })(
<Skeleton />
)}
</TableCell>
- <TableCell className={classes.alignRight}>
- <IconButton
- color="primary"
- disabled={disabled}
- onClick={event => {
- event.stopPropagation();
- onRateEdit(rate.id);
- }}
- >
- <EditIcon />
- </IconButton>
- </TableCell>
- <TableCell className={classes.alignRight}>
- <IconButton
- color="primary"
- disabled={disabled}
- onClick={event => {
- event.stopPropagation();
- onRateRemove(rate.id);
- }}
- >
- <DeleteIcon />
- </IconButton>
- </TableCell>
+ <IconButtonTableCell
+ disabled={disabled}
+ onClick={() => onRateEdit(rate.id)}
+ >
+ <EditIcon />
+ </IconButtonTableCell>
+ <IconButtonTableCell
+ disabled={disabled}
+ onClick={() => onRateRemove(rate.id)}
+ >
+ <DeleteIcon />
+ </IconButtonTableCell>
</TableRow>
),
() => (