mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-21 13:47:39 +02:00
* refactor: update test deps * refactor: remove unused ts-expect-error annotations * refactor: add missing arg and return types * refactor: the loading prop is optional * refactor: add missing arg and return types * reafactor: fix value arg type * refactor: fix missing array type * refactor: the parameters field is an array * refactor: use undefined instead of null in state * refactor: add missing params type * refactor: add missing children prop * refactor: add missing array type * refactor: add missing React imports * refactor: use correct IProjectEnvironment type * refactor: type errors as unknown * refactor: the index prop is required * refactor: fix date prop type * refactor: fix tooltip placement prop type * refactor: fix environments state type * refactor: add missing arg types * refactor: add guard for undefined field * refactor: fix ChangePassword prop types * refactor: fix MUI import paths * refactor: add missing arg type * refactor: fix showDialog prop type * refactor: remove unused openUpdateDialog prop * refactor: add missing non-null assertion * refactor: remove unused types prop * refactor: stricten API error handler types * refactor: add missing undefined check * refactor: add missing IProject id field * refactor: fix ConditionallyRender condition prop types * refactor: remove unused args * refactor: add AddVariant prop types * refactor: add types to UIContext * refactor: fix event arg type * refactor: add missing default impressionData field * refactor: fix handleDeleteEnvironment prop args * refactor: fix IFeatureMetrics field requirements * refactor: add missing element types to ConditionallyRender * refactor: remove unused ProjectAccess projectId prop * refactor: add missing undefined check * refactor: fix getCreateTogglePath arg type * refactor: add missing IStrategyPayload import * refactor: remove unused user arg * refactor: add missing event arg type * refactor: add missing style object types * refactor: improve userApiErrors prop type * refactor: the Dialogue onClose prop is optional * refactor: fix the AddonEvents setEventValue prop type
114 lines
3.6 KiB
TypeScript
114 lines
3.6 KiB
TypeScript
import React, { Fragment, useState } from 'react';
|
|
import { Button, IconButton } from '@material-ui/core';
|
|
import { useStyles } from './Splash.styles';
|
|
import {
|
|
CloseOutlined,
|
|
FiberManualRecord,
|
|
FiberManualRecordOutlined,
|
|
} from '@material-ui/icons';
|
|
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 key={index} />;
|
|
});
|
|
};
|
|
|
|
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;
|