Skip to content

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

Improve error state

dominik-zeglende0ec4d2d288
diff --git a/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx b/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx
index f9a5376cb2..94d4c83b84 100644
--- a/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx
+++ b/saleor/static/dashboard-next/components/RichTextEditor/RichTextEditor.tsx
@@ -12,6 +12,7 @@ import UnorderedListIcon from "@material-ui/icons/FormatListBulleted";
import OrderedListIcon from "@material-ui/icons/FormatListNumbered";
import QuotationIcon from "@material-ui/icons/FormatQuote";
import LinkIcon from "@material-ui/icons/Link";
+import * as classNames from "classnames";
import { RawDraftContentState } from "draft-js";
import {
BLOCK_TYPE,
@@ -28,6 +29,8 @@ import LinkSource from "./LinkSource";
export interface RichTextEditorProps {
disabled: boolean;
+ error: boolean;
+ helperText: string;
label: string;
name: string;
initial?: RawDraftContentState;
@@ -36,6 +39,28 @@ export interface RichTextEditorProps {
const styles = (theme: Theme) =>
createStyles({
+ "@keyframes focus": {
+ from: {
+ transform: "scaleX(0) scaleY(1)"
+ },
+ to: {
+ transform: "scaleX(1) scaleY(1)"
+ }
+ },
+ "@keyframes hover": {
+ from: {
+ transform: "scaleX(1) scaleY(0)"
+ },
+ to: {
+ transform: "scaleX(1) scaleY(1)"
+ }
+ },
+ error: {
+ color: theme.palette.error.main
+ },
+ helperText: {
+ marginTop: theme.spacing.unit * 0.75
+ },
label: {
marginBottom: theme.spacing.unit * 2
},
@@ -46,18 +71,21 @@ const styles = (theme: Theme) =>
color: theme.palette.secondary.light
},
"&:after": {
- background: theme.palette.primary.main,
+ animationDuration: theme.transitions.duration.shortest + "ms",
+ animationFillMode: "both",
+ background: theme.palette.grey[700],
bottom: -1,
content: "''",
display: "block",
height: 2,
position: "absolute",
- transform: "scaleX(0)",
- transition: theme.transitions.duration.short + "ms",
+ transform: "scaleX(0) scaleY(0)",
width: "100%"
},
"&:hover": {
- borderBottom: ``
+ "&:after": {
+ animationName: "hover"
+ }
},
borderBottom: `1px ${theme.palette.grey[500]} solid`,
paddingBottom: theme.spacing.unit / 2,
@@ -73,7 +101,9 @@ const styles = (theme: Theme) =>
"& .DraftEditor": {
"&-editorContainer": {
"&:after": {
- transform: "scaleX(1)"
+ animationName: "focus !important",
+ background: theme.palette.primary.main,
+ transform: "scaleX(0) scaleY(1)"
}
}
}
@@ -138,18 +168,50 @@ const styles = (theme: Theme) =>
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`
}
}
+ },
+
+ "&$error": {
+ "& .Draftail": {
+ "&-Editor": {
+ "& .DraftEditor": {
+ "&-editorContainer": {
+ "&:after": {
+ animationName: "none",
+ background: theme.palette.error.main,
+ transform: "scaleX(1) scaleY(1)"
+ }
+ }
+ },
+ "&--focus": {
+ "& .DraftEditor": {
+ "&-editorContainer": {
+ "&:after": {
+ animationName: "none !important"
+ }
+ }
+ }
+ }
+ }
+ }
}
}
});
const RichTextEditor = withStyles(styles, { name: "RichTextEditor" })(
({
classes,
+ error,
+ helperText,
initial,
label,
name,
onChange
}: RichTextEditorProps & WithStyles<typeof styles>) => (
- <div className={classes.root}>
+ <div
+ className={classNames({
+ [classes.error]: error,
+ [classes.root]: true
+ })}
+ >
<Typography className={classes.label} variant="caption" color="primary">
{label}
</Typography>
@@ -186,6 +248,15 @@ const RichTextEditor = withStyles(styles, { name: "RichTextEditor" })(
}
]}
/>
+ <Typography
+ className={classNames({
+ [classes.error]: error,
+ [classes.helperText]: true
+ })}
+ variant="caption"
+ >
+ {helperText}
+ </Typography>
</div>
)
);