Created
April 26, 2022 15:59
-
-
Save brunoksato/0ed83d971650f78f07fdf6032d5169d4 to your computer and use it in GitHub Desktop.
newsDetail.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Dialog } from 'evergreen-ui'; | |
interface INewsDetail { | |
isShown: boolean; | |
onClose: any; | |
data: any; | |
} | |
const NewsDetail = ({ isShown, onClose, data }: INewsDetail) => { | |
const setTextTypes = (child, child_idx, array) => { | |
if (typeof child === `string`) { | |
if (typeof array[child_idx + 1] !== `object` || array[child_idx + 1]?.type !== `url`) { | |
return child; | |
} | |
} else if (typeof child === `object`) { | |
if (child?.type === `url`) { | |
return ( | |
<a | |
href={child?.params?.url} | |
target="_blank" | |
rel="noopener noreferrer" | |
key={child_idx} | |
className="hover:underline" | |
> | |
{array[child_idx - 1]} | |
</a> | |
); | |
} | |
} | |
}; | |
return ( | |
<Dialog | |
width={700} | |
isShown={isShown} | |
onCloseComplete={onClose} | |
hasFooter={false} | |
title={data?.title} | |
> | |
<div> | |
{data?.description?.children?.map((item, idx) => { | |
if (item?.type === `p`) { | |
return ( | |
<p className="mb-4 text-gray-600" key={idx}> | |
{item?.children?.map((child, child_idx) => | |
setTextTypes(child, child_idx, item?.children), | |
)} | |
</p> | |
); | |
} | |
})} | |
</div> | |
</Dialog> | |
); | |
}; | |
export default NewsDetail; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment