-
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 #63 from permaweb/permaweb-libs
Permaweb libs
- Loading branch information
Showing
37 changed files
with
1,055 additions
and
964 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
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.
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,101 @@ | ||
import React from 'react'; | ||
|
||
import { IconButton } from 'components/atoms/IconButton'; | ||
import { Portal } from 'components/atoms/Portal'; | ||
import { ASSETS, DOM } from 'helpers/config'; | ||
import { useLanguageProvider } from 'providers/LanguageProvider'; | ||
import { CloseHandler } from 'wrappers/CloseHandler'; | ||
|
||
import * as S from './styles'; | ||
import { IProps } from './types'; | ||
|
||
export default function Panel(props: IProps) { | ||
const languageProvider = useLanguageProvider(); | ||
const language = languageProvider.object[languageProvider.current]; | ||
|
||
React.useEffect(() => { | ||
hideDocumentBody(); | ||
return () => { | ||
showDocumentBody(); | ||
}; | ||
}, []); | ||
|
||
const escFunction = React.useCallback( | ||
(e: any) => { | ||
if (e.key === 'Escape' && props.handleClose && !props.closeHandlerDisabled) { | ||
props.handleClose(); | ||
} | ||
}, | ||
[props] | ||
); | ||
|
||
React.useEffect(() => { | ||
document.addEventListener('keydown', escFunction, false); | ||
|
||
return () => { | ||
document.removeEventListener('keydown', escFunction, false); | ||
}; | ||
}, [escFunction]); | ||
|
||
function getBody() { | ||
return ( | ||
<> | ||
<S.Container noHeader={!props.header} width={props.width}> | ||
<CloseHandler | ||
active={props.open && !props.closeHandlerDisabled} | ||
disabled={!props.open || props.closeHandlerDisabled} | ||
callback={() => (props.handleClose ? props.handleClose() : {})} | ||
> | ||
{props.header && ( | ||
<S.Header> | ||
<S.LT> | ||
<S.Title>{props.header}</S.Title> | ||
</S.LT> | ||
{props.handleClose && ( | ||
<S.Close> | ||
<IconButton | ||
type={'primary'} | ||
warning | ||
src={ASSETS.close} | ||
handlePress={() => props.handleClose()} | ||
active={false} | ||
dimensions={{ | ||
wrapper: 35, | ||
icon: 20, | ||
}} | ||
tooltip={language.close} | ||
useBottomToolTip | ||
/> | ||
</S.Close> | ||
)} | ||
</S.Header> | ||
)} | ||
<S.Body className={'scroll-wrapper'}>{props.children}</S.Body> | ||
</CloseHandler> | ||
</S.Container> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<Portal node={DOM.overlay}> | ||
<S.Wrapper noHeader={!props.header} top={window ? (window as any).pageYOffset : 0}> | ||
{getBody()} | ||
</S.Wrapper> | ||
</Portal> | ||
); | ||
} | ||
|
||
let panelOpenCounter = 0; | ||
|
||
const showDocumentBody = () => { | ||
panelOpenCounter -= 1; | ||
if (panelOpenCounter === 0) { | ||
document.body.style.overflow = 'auto'; | ||
} | ||
}; | ||
|
||
const hideDocumentBody = () => { | ||
panelOpenCounter += 1; | ||
document.body.style.overflow = 'hidden'; | ||
}; |
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 as Panel } from './Panel'; |
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,78 @@ | ||
import styled from 'styled-components'; | ||
|
||
import { fadeIn1, open, openRight } from 'helpers/animations'; | ||
import { STYLING } from 'helpers/config'; | ||
|
||
export const Wrapper = styled.div<{ top: number; noHeader: boolean }>` | ||
min-height: 100vh; | ||
height: 100%; | ||
width: 100%; | ||
position: fixed; | ||
z-index: 15; | ||
top: 0; | ||
left: 0; | ||
background: ${(props) => props.theme.colors.overlay.primary}; | ||
backdrop-filter: blur(2.5px); | ||
animation: ${open} ${fadeIn1}; | ||
`; | ||
|
||
export const Container = styled.div<{ | ||
noHeader: boolean; | ||
width?: number; | ||
}>` | ||
height: calc(100dvh - 20px); | ||
min-width: ${(props) => (props.width ? `${props.width.toString()}px` : '425px')}; | ||
width: fit-content; | ||
max-width: calc(100vw - 30px); | ||
position: fixed; | ||
overflow: hidden; | ||
top: 10px; | ||
right: 10px; | ||
transition: width 50ms ease-out; | ||
animation: ${openRight} 200ms; | ||
background: ${(props) => props.theme.colors.container.primary.background}; | ||
border: 1px solid ${(props) => props.theme.colors.border.alt4}; | ||
border-radius: ${STYLING.dimensions.radius.primary}; | ||
@media (max-width: ${STYLING.cutoffs.secondary}) { | ||
min-width: 82.5vw; | ||
} | ||
`; | ||
|
||
export const Header = styled.div` | ||
height: 65px; | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 0 20px; | ||
`; | ||
|
||
export const LT = styled.div` | ||
max-width: 75%; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
export const Title = styled.p` | ||
color: ${(props) => props.theme.colors.font.primary}; | ||
font-size: ${(props) => props.theme.typography.size.lg}; | ||
font-weight: ${(props) => props.theme.typography.weight.bold}; | ||
line-height: calc(${(props) => props.theme.typography.size.lg} + 5px); | ||
font-family: ${(props) => props.theme.typography.family.alt1}; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
margin: 2.5px 0 0 0; | ||
`; | ||
|
||
export const Close = styled.div` | ||
padding: 2.5px 0 0 0; | ||
`; | ||
|
||
export const Body = styled.div` | ||
height: calc(100% - 65px); | ||
width: 100%; | ||
overflow-y: auto; | ||
scrollbar-color: transparent transparent; | ||
position: relative; | ||
`; |
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,10 @@ | ||
import React from 'react'; | ||
|
||
export interface IProps { | ||
header: string | null | undefined; | ||
handleClose: () => void | null; | ||
children: React.ReactNode; | ||
open: boolean; | ||
width?: number; | ||
closeHandlerDisabled?: boolean; | ||
} |
Oops, something went wrong.