💫(ap-impress) improve transition

Improve transition on Box component.
This commit is contained in:
Anthony LC
2024-04-18 15:38:14 +02:00
committed by Anthony LC
parent f61047dd6a
commit 4de79c2388
3 changed files with 35 additions and 35 deletions

View File

@@ -47,11 +47,22 @@ export const Box = styled('div')<BoxProps>`
${({ $minWidth }) => $minWidth && `min-width: ${$minWidth};`}
${({ $css }) => $css && `${$css};`}
${({ $effect }) => {
let effect;
switch ($effect) {
case 'show':
return showEffect;
effect = showEffect;
break;
case 'hide':
return hideEffect;
effect = hideEffect;
break;
}
return (
effect &&
`
transition: all 0.3s ease-in-out;
${effect}
`
);
}}
`;

View File

@@ -1,20 +1,11 @@
import { css, keyframes } from 'styled-components';
const show = keyframes`
0% { transform: scaleY(0); opacity: 0; max-height: 0; }
100% { transform: scaleY(1); opacity: 1; max-height: 150px;}
export const showEffect = `
transform: scaleY(1);
opacity: 1;
max-height: 150px;
`;
const hide = keyframes`
0% { transform: scaleY(1); opacity: 1; max-height: 150px;}
100% { display:none; transform: scaleY(0); opacity: 0; max-height: 0; }
`;
export const showEffect = css`
animation: ${show} 0.3s ease-in-out;
`;
export const hideEffect = css`
animation: ${hide} 0.3s ease-in-out;
animation-fill-mode: forwards;
export const hideEffect = `
transform: scaleY(0);
opacity: 0;
max-height: 0;
`;

View File

@@ -31,17 +31,17 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => {
},
});
const [editor, setEditor] = useState<Editor>();
const [showWarning, setShowWarning] = useState(false);
const html = editor?.getHtml();
const [showWarning, setShowWarning] = useState(!!html);
useEffect(() => {
if (showWarning || !html) {
if (!html) {
return;
}
setShowWarning(html.includes('{{body}}') === false);
}, [html, showWarning]);
setShowWarning(!html.includes('{{body}}'));
}, [html]);
useEffect(() => {
if (!editor?.loadProjectData || !editor?.Storage) {
@@ -106,17 +106,15 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => {
{t('Save template')}
</Button>
</Box>
{showWarning && html && (
<Box
className="m-b"
$css="margin-top:0;"
$effect={html.includes('{{body}}') ? 'hide' : 'show'}
>
<Alert
type={VariantType.WARNING}
>{`The {{body}} tag is necessary to works with the pads.`}</Alert>
</Box>
)}
<Box
className="m-b"
$css="margin-top:0;"
$effect={showWarning ? 'show' : 'hide'}
>
<Alert
type={VariantType.WARNING}
>{`The {{body}} tag is necessary to works with the pads.`}</Alert>
</Box>
{!template.abilities.partial_update && (
<Box className="m-b" $css="margin-top:0;">