From d0a3779091661cfa099ec84f12e5d944287d1e3f Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 14 Jun 2018 18:19:07 -0700 Subject: Add Pointer component --- .../components/onboarding/onboarding_tooltip.tsx | 35 ++++++----- packages/website/ts/components/ui/pointer.tsx | 68 ++++++++++++++++++++++ 2 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 packages/website/ts/components/ui/pointer.tsx diff --git a/packages/website/ts/components/onboarding/onboarding_tooltip.tsx b/packages/website/ts/components/onboarding/onboarding_tooltip.tsx index 155c70c5f..9e0744dcb 100644 --- a/packages/website/ts/components/onboarding/onboarding_tooltip.tsx +++ b/packages/website/ts/components/onboarding/onboarding_tooltip.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { Container } from 'ts/components/ui/container'; import { Island } from 'ts/components/ui/island'; +import { Pointer } from 'ts/components/ui/pointer'; export type ContinueButtonDisplay = 'enabled' | 'disabled'; @@ -34,22 +35,24 @@ export const ContinueButton: React.StatelessComponent = (pr }; export const OnboardingTooltip: React.StatelessComponent = (props: OnboardingTooltipProps) => ( - - -
- {props.title} - {props.content} - {props.continueButtonDisplay && ( - - Continue - - )} - {!props.hideBackButton && } - {!props.hideNextButton && } - -
-
-
+ + + +
+ {props.title} + {props.content} + {props.continueButtonDisplay && ( + + Continue + + )} + {!props.hideBackButton && } + {!props.hideNextButton && } + +
+
+
+
); OnboardingTooltip.displayName = 'OnboardingTooltip'; diff --git a/packages/website/ts/components/ui/pointer.tsx b/packages/website/ts/components/ui/pointer.tsx new file mode 100644 index 000000000..dcd1b8e54 --- /dev/null +++ b/packages/website/ts/components/ui/pointer.tsx @@ -0,0 +1,68 @@ +import { colors } from '@0xproject/react-shared'; +import { Island } from 'ts/components/ui/island'; +import * as React from 'react'; +import { styled } from 'ts/style/theme'; + +export type PointerDirection = 'top' | 'right' | 'bottom' | 'left'; + +export interface PointerProps { + className?: string; + color?: string; + size?: number; + direction: PointerDirection; +} + +const PlainPointer: React.StatelessComponent = props =>
; + +const positionToCss = (props: PointerProps) => { + const position = { + top: `bottom: 100%; left: 50%;`, + right: `left: 100%; top: 50%;`, + bottom: `top: 100%; left: 50%;`, + left: `right: 100%; top: 50%;`, + }[props.direction]; + + const borderColorSide = { + top: 'border-bottom-color', + right: 'border-left-color', + bottom: 'border-top-color', + left: 'border-right-color', + }[props.direction]; + const border = `${borderColorSide}: ${props.color};`; + const marginSide = { + top: 'margin-left', + right: 'margin-top', + bottom: 'margin-left', + left: 'margin-top', + }[props.direction]; + const margin = `${marginSide}: -${props.size}px`; + return { + position, + border, + margin, + }; +}; + +export const Pointer = styled(PlainPointer)` + position: relative; + &:after { + border: solid transparent; + content: " "; + height: 0; + width: 0; + position: absolute; + pointer-events: none; + border-color: rgba(136, 183, 213, 0); + border-width: ${props => `${props.size}px`}; + ${props => positionToCss(props).position} + ${props => positionToCss(props).border} + ${props => positionToCss(props).margin} + } +`; + +Pointer.defaultProps = { + color: colors.white, + size: 16, +}; + +Pointer.displayName = 'Pointer'; -- cgit