-
Notifications
You must be signed in to change notification settings - Fork 4
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 #68 from kleros/feat/file-attachment-display
Feat/file attachment display
- Loading branch information
Showing
16 changed files
with
774 additions
and
14 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { type DocRenderer } from "@cyntler/react-doc-viewer"; | ||
import ReactMarkdown from "react-markdown"; | ||
|
||
const Container = styled.div` | ||
padding: 16px; | ||
`; | ||
|
||
const StyledMarkdown = styled(ReactMarkdown)` | ||
background-color: ${({ theme }) => theme.whiteBackground}; | ||
a { | ||
font-size: 16px; | ||
} | ||
code { | ||
color: ${({ theme }) => theme.secondaryText}; | ||
} | ||
`; | ||
|
||
const MarkdownRenderer: DocRenderer = ({ mainState: { currentDocument } }) => { | ||
if (!currentDocument) return null; | ||
const base64String = (currentDocument.fileData as string).split(",")[1]; | ||
|
||
// Decode the base64 string | ||
const decodedData = atob(base64String); | ||
|
||
return ( | ||
<Container id="md-renderer"> | ||
<StyledMarkdown>{decodedData}</StyledMarkdown> | ||
</Container> | ||
); | ||
}; | ||
|
||
MarkdownRenderer.fileTypes = ["md", "text/plain"]; | ||
MarkdownRenderer.weight = 1; | ||
|
||
export default MarkdownRenderer; |
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,53 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import DocViewer, { DocViewerRenderers } from "@cyntler/react-doc-viewer"; | ||
|
||
import "@cyntler/react-doc-viewer/dist/index.css"; | ||
|
||
import MarkdownRenderer from "./Viewers/MarkdownViewer"; | ||
import { customScrollbar } from "styles/customScrollbar"; | ||
|
||
const Wrapper = styled.div` | ||
background-color: ${({ theme }) => theme.whiteBackground}; | ||
border-radius: 3px; | ||
box-shadow: 0px 2px 3px 0px rgba(0, 0, 0, 0.06); | ||
max-height: 1050px; | ||
overflow: scroll; | ||
${customScrollbar} | ||
`; | ||
|
||
const StyledDocViewer = styled(DocViewer)` | ||
background-color: ${({ theme }) => theme.whiteBackground} !important; | ||
`; | ||
|
||
/** | ||
* @description this viewer supports loading multiple files, it can load urls, local files, etc | ||
* @param url The url of the file to be displayed | ||
* @returns renders the file | ||
*/ | ||
const FileViewer: React.FC<{ url: string }> = ({ url }) => { | ||
const docs = [{ uri: url }]; | ||
return ( | ||
<Wrapper className="file-viewer-wrapper"> | ||
<StyledDocViewer | ||
documents={docs} | ||
pluginRenderers={[...DocViewerRenderers, MarkdownRenderer]} | ||
config={{ | ||
header: { | ||
disableHeader: true, | ||
disableFileName: true, | ||
}, | ||
pdfZoom: { | ||
defaultZoom: 0.8, | ||
zoomJump: 0.1, | ||
}, | ||
pdfVerticalScrollByDefault: true, // false as default | ||
}} | ||
/> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default FileViewer; |
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,49 @@ | ||
import React from "react"; | ||
import styled, { type CSSProperties, keyframes } from "styled-components"; | ||
|
||
import KlerosIcon from "svgs/icons/kleros.svg"; | ||
|
||
type Width = CSSProperties["width"]; | ||
type Height = CSSProperties["height"]; | ||
|
||
const breathing = keyframes` | ||
0% { | ||
transform: scale(1); | ||
} | ||
50% { | ||
transform: scale(1.3); | ||
} | ||
100% { | ||
transform: scale(1); | ||
} | ||
`; | ||
|
||
const StyledKlerosIcon = styled(KlerosIcon)` | ||
path { | ||
fill: ${({ theme }) => theme.klerosUIComponentsStroke}; | ||
} | ||
animation: ${breathing} 2s ease-out infinite normal; | ||
`; | ||
|
||
const Container = styled.div<{ width?: Width; height?: Height }>` | ||
width: ${({ width }) => width ?? "100%"}; | ||
height: ${({ height }) => height ?? "100%"}; | ||
`; | ||
|
||
interface ILoader { | ||
width?: Width; | ||
height?: Height; | ||
className?: string; | ||
} | ||
|
||
const Loader: React.FC<ILoader> = ({ width, height, className }) => { | ||
return ( | ||
<Container {...{ width, height, className }}> | ||
<StyledKlerosIcon /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Loader; |
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 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,73 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { useNavigate } from "react-router-dom"; | ||
|
||
import { Button } from "@kleros/ui-components-library"; | ||
|
||
import Arrow from "svgs/icons/arrow-left.svg"; | ||
import PaperClip from "svgs/icons/paperclip.svg"; | ||
|
||
import { responsiveSize } from "styles/responsiveSize"; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 38px; | ||
`; | ||
|
||
const TitleContainer = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 8px; | ||
`; | ||
|
||
const Title = styled.h1` | ||
margin: 0px; | ||
font-size: ${responsiveSize(16, 24)}; | ||
`; | ||
|
||
const StyledPaperClip = styled(PaperClip)` | ||
width: ${responsiveSize(16, 24)}; | ||
height: ${responsiveSize(16, 24)}; | ||
path { | ||
fill: ${({ theme }) => theme.primaryPurple}; | ||
} | ||
`; | ||
|
||
const StyledButton = styled(Button)` | ||
background-color: transparent; | ||
padding: 0; | ||
.button-text { | ||
color: ${({ theme }) => theme.primaryBlue}; | ||
font-weight: 400; | ||
} | ||
.button-svg { | ||
path { | ||
fill: ${({ theme }) => theme.primaryBlue}; | ||
} | ||
} | ||
:focus, | ||
:hover { | ||
background-color: transparent; | ||
} | ||
`; | ||
|
||
const Header: React.FC = () => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Container> | ||
<TitleContainer> | ||
<StyledPaperClip /> | ||
<Title>Attachment File</Title>{" "} | ||
</TitleContainer> | ||
<StyledButton text="Return" Icon={Arrow} onClick={() => navigate(-1)} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Header; |
Oops, something went wrong.