forked from Chia-Network/chia-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
used dropzone for on the trading page
- Loading branch information
Showing
8 changed files
with
30,738 additions
and
170 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
36 changes: 36 additions & 0 deletions
36
electron-react/src/components/core/components/AspectRatio/AspectRatio.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { ReactNode } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Box } from '@material-ui/core'; | ||
|
||
const OuterWrapper = styled(({ ration, ...rest }) => <Box {...rest} />)` | ||
position: relative; | ||
width: 100%; | ||
height: 0; | ||
padding-bottom: ${(props) => (1 / props.ratio) * 100}%; | ||
overflow: hidden; | ||
`; | ||
|
||
export const InnerWrapper = styled(Box)` | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
`; | ||
|
||
type Props = { | ||
ratio: number; | ||
children: ReactNode; | ||
}; | ||
|
||
export default function AspectRatio(props: Props) { | ||
const { children, ratio } = props; | ||
|
||
return ( | ||
<OuterWrapper ratio={ratio}> | ||
<InnerWrapper> | ||
{children} | ||
</InnerWrapper> | ||
</OuterWrapper> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
electron-react/src/components/core/components/AspectRatio/index.ts
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 @@ | ||
export { default } from './AspectRatio'; |
64 changes: 64 additions & 0 deletions
64
electron-react/src/components/core/components/Dropzone/Dropzone.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { Paper, CircularProgress } from '@material-ui/core'; | ||
import styled from 'styled-components'; | ||
import { useDropzone, DropzoneOptions } from 'react-dropzone'; | ||
import AspectRatio from '../AspectRatio'; | ||
import Flex from '../Flex'; | ||
|
||
const StyledPaper = styled(Paper)` | ||
background-color: #999999; | ||
padding: ${({ theme }) => `${theme.spacing(1)}px ${theme.spacing(2)}px`}; | ||
`; | ||
|
||
type ChildrenRender = (input: { | ||
isDragActive: boolean; | ||
}) => ReactNode | ||
|
||
type Props = { | ||
children: ReactNode | ChildrenRender; | ||
onDrop: (acceptedFiles: File[]) => void; | ||
maxFiles?: number; | ||
accept?: string[]; // ['image/jpeg', 'image/png'] | ||
ratio: number; | ||
processing?: boolean; | ||
}; | ||
|
||
export default function Dropzone(props: Props) { | ||
const { children, onDrop, maxFiles, accept, ratio, processing } = props; | ||
|
||
const config: DropzoneOptions = { | ||
onDrop, | ||
maxFiles, | ||
}; | ||
|
||
if (accept) { | ||
config.accept = accept.join(', '); | ||
} | ||
|
||
const { getRootProps, getInputProps, isDragActive } = useDropzone(config); | ||
const childrenContent = typeof children === 'function' | ||
? children({ isDragActive }) | ||
: children; | ||
|
||
return ( | ||
<div {...getRootProps()}> | ||
<input {...getInputProps()} /> | ||
<StyledPaper> | ||
<AspectRatio ratio={ratio}> | ||
<Flex alignItems="center" justifyContent="center" flexDirection="column" height="100%"> | ||
{processing ? ( | ||
<CircularProgress color="secondary" /> | ||
) : childrenContent} | ||
</Flex> | ||
</AspectRatio> | ||
</StyledPaper> | ||
</div> | ||
); | ||
} | ||
|
||
Dropzone.defaultProps = { | ||
maxFiles: undefined, | ||
accept: undefined, | ||
ratio: 16/6, | ||
processing: false, | ||
}; |
1 change: 1 addition & 0 deletions
1
electron-react/src/components/core/components/Dropzone/index.ts
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 @@ | ||
export { default } from './Dropzone'; |
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