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 ++++- 3 files changed, 83 insertions(+), 64 deletions(-) (limited to 'packages/instant/src/components') 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 - - + + + + + + + ); -- cgit