From 4181a040b5d5ca2335556948585278133ec63bd1 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 7 Nov 2018 20:53:25 -0800 Subject: feat: refactor out overlay component and use it to implement click-outside --- packages/instant/src/components/ui/dropdown.tsx | 98 ++++++++++++---------- packages/instant/src/components/ui/overlay.tsx | 28 +++---- .../src/components/zero_ex_instant_overlay.tsx | 21 ++++- packages/instant/src/style/theme.ts | 1 + packages/instant/src/style/z_index.ts | 9 +- 5 files changed, 89 insertions(+), 68 deletions(-) diff --git a/packages/instant/src/components/ui/dropdown.tsx b/packages/instant/src/components/ui/dropdown.tsx index 2bc552ab4..c69e89c0e 100644 --- a/packages/instant/src/components/ui/dropdown.tsx +++ b/packages/instant/src/components/ui/dropdown.tsx @@ -1,12 +1,13 @@ import * as _ from 'lodash'; import * as React from 'react'; -import { ColorOption } from '../../style/theme'; +import { ColorOption, completelyTransparent } from '../../style/theme'; import { zIndex } from '../../style/z_index'; import { Container } from './container'; import { Flex } from './flex'; import { Icon } from './icon'; +import { Overlay } from './overlay'; import { Text } from './text'; export interface DropdownItemConfig { @@ -27,12 +28,12 @@ export interface DropdownState { export class Dropdown extends React.Component { public static defaultProps = { items: [ - { - text: 'Item 1', - }, - { - text: 'Item 2', - }, + // { + // text: 'Item 1', + // }, + // { + // text: 'Item 2', + // }, ], }; public state: DropdownState = { @@ -44,48 +45,57 @@ export class Dropdown extends React.Component { const hasItems = !_.isEmpty(items); const borderRadius = isOpen ? '4px 4px 0px 0px' : '4px'; return ( - - - - - {value} - - - - {label} - - {hasItems && ( - - - - )} - - - + {isOpen && ( - + )} + + - {_.map(items, (item, index) => ( - - ))} + + + {value} + + + + {label} + + {hasItems && ( + + + + )} + + - )} - + {isOpen && ( + + {_.map(items, (item, index) => ( + + ))} + + )} + + ); } private readonly _handleDropdownClick = (): void => { diff --git a/packages/instant/src/components/ui/overlay.tsx b/packages/instant/src/components/ui/overlay.tsx index f1706c874..64090a6b3 100644 --- a/packages/instant/src/components/ui/overlay.tsx +++ b/packages/instant/src/components/ui/overlay.tsx @@ -1,38 +1,30 @@ import * as _ from 'lodash'; import * as React from 'react'; -import { ColorOption, overlayBlack, styled } from '../../style/theme'; - -import { Container } from './container'; -import { Flex } from './flex'; -import { Icon } from './icon'; +import { overlayBlack, styled } from '../../style/theme'; +import { zIndex } from '../../style/z_index'; export interface OverlayProps { - className?: string; - onClose?: () => void; zIndex?: number; + backgroundColor?: string; } -const PlainOverlay: React.StatelessComponent = ({ children, className, onClose }) => ( - - - - -
{children}
-
-); -export const Overlay = styled(PlainOverlay)` +export const Overlay = + styled.div < + OverlayProps > + ` position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: ${props => props.zIndex} - background-color: ${overlayBlack}; + background-color: ${props => props.backgroundColor}; `; Overlay.defaultProps = { - zIndex: 100, + zIndex: zIndex.overlayDefault, + backgroundColor: overlayBlack, }; Overlay.displayName = 'Overlay'; diff --git a/packages/instant/src/components/zero_ex_instant_overlay.tsx b/packages/instant/src/components/zero_ex_instant_overlay.tsx index 3461600e1..d2b41d27f 100644 --- a/packages/instant/src/components/zero_ex_instant_overlay.tsx +++ b/packages/instant/src/components/zero_ex_instant_overlay.tsx @@ -1,5 +1,10 @@ import * as React from 'react'; +import { ColorOption, overlayBlack, styled } from '../style/theme'; + +import { Container } from './ui/container'; +import { Flex } from './ui/flex'; +import { Icon } from './ui/icon'; import { Overlay } from './ui/overlay'; import { ZeroExInstantContainer } from './zero_ex_instant_container'; import { ZeroExInstantProvider, ZeroExInstantProviderProps } from './zero_ex_instant_provider'; @@ -13,8 +18,20 @@ export const ZeroExInstantOverlay: React.StatelessComponent - - + + + + + + + ); diff --git a/packages/instant/src/style/theme.ts b/packages/instant/src/style/theme.ts index d10c9b72c..7917164a1 100644 --- a/packages/instant/src/style/theme.ts +++ b/packages/instant/src/style/theme.ts @@ -32,5 +32,6 @@ export const theme: Theme = { export const transparentWhite = 'rgba(255,255,255,0.3)'; export const overlayBlack = 'rgba(0, 0, 0, 0.6)'; +export const completelyTransparent = 'rga(0, 0, 0, 0)'; export { styled, css, keyframes, withTheme, ThemeProvider }; diff --git a/packages/instant/src/style/z_index.ts b/packages/instant/src/style/z_index.ts index 95e6cd912..0eedcaf29 100644 --- a/packages/instant/src/style/z_index.ts +++ b/packages/instant/src/style/z_index.ts @@ -1,6 +1,7 @@ export const zIndex = { - errorPopup: 1, - mainContainer: 2, - dropdownItems: 3, - panel: 4, + errorPopup: 10, + mainContainer: 20, + dropdownItems: 30, + panel: 40, + overlayDefault: 100, }; -- cgit v1.2.3