PteroTheme/resources/scripts/components/FlashMessageRender.tsx

33 lines
967 B
TypeScript
Raw Normal View History

import React from 'react';
import MessageBox from '@/components/MessageBox';
2020-07-04 22:21:28 +01:00
import { useStoreState } from 'easy-peasy';
2020-07-04 20:39:55 +01:00
import tw from 'twin.macro';
type Props = Readonly<{
byKey?: string;
2020-07-04 22:21:28 +01:00
className?: string;
}>;
2020-07-04 22:21:28 +01:00
const FlashMessageRender = ({ byKey, className }: Props) => {
const flashes = useStoreState(state => state.flashes.items.filter(
flash => byKey ? flash.key === byKey : true,
));
return (
2020-07-04 22:21:28 +01:00
<div className={className}>
{
2020-07-04 22:21:28 +01:00
flashes.map((flash, index) => (
<React.Fragment key={flash.id || flash.type + flash.message}>
2020-07-04 20:39:55 +01:00
{index > 0 && <div css={tw`mt-2`}></div>}
<MessageBox type={flash.type} title={flash.title}>
{flash.message}
</MessageBox>
</React.Fragment>
))
}
</div>
);
};
2020-07-04 22:21:28 +01:00
export default FlashMessageRender;