Skip to content

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

Remove <Anchor /> component

dominik-zeglen1eac2b357b6f
diff --git a/saleor/static/dashboard-next/components/Anchor/Anchor.tsx b/saleor/static/dashboard-next/components/Anchor/Anchor.tsx
deleted file mode 100644
index c2dd266009..0000000000
--- a/saleor/static/dashboard-next/components/Anchor/Anchor.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import * as React from "react";
-
-export interface AnchorProps {
- children: (anchor: React.RefObject<HTMLDivElement>) => React.ReactNode;
-}
-
-class Anchor extends React.Component<AnchorProps> {
- anchor = React.createRef<HTMLDivElement>();
-
- render() {
- return this.anchor ? this.props.children(this.anchor) : null;
- }
-}
-export default Anchor;
diff --git a/saleor/static/dashboard-next/components/Anchor/index.ts b/saleor/static/dashboard-next/components/Anchor/index.ts
deleted file mode 100644
index 63f537245e..0000000000
--- a/saleor/static/dashboard-next/components/Anchor/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from './Anchor';
-export * from './Anchor';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/components/RichTextEditor/ImageEntity.tsx b/saleor/static/dashboard-next/components/RichTextEditor/ImageEntity.tsx
index 7b05ee4d87..f18508ed32 100644
--- a/saleor/static/dashboard-next/components/RichTextEditor/ImageEntity.tsx
+++ b/saleor/static/dashboard-next/components/RichTextEditor/ImageEntity.tsx
@@ -15,8 +15,6 @@ import { ContentState } from "draft-js";
import * as React from "react";
import i18n from "../../i18n";
-import Anchor from "../Anchor";
-import Toggle from "../Toggle";
interface ImageEntityProps {
children: React.ReactNode;
@@ -56,63 +54,60 @@ const ImageEntity = withStyles(styles, {
entityKey,
onEdit,
onRemove
- }: ImageEntityProps & WithStyles<typeof styles>) => (
- <Toggle>
- {(isOpened, { disable, toggle }) => (
- <>
- <Anchor>
- {anchor => (
- <div className={classes.anchor} ref={anchor}>
- <Popper
- open={isOpened}
- anchorEl={anchor.current}
- transition
- disablePortal
- placement="bottom"
- >
- {({ TransitionProps, placement }) => (
- <Grow
- {...TransitionProps}
- style={{
- transformOrigin: placement
- }}
- >
- <Paper className={classes.root}>
- <ClickAwayListener
- onClickAway={disable}
- mouseEvent="onClick"
- >
- <div className={classes.container}>
- <Button
- onClick={() => {
- disable();
- onEdit(entityKey);
- }}
- color="primary"
- variant="flat"
- >
- {i18n.t("Replace")}
- </Button>
- <IconButton onClick={() => onRemove(entityKey)}>
- <DeleteIcon color="primary" />
- </IconButton>
- </div>
- </ClickAwayListener>
- </Paper>
- </Grow>
- )}
- </Popper>
- </div>
+ }: ImageEntityProps & WithStyles<typeof styles>) => {
+ const [isOpened, setOpenStatus] = React.useState(false);
+ const anchor = React.useRef<HTMLDivElement>();
+
+ const disable = () => setOpenStatus(false);
+ const toggle = () => setOpenStatus(!isOpened);
+
+ return (
+ <>
+ <div className={classes.anchor} ref={anchor}>
+ <Popper
+ open={isOpened}
+ anchorEl={anchor.current}
+ transition
+ disablePortal
+ placement="bottom"
+ >
+ {({ TransitionProps, placement }) => (
+ <Grow
+ {...TransitionProps}
+ style={{
+ transformOrigin: placement
+ }}
+ >
+ <Paper className={classes.root}>
+ <ClickAwayListener onClickAway={disable} mouseEvent="onClick">
+ <div className={classes.container}>
+ <Button
+ onClick={() => {
+ disable();
+ onEdit(entityKey);
+ }}
+ color="primary"
+ variant="flat"
+ >
+ {i18n.t("Replace")}
+ </Button>
+ <IconButton onClick={() => onRemove(entityKey)}>
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </div>
+ </ClickAwayListener>
+ </Paper>
+ </Grow>
)}
- </Anchor>
- <img
- className={classes.image}
- src={contentState.getEntity(entityKey).getData().href}
- onClick={toggle}
- />
- </>
- )}
- </Toggle>
- )
+ </Popper>
+ </div>
+ <img
+ className={classes.image}
+ src={contentState.getEntity(entityKey).getData().href}
+ onClick={toggle}
+ />
+ </>
+ );
+ }
);
export default ImageEntity;
diff --git a/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx b/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx
index 0e79c6b70d..bf07375780 100644
--- a/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx
+++ b/saleor/static/dashboard-next/components/RichTextEditor/LinkEntity.tsx
@@ -16,9 +16,7 @@ import { ContentState } from "draft-js";
import * as React from "react";
import i18n from "../../i18n";
-import Anchor from "../Anchor";
import Link from "../Link";
-import Toggle from "../Toggle";
interface LinkEntityProps {
children: React.ReactNode;
@@ -67,71 +65,65 @@ const LinkEntity = withStyles(styles, {
entityKey,
onEdit,
onRemove
- }: LinkEntityProps & WithStyles<typeof styles>) => (
- <Toggle>
- {(isOpened, { disable, toggle }) => (
- <>
- <Anchor>
- {anchor => (
- <div className={classes.anchor} ref={anchor}>
- <Popper
- open={isOpened}
- anchorEl={anchor.current}
- transition
- disablePortal
- placement="bottom"
- >
- {({ TransitionProps, placement }) => (
- <Grow
- {...TransitionProps}
- style={{
- transformOrigin: placement
- }}
- >
- <Paper className={classes.root}>
- <ClickAwayListener
- onClickAway={disable}
- mouseEvent="onClick"
- >
- <div className={classes.container}>
- <Typography
- className={classes.inline}
- variant="body1"
- >
- {contentState.getEntity(entityKey).getData().href}
- </Typography>
- <span className={classes.separator} />
- <Button
- onClick={() => {
- disable();
- onEdit(entityKey);
- }}
- color="primary"
- variant="flat"
- >
- {i18n.t("Edit")}
- </Button>
- <IconButton onClick={() => onRemove(entityKey)}>
- <DeleteIcon color="primary" />
- </IconButton>
- </div>
- </ClickAwayListener>
- </Paper>
- </Grow>
- )}
- </Popper>
- </div>
- )}
- </Anchor>
- <Link
- href={contentState.getEntity(entityKey).getData().href}
- onClick={toggle}
+ }: LinkEntityProps & WithStyles<typeof styles>) => {
+ const [isOpened, setOpenStatus] = React.useState(false);
+ const anchor = React.useRef<HTMLDivElement>();
+
+ const disable = () => setOpenStatus(false);
+ const toggle = () => setOpenStatus(!isOpened);
+
+ return (
+ <>
+ <div className={classes.anchor} ref={anchor}>
+ <Popper
+ open={isOpened}
+ anchorEl={anchor.current}
+ transition
+ disablePortal
+ placement="bottom"
>
- {children}
- </Link>
- </>
- )}
- </Toggle>
- )
+ {({ TransitionProps, placement }) => (
+ <Grow
+ {...TransitionProps}
+ style={{
+ transformOrigin: placement
+ }}
+ >
+ <Paper className={classes.root}>
+ <ClickAwayListener onClickAway={disable} mouseEvent="onClick">
+ <div className={classes.container}>
+ <Typography className={classes.inline} variant="body1">
+ {contentState.getEntity(entityKey).getData().href}
+ </Typography>
+ <span className={classes.separator} />
+ <Button
+ onClick={() => {
+ disable();
+ onEdit(entityKey);
+ }}
+ color="primary"
+ variant="flat"
+ >
+ {i18n.t("Edit")}
+ </Button>
+ <IconButton onClick={() => onRemove(entityKey)}>
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </div>
+ </ClickAwayListener>
+ </Paper>
+ </Grow>
+ )}
+ </Popper>
+ </div>
+ <Link
+ href={contentState.getEntity(entityKey).getData().href}
+ onClick={toggle}
+ >
+ {children}
+ </Link>
+ </>
+ );
+ }
);
export default LinkEntity;
diff --git a/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsx b/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsx
index 8c46fad908..a8157c1af5 100644
--- a/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsx
+++ b/saleor/static/dashboard-next/components/TextFieldWithChoice/TextFieldWithChoice.tsx
@@ -9,7 +9,7 @@ import TextField, { TextFieldProps } from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import DropdownIcon from "@material-ui/icons/ArrowDropDown";
import * as React from "react";
-import Anchor from "../Anchor";
+
import MenuToggle from "../MenuToggle";
export type TextFieldWithChoiceProps<TValue = string> = TextFieldProps & {
@@ -43,89 +43,89 @@ const TextFieldWithChoice = withStyles(styles, {
classes,
onChange,
...props
- }: TextFieldWithChoiceProps & WithStyles<typeof styles>) => (
- <Anchor>
- {anchor => (
- <TextField
- {...props}
- onChange={onChange}
- InputProps={{
- ...InputProps,
- endAdornment: (
- <MenuToggle ariaOwns="user-menu">
- {({
- open: menuOpen,
- actions: { open: openMenu, close: closeMenu }
- }) => {
- const handleSelect = value => {
- onChange({
- target: {
- name: ChoiceProps.name,
- value
- }
- } as any);
- closeMenu();
- };
+ }: TextFieldWithChoiceProps & WithStyles<typeof styles>) => {
+ const anchor = React.useRef<HTMLDivElement>();
+
+ return (
+ <TextField
+ {...props}
+ onChange={onChange}
+ InputProps={{
+ ...InputProps,
+ endAdornment: (
+ <MenuToggle ariaOwns="user-menu">
+ {({
+ open: menuOpen,
+ actions: { open: openMenu, close: closeMenu }
+ }) => {
+ const handleSelect = value => {
+ onChange({
+ target: {
+ name: ChoiceProps.name,
+ value
+ }
+ } as any);
+ closeMenu();
+ };
- return (
- <>
- <div
- className={classes.adornment}
- ref={anchor}
- onClick={!menuOpen ? openMenu : undefined}
- >
- <Typography component="span" variant="caption">
- {ChoiceProps.label}
- </Typography>
- <DropdownIcon />
- </div>
- <Popper
- open={menuOpen}
- anchorEl={anchor.current}
- transition
- disablePortal
- placement="bottom-end"
- className={classes.menu}
- >
- {({ TransitionProps, placement }) => (
- <Grow
- {...TransitionProps}
- style={{
- transformOrigin:
- placement === "bottom"
- ? "right top"
- : "right bottom"
- }}
- >
- <Paper>
- <ClickAwayListener
- onClickAway={closeMenu}
- mouseEvent="onClick"
- >
- <Menu>
- {ChoiceProps.values.map(choice => (
- <MenuItem
- onClick={() => handleSelect(choice.value)}
- >
- {choice.label}
- </MenuItem>
- ))}
- </Menu>
- </ClickAwayListener>
- </Paper>
- </Grow>
- )}
- </Popper>
- </>
- );
- }}
- </MenuToggle>
- )
- }}
- />
- )}
- </Anchor>
- )
+ return (
+ <>
+ <div
+ className={classes.adornment}
+ ref={anchor}
+ onClick={!menuOpen ? openMenu : undefined}
+ >
+ <Typography component="span" variant="caption">
+ {ChoiceProps.label}
+ </Typography>
+ <DropdownIcon />
+ </div>
+ <Popper
+ open={menuOpen}
+ anchorEl={anchor.current}
+ transition
+ disablePortal
+ placement="bottom-end"
+ className={classes.menu}
+ >
+ {({ TransitionProps, placement }) => (
+ <Grow
+ {...TransitionProps}
+ style={{
+ transformOrigin:
+ placement === "bottom"
+ ? "right top"
+ : "right bottom"
+ }}
+ >
+ <Paper>
+ <ClickAwayListener
+ onClickAway={closeMenu}
+ mouseEvent="onClick"
+ >
+ <Menu>
+ {ChoiceProps.values.map(choice => (
+ <MenuItem
+ onClick={() => handleSelect(choice.value)}
+ >
+ {choice.label}
+ </MenuItem>
+ ))}
+ </Menu>
+ </ClickAwayListener>
+ </Paper>
+ </Grow>
+ )}
+ </Popper>
+ </>
+ );
+ }}
+ </MenuToggle>
+ )
+ }}
+ />
+ );
+ }
);
TextFieldWithChoice.displayName = "TextFieldWithChoice";
export default TextFieldWithChoice;