-
Notifications
You must be signed in to change notification settings - Fork 9
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 #214 from acl-services/UX-565-migrate-takeover
UX-565 Takeover component migration
- Loading branch information
Showing
27 changed files
with
684 additions
and
45 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { default as useEscapeKey } from "./useEscapeKey"; | ||
export { default as useOffsetScroll } from "./useOffsetScroll"; | ||
export { default as useFooterOffset } from "./useFooterOffset"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
|
||
!readme.md | ||
!lib/** |
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,34 @@ | ||
# Takeover | ||
|
||
Takeover component can toggle a full-screen view to help the user focus on complex UI tasks. | ||
More information at the design system site: https://design.wegalvanize.com/p/components/takeover | ||
|
||
## Components | ||
|
||
You can use any of the following components to compose the Takeover: | ||
|
||
```jsx | ||
<Takeover.Header /> | ||
<Takeover.Content /> | ||
<Takeover.FocusTrap /> | ||
``` | ||
|
||
## Basic example | ||
|
||
```jsx | ||
<Takeover isOpen={isOpen} onClose={toggle}> | ||
<Takeover.Header> | ||
<Heading level={2}>Header</Heading> | ||
</Takeover.Header> | ||
<Takeover.Content>My content</Takeover.Content> | ||
</Takeover> | ||
``` | ||
|
||
## Props | ||
|
||
- `children` (required) | ||
- `isOpen` (required) | ||
- `onClose` | ||
- `onAfterOpen` | ||
- `onAfterClose` | ||
- `isInline` |
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,31 @@ | ||
{ | ||
"name": "@paprika/takeover", | ||
"version": "0.1.0", | ||
"description": "Takeover component", | ||
"author": "@paprika", | ||
"main": "lib/index.js", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/acl-services/paprika/tree/master/packages/Takeover" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime-corejs2": "^7.3.1", | ||
"@paprika/button": "^0.2.2", | ||
"@paprika/heading": "^0.2.2", | ||
"@paprika/helpers": "^0.2.3", | ||
"@paprika/stylers": "^0.2.2", | ||
"@paprika/tokens": "^0.1.4", | ||
"focus-trap-react": "^6.0.0", | ||
"prop-types": "^15.7.2", | ||
"react-transition-group": "^4.3.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.4", | ||
"react-dom": "^16.8.4", | ||
"styled-components": "^4.2.0" | ||
} | ||
} |
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,106 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Transition } from "react-transition-group"; | ||
import FocusTrapLibrary from "focus-trap-react"; | ||
import LockBodyScroll from "@paprika/helpers/lib/components/LockBodyScroll"; | ||
import Portal from "@paprika/helpers/lib/components/Portal"; | ||
import extractChildren from "@paprika/helpers/lib/extractChildren"; | ||
import * as styled from "./Takeover.styles"; | ||
import { animationDuration } from "./helpers/tokens"; | ||
|
||
const propTypes = { | ||
/** The content for the Takeover. */ | ||
children: PropTypes.node.isRequired, | ||
|
||
/** Control the visibility of the takeover */ | ||
isOpen: PropTypes.bool.isRequired, | ||
|
||
/** Callback triggered when the takeover needs to be close */ | ||
onClose: PropTypes.func, | ||
|
||
/** Callback once the takeover has been opened event */ | ||
onAfterOpen: PropTypes.func, | ||
|
||
/** Callback once the takeover has been closed event */ | ||
onAfterClose: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
onAfterClose: () => {}, | ||
onClose: () => {}, | ||
onAfterOpen: () => {}, | ||
}; | ||
|
||
const Takeover = props => { | ||
const { isOpen, onClose, onAfterClose, onAfterOpen, ...moreProps } = props; | ||
|
||
function handleTransitionEnter(node) { | ||
// https://github.com/reactjs/react-transition-group/blob/6dbadb594c7c2a2f15bc47afc6b4374cfd73c7c0/src/CSSTransition.js#L44 | ||
// eslint-disable-next-line no-unused-expressions | ||
node.scrollTop; | ||
} | ||
|
||
const { | ||
"Takeover.FocusTrap": focusTrapExtracted, | ||
"Takeover.Header": headerExtracted, | ||
"Takeover.Content": contentExtracted, | ||
children, | ||
} = extractChildren(moreProps.children, ["Takeover.FocusTrap", "Takeover.Header", "Takeover.Content"]); | ||
|
||
const extendedFocusTrapOptions = focusTrapExtracted ? focusTrapExtracted.props : {}; | ||
|
||
const focusTrapOptions = { | ||
fallbackFocus: () => document.createElement("div"), | ||
...extendedFocusTrapOptions, | ||
}; | ||
|
||
function handleEscKey(event) { | ||
if (event.key === "Escape") { | ||
event.stopPropagation(); | ||
|
||
onClose(); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{isOpen && <LockBodyScroll />} | ||
<Portal> | ||
<Transition | ||
mountOnEnter | ||
unmountOnExit | ||
in={isOpen} | ||
timeout={animationDuration} | ||
onEnter={handleTransitionEnter} | ||
onEntered={onAfterOpen} | ||
onExited={onAfterClose} | ||
> | ||
{state => ( | ||
<FocusTrapLibrary focusTrapOptions={focusTrapOptions}> | ||
<styled.Wrapper | ||
state={state} | ||
role="dialog" | ||
tabIndex="-1" | ||
onKeyDown={handleEscKey} | ||
data-pka-anchor="takeover" | ||
> | ||
{headerExtracted && <styled.Header {...headerExtracted.props} onClose={onClose} />} | ||
{contentExtracted && ( | ||
<styled.ContentWrapper role="region" tabIndex="0"> | ||
{contentExtracted} | ||
</styled.ContentWrapper> | ||
)} | ||
{children} | ||
</styled.Wrapper> | ||
</FocusTrapLibrary> | ||
)} | ||
</Transition> | ||
</Portal> | ||
</> | ||
); | ||
}; | ||
|
||
Takeover.propTypes = propTypes; | ||
Takeover.defaultProps = defaultProps; | ||
|
||
export default Takeover; |
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,41 @@ | ||
import styled, { css } from "styled-components"; | ||
import tokens from "@paprika/tokens"; | ||
import { animationDuration } from "./helpers/tokens"; | ||
import OriginalHeader from "./components/Header"; | ||
|
||
const openedCss = css` | ||
opacity: 1; | ||
`; | ||
|
||
const closedCss = css` | ||
opacity: 0; | ||
`; | ||
|
||
const states = { | ||
entering: openedCss, | ||
entered: openedCss, | ||
exiting: closedCss, | ||
exited: closedCss, | ||
}; | ||
|
||
export const Wrapper = styled.div` | ||
background-color: ${tokens.backgroundColor.level0}; | ||
bottom: 0; | ||
display: flex; | ||
flex-direction: column; | ||
left: 0; | ||
position: fixed; | ||
right: 0; | ||
top: 0; | ||
transition: all ${animationDuration}ms ease; | ||
${({ state }) => states[state]}; | ||
`; | ||
|
||
export const Header = styled(OriginalHeader)` | ||
flex: none; | ||
`; | ||
|
||
export const ContentWrapper = styled.div` | ||
flex-grow: 1; | ||
overflow-y: auto; | ||
`; |
Oops, something went wrong.