Notes
![]() ![]() Notes - notes.io |
import clsx from 'clsx';
import { Typography, Button, Fab } from '@material-ui/core';
import SvgBackArrow from 'icons/ChevronLeft';
import Stepper from '@highradius/g4_ui_components/lib/components/atoms/Stepper';
import { FormattedMessage } from 'react-intl';
import FlexBox from 'components/FlexBox';
import useDynamicStepperLayoutStyle from './styles';
import messages from './messages';
const configParser = (newConfig: any) => {
const config = newConfig.filter((cnf) => !cnf.hidden);
const header: any = config?.map((item) => item.header);
const indicatorList: any = config?.map((item) => ({
label: item.label,
icon: item.icon,
}));
const content: any = config?.map((item) => item?.content?.map((i1) => i1));
const isDisabled: any = config?.map((item) => item.isDisabled);
return { header, indicatorList, content, isDisabled };
};
const DynamicStepperLayout = ({
isCreate = false,
config,
onSave,
onCancel,
onNext = () => {},
classes = { content: '', stepper: '' },
}: {
isCreate: boolean;
config: any;
onSave: any;
onCancel: any;
onNext?: any;
classes?: { content?: string; stepper?: string };
}) => {
const defaultClasses = useDynamicStepperLayoutStyle();
const { header, indicatorList, content, isDisabled } = React.useMemo(() => {
console.log('running');
return configParser(config);
}, [config]);
const [page, setPage] = React.useState(0);
const [innerContent, setInnerContent] = React.useState(0);
const lengthOfIndicatorList = React.useMemo(
() => indicatorList?.length - 1,
[indicatorList?.length],
);
const handleNextButton = () => {
onNext();
if (content[page].length > 1) {
if (content[page].length - 1 === innerContent) {
setPage(
page >= lengthOfIndicatorList ? lengthOfIndicatorList : page + 1,
);
setInnerContent(0);
} else {
setInnerContent(innerContent + 1);
}
} else {
setPage(page >= lengthOfIndicatorList ? lengthOfIndicatorList : page + 1);
setInnerContent(0);
}
};
const handlePreviousButton = () => {
setPage(page <= 0 ? 0 : page - 1);
setInnerContent(0);
};
const handleCancel = () => {
onCancel();
setPage(0);
};
const buttonText = (isLast) => {
if (isLast && isCreate)
return (
<Typography variant="body2">
<FormattedMessage {...messages.createText} />
</Typography>
);
if (isLast && !isCreate)
return (
<Typography variant="body2">
<FormattedMessage {...messages.saveText} />
</Typography>
);
return (
<Typography variant="body2">
<FormattedMessage {...messages.nextText} />
</Typography>
);
};
const getFooter = (isLast: any) => (
<FlexBox justifyContent="flex-end" className={defaultClasses.footer}>
<Button variant="outlined" onClick={handleCancel}>
<Typography variant="body2">
<FormattedMessage {...messages.cancelText} />
</Typography>
</Button>
<Button
variant="contained"
disabled={isDisabled[page]}
onClick={isLast ? onSave : handleNextButton}
>
{buttonText(isLast)}
</Button>
</FlexBox>
);
return (
<FlexBox
justifyContent="space-between"
direction="column"
overflow="hidden"
className={defaultClasses.root}
>
<div className={clsx(defaultClasses.stepper, classes.stepper)}>
<Stepper activeStep={page} stepperContent={indicatorList} />
</div>
<FlexBox
justifyContent="space-between"
direction="column"
overflow="hidden"
className={clsx(defaultClasses.content, classes.content)}
>
<FlexBox direction="column" overflow="hidden" fullWidth>
{header[page] && (
<FlexBox alignItems="center" className={defaultClasses.heading}>
<Fab
size="small"
onClick={page === 0 ? handleCancel : handlePreviousButton}
>
<SvgBackArrow />
</Fab>
<Typography variant="h2">{header[page]}</Typography>
</FlexBox>
)}
{content[page][innerContent]}
</FlexBox>
{getFooter(page === lengthOfIndicatorList)}
</FlexBox>
</FlexBox>
);
};
export default DynamicStepperLayout;
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team