Skip to content

Commit

Permalink
Merge pull request #45 from aceleradora-TW/30/componente-descricao-to…
Browse files Browse the repository at this point in the history
…picos-referencias-exercicios

30/componente descricao topicos referencias exercicios
  • Loading branch information
daniellemadrid authored Aug 29, 2024
2 parents 852f2ad + 51279b7 commit 0f8c773
Show file tree
Hide file tree
Showing 14 changed files with 1,807 additions and 183 deletions.
1,598 changes: 1,511 additions & 87 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
"husky": "^9.0.11",
"next": "14.2.3",
"react": "^18",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18",
"react-markdown": "^9.0.1",
"react-syntax-highlighter": "^15.5.0",
"styled-components": "^6.1.11"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-copy-to-clipboard": "^5.0.7",
"@types/react-dom": "^18",
"@types/react-syntax-highlighter": "^15.5.13",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"postcss": "^8",
Expand Down
19 changes: 12 additions & 7 deletions src/app/config/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ declare module "@mui/material/styles" {
margin: string;
borderRadius: string;
};
linkReference:{
color: string;
},
logoType: {
fontSize: string;
mr: number;
Expand Down Expand Up @@ -176,8 +179,7 @@ declare module "@mui/material/styles" {
boxShadow: string;
maxWidth: string;
height: string;
margin: string;
marginTop: string;
boxSizing: string;
borderRadius: string,
};
cardVideoLink:{
Expand Down Expand Up @@ -258,6 +260,9 @@ declare module "@mui/material/styles" {
margin?: string;
borderRadius?: string;
};
linkReference:{
color?: string;
},
logoType: {
fontSize?: string;
mr?: number;
Expand Down Expand Up @@ -340,8 +345,7 @@ declare module "@mui/material/styles" {
boxShadow?: string;
maxWidth?: string;
height?: string;
margin?: string;
marginTop?: string;
boxSizing?: string;
borderRadius?: string;
};
cardVideoLink?:{
Expand Down Expand Up @@ -389,7 +393,6 @@ const theme = createTheme({
},
description:{
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
padding: 2,
boxShadow: "0em 0em 0.4em rgb(44 44 44 / 40% );",
Expand Down Expand Up @@ -423,6 +426,9 @@ const theme = createTheme({
margin: "0 0.5rem",
borderRadius: "0",
},
linkReference:{
color: themePalette.descriptionCard
},
logoType: {
fontSize: "19.2px",
mr: 2,
Expand Down Expand Up @@ -504,8 +510,7 @@ const theme = createTheme({
boxShadow: "0em 0em 0.4em rgb(44 44 44 / 40%)",
maxWidth: "100%",
height: "100%",
margin: "24px",
marginTop: "17px",
boxSizing: "border-box",
borderRadius: "6px",
},
cardVideoLink:{
Expand Down
20 changes: 0 additions & 20 deletions src/app/teste/page.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions src/components/CardVideo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const components = {
),
};
interface CardVideoProps{
text : string;
text: string;
title: string;
linkVideo: string;
references?: string;
Expand Down Expand Up @@ -46,9 +46,6 @@ export const CardVideo: React.FC<CardVideoProps>=({ text, title, linkVideo, refe
{text}
</ReactMarkdown>
</Box>
<Box sx={theme.customStyles.cardVideoSelect}>
<StatusSelect />
</Box>
</Box>
</Box>
);
Expand Down
74 changes: 74 additions & 0 deletions src/components/Description/DescriptionDivider/index.tsx
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>
)}
</>
);
};
117 changes: 117 additions & 0 deletions src/components/Description/DescriptionFull/index.tsx
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>
);
};
35 changes: 35 additions & 0 deletions src/components/Description/DescriptionReference/index.tsx
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>
);
};
Loading

0 comments on commit 0f8c773

Please sign in to comment.