diff --git a/src/components/Element.tsx b/src/components/Element.tsx index 40aecb47..309699b4 100644 --- a/src/components/Element.tsx +++ b/src/components/Element.tsx @@ -1,5 +1,5 @@ import React from "react" -import { RenderElementProps } from "slate-react" +import { RenderElementProps, useSelected, useFocused } from "slate-react" import { makeStyles } from "@material-ui/core/styles" import Typography, { TypographyProps } from "@material-ui/core/Typography" import Divider from "@material-ui/core/Divider" @@ -8,6 +8,8 @@ import { types } from "../constants/types" type StyleProps = { lineSpacing: string | unknown align: string | unknown + selected: boolean + focused: boolean } const useStyles = makeStyles(() => ({ @@ -15,7 +17,13 @@ const useStyles = makeStyles(() => ({ lineHeight: props.lineSpacing, }), image: (props: StyleProps) => ({ + maxWidth: "100%", + maxHeight: "100%", + boxShadow: props.selected && props.focused ? "0 0 0 3px #B4D5FF" : "none", + }), + imageContainer: (props: StyleProps) => ({ textAlign: props.align, + display: "block", }), })) @@ -52,9 +60,13 @@ const Element = ({ attributes, children, element }: Props) => { width, height, } = element + const selected = useSelected() + const focused = useFocused() const styleProps = { lineSpacing: lineSpacing ? lineSpacing : "normal", align, + selected, + focused, } const classes = useStyles(styleProps) @@ -96,14 +108,18 @@ const Element = ({ attributes, children, element }: Props) => { ) case types.image: return ( - {description} +
+
+ {description} +
+ {children} +
) default: return (