mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-28 17:55:15 +02:00
* splash screen * add styles for controllers * feat: animated circles * fix: remove unused code * fix: folder structure * create splash screens for envs * add styles and ui changes * fix: revert App.tsx * add splash state to store * add splash to app.tsx + add a loader * fix: mobile view + desktop view * fix: render splash condition + styling fix * fix: change splash display to full screen * Update src/hooks/api/actions/useSplashApi/useSplashApi.ts Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com> * fix: change function type Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com> * fix: disable incrementing counter when matching the components length. * fix: add SWR configuration * fix: spelling mistakes in splash screen * fix: add keys and adjust styling * fix: tests * fix: tests * fix: default command timeout Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
115 lines
3.6 KiB
TypeScript
115 lines
3.6 KiB
TypeScript
import { Fragment } from 'react';
|
|
import { Button, IconButton } from '@material-ui/core';
|
|
import { useStyles } from './Splash.styles';
|
|
import {
|
|
FiberManualRecord,
|
|
FiberManualRecordOutlined,
|
|
CloseOutlined,
|
|
} from '@material-ui/icons';
|
|
import { useState } from 'react';
|
|
import ConditionallyRender from '../ConditionallyRender';
|
|
import { CLOSE_SPLASH } from '../../../testIds';
|
|
|
|
interface ISplashProps {
|
|
components: React.ReactNode[];
|
|
onFinish: (status: boolean) => void;
|
|
}
|
|
|
|
const Splash: React.FC<ISplashProps> = ({
|
|
components,
|
|
onFinish,
|
|
}: ISplashProps) => {
|
|
const styles = useStyles();
|
|
const [counter, setCounter] = useState(0);
|
|
|
|
const onNext = () => {
|
|
if (counter === components.length - 1) {
|
|
onFinish(false);
|
|
return;
|
|
}
|
|
setCounter(counter + 1);
|
|
};
|
|
|
|
const onBack = () => {
|
|
setCounter(counter - 1);
|
|
};
|
|
const onClose = () => {
|
|
onFinish(false);
|
|
};
|
|
|
|
const calculatePosition = () => {
|
|
if (counter === 0) {
|
|
return '0';
|
|
}
|
|
|
|
return counter * 24;
|
|
};
|
|
|
|
const renderCircles = () => {
|
|
return components.map((_, index) => {
|
|
if (index === 0) {
|
|
// Use index as key because the amount of pages will never dynamically change.
|
|
return (
|
|
<Fragment key={index}>
|
|
<FiberManualRecordOutlined />
|
|
<FiberManualRecord
|
|
style={{
|
|
position: 'absolute',
|
|
transition: 'transform 0.3s ease',
|
|
left: '0',
|
|
transform: `translateX(${calculatePosition()}px)`,
|
|
}}
|
|
/>
|
|
</Fragment>
|
|
);
|
|
}
|
|
|
|
return <FiberManualRecordOutlined />;
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div className={styles.splashMainContainer}>
|
|
<div className={styles.splashContainer}>
|
|
<div className={styles.closeButtonContainer}>
|
|
<IconButton
|
|
className={styles.closeButton}
|
|
onClick={onClose}
|
|
data-test={CLOSE_SPLASH}
|
|
>
|
|
<CloseOutlined />
|
|
</IconButton>
|
|
</div>
|
|
{components[counter]}
|
|
<div className={styles.controllers}>
|
|
<div className={styles.circlesContainer}>
|
|
<div className={styles.circles}>{renderCircles()}</div>
|
|
</div>
|
|
<div className={styles.buttonsContainer}>
|
|
<ConditionallyRender
|
|
condition={counter > 0}
|
|
show={
|
|
<Button
|
|
className={styles.button}
|
|
disabled={counter === 0}
|
|
onClick={onBack}
|
|
>
|
|
Back
|
|
</Button>
|
|
}
|
|
/>
|
|
|
|
<Button className={styles.nextButton} onClick={onNext}>
|
|
{counter === components.length - 1
|
|
? 'Finish'
|
|
: 'Next'}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Splash;
|