-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from aceleradora-TW/30/componente-descricao-to…
…picos-referencias-exercicios 30/componente descricao topicos referencias exercicios
- Loading branch information
Showing
14 changed files
with
1,807 additions
and
183 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from "react"; | ||
import { Divider, Box, Typography, useMediaQuery, Link } from "@mui/material"; | ||
import { theme, themePalette } from "@/app/config/theme"; | ||
import ReactMarkdown from "react-markdown"; | ||
import { DescriptionFull } from "../DescriptionFull"; | ||
|
||
interface DescriptionDividerProps { | ||
text: string; | ||
} | ||
|
||
const boxStyle: object = { | ||
width: "49%" | ||
} | ||
|
||
export const DescriptionDivider: React.FC<DescriptionDividerProps> = ({ text }) => { | ||
const descriptionSize: number = text.length; | ||
const middleTextPoint: number = Math.floor(descriptionSize / 2); | ||
|
||
let splitPoint: number = middleTextPoint; | ||
while (splitPoint > 0 && text[splitPoint] !== ' ') { | ||
splitPoint--; | ||
} | ||
|
||
if (splitPoint === 0) { | ||
splitPoint = middleTextPoint; | ||
} | ||
|
||
const components = { | ||
p: (props: React.HTMLAttributes<HTMLHeadingElement>) => ( | ||
<Typography variant="body1" {...props} /> | ||
), | ||
a: (props: React.HTMLAttributes<HTMLAnchorElement>) => ( | ||
<Link | ||
variant="caption" target="_blank" rel="noreferrer" | ||
sx={{ color: themePalette.descriptionCard, textDecorationColor: themePalette.descriptionCard, display: "block" }} | ||
{...props} /> | ||
) | ||
}; | ||
|
||
const typographyBreakLine = { | ||
p: (props:React.HTMLAttributes<HTMLHeadingElement> ) => ( | ||
<Typography variant="body1" sx={{marginBottom: 3}} {...props} /> | ||
), | ||
} | ||
|
||
const textBox1: string = text.substring(0, splitPoint); | ||
const textBox2: string = text.substring(splitPoint).trim(); | ||
|
||
const isSmallScreen: boolean = useMediaQuery(theme.breakpoints.down('md')); | ||
|
||
return ( | ||
<> | ||
{isSmallScreen ? ( | ||
<DescriptionFull text={text}/> | ||
) : ( | ||
<Box sx={{...theme.customStyles.description}}> | ||
<Box sx={boxStyle}> | ||
<ReactMarkdown components={components}> | ||
{textBox1.replace(/\n\n/g, "")} | ||
</ReactMarkdown> | ||
</Box> | ||
|
||
<Divider orientation="vertical" flexItem color="black" sx={{ margin: 0 }} /> | ||
|
||
<Box sx={boxStyle}> | ||
<ReactMarkdown components={components}> | ||
{textBox2.replace(/\n\n/g, "")} | ||
</ReactMarkdown> | ||
</Box> | ||
</Box> | ||
)} | ||
</> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React, { useState } from "react"; | ||
import { Box, Link, Typography, Snackbar, Alert, Grid } from "@mui/material"; | ||
import { theme, themePalette } from "@/app/config/theme"; | ||
import ReactMarkdown from "react-markdown"; | ||
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; | ||
import { materialDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; | ||
import ContentCopyIcon from "@mui/icons-material/ContentCopy"; | ||
|
||
interface DescriptionFullProps { | ||
text: string; | ||
} | ||
|
||
export const DescriptionFull: React.FC<DescriptionFullProps> = ({ | ||
text, | ||
}) => { | ||
const [copySuccess, setCopySuccess] = useState(false); | ||
|
||
const handleCopy = (code: string) => { | ||
navigator.clipboard.writeText(code).then(() => { | ||
setCopySuccess(true); | ||
setTimeout(() => setCopySuccess(false), 2000); | ||
}); | ||
}; | ||
|
||
const components = { | ||
p: (props: React.HTMLAttributes<HTMLParagraphElement>) => ( | ||
<Typography variant="body1" sx={{ marginBottom: 3 }} {...props} /> | ||
), | ||
a: (props: React.HTMLAttributes<HTMLAnchorElement>) => ( | ||
<Link | ||
variant="body1" | ||
target="_blank" | ||
rel="noreferrer" | ||
sx={{ | ||
color: themePalette.descriptionCard, | ||
textDecorationColor: themePalette.descriptionCard, | ||
display: "block", | ||
}} | ||
{...props} | ||
/> | ||
), | ||
code: ({ node, inline, className, children, ...props }: any) => { | ||
const match = /language-(\w+)/.exec(className || ""); | ||
const codeString = String(children).replace(/\n$/, ""); | ||
return !inline && match ? ( | ||
<Box | ||
component="div" | ||
sx={{ | ||
position: "relative", | ||
cursor: "pointer" | ||
}} | ||
onClick={() => handleCopy(codeString)} | ||
> | ||
<SyntaxHighlighter | ||
style={materialDark} | ||
language={match[1]} | ||
PreTag="div" | ||
{...props} | ||
showLineNumbers={true} | ||
customStyle={{ | ||
margin: 0, | ||
borderRadius: "4px", | ||
}} | ||
> | ||
{codeString} | ||
</SyntaxHighlighter> | ||
<Box | ||
sx={{ | ||
position: "absolute", | ||
top: "24px", | ||
right: "16px", | ||
cursor: "pointer", | ||
|
||
}} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
handleCopy(codeString); | ||
}} | ||
> | ||
<ContentCopyIcon sx={{ color: "white" }} /> | ||
</Box> | ||
</Box> | ||
) : ( | ||
<Typography | ||
component="span" | ||
sx={{ | ||
fontFamily: "monospace", | ||
backgroundColor: "#f5f5f5", | ||
padding: "2px 4px", | ||
borderRadius: "4px", | ||
wordBreak: "break-word", | ||
whiteSpace: "pre-wrap", | ||
}} | ||
> | ||
{children} | ||
</Typography> | ||
); | ||
}, | ||
}; | ||
|
||
return ( | ||
<Grid container alignItems="stretch" sx={{...theme.customStyles.description, height: "100%"}}> | ||
<Grid item xl={12} lg={12} md={12} sm={12} xs={12}> | ||
<ReactMarkdown components={components}>{text}</ReactMarkdown> | ||
<Snackbar | ||
open={copySuccess} | ||
anchorOrigin={{ vertical: "bottom", horizontal: "center" }} | ||
autoHideDuration={2000} | ||
> | ||
<Alert severity="success" sx={{ width: "100%" }}> | ||
Código copiado para a área de transferência! | ||
</Alert> | ||
</Snackbar> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import { Box, Grid, Link, Typography } from "@mui/material"; | ||
import { theme, themePalette } from "@/app/config/theme"; | ||
import ReactMarkdown from "react-markdown"; | ||
|
||
interface DescriptionReferenceProps { | ||
text: string; | ||
} | ||
|
||
export const DescriptionReference: React.FC<DescriptionReferenceProps> = ({ | ||
text, | ||
}) => { | ||
const components = { | ||
a: (props: React.HTMLAttributes<HTMLAnchorElement>) => ( | ||
<Link | ||
variant="caption" | ||
target="_blank" | ||
rel="noreferrer" | ||
sx={{ | ||
color: themePalette.descriptionCard, | ||
textDecorationColor: themePalette.descriptionCard, | ||
display: "block", | ||
}} | ||
{...props} | ||
/> | ||
), | ||
}; | ||
return ( | ||
<Grid container alignItems="stretch" sx={{...theme.customStyles.description}}> | ||
<Grid item xl={12} lg={12} md={12} sm={12} xs={12}> | ||
<ReactMarkdown components={components}>{text}</ReactMarkdown> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
Oops, something went wrong.