diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-20 00:44:47 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-20 00:44:47 +0800 |
commit | 100f446031e84c367f1d0852ef60fd04d4544b9f (patch) | |
tree | e0e2c6c896a7f0b4e738727f6baa8a30e5234695 /packages/website/ts/pages/documentation/developers_page.tsx | |
parent | 48f1e6057c878a948d21ed7d2214c7792c648f75 (diff) | |
parent | eb3a4d2fabcab3c2423d5827aba2fcaffc348320 (diff) | |
download | dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.tar dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.tar.gz dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.tar.bz2 dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.tar.lz dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.tar.xz dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.tar.zst dexon-sol-tools-100f446031e84c367f1d0852ef60fd04d4544b9f.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/instant/beta-render-et-al
Diffstat (limited to 'packages/website/ts/pages/documentation/developers_page.tsx')
-rw-r--r-- | packages/website/ts/pages/documentation/developers_page.tsx | 164 |
1 files changed, 91 insertions, 73 deletions
diff --git a/packages/website/ts/pages/documentation/developers_page.tsx b/packages/website/ts/pages/documentation/developers_page.tsx index 934a4cc36..30b79552f 100644 --- a/packages/website/ts/pages/documentation/developers_page.tsx +++ b/packages/website/ts/pages/documentation/developers_page.tsx @@ -1,4 +1,4 @@ -import { colors, constants as sharedConstants } from '@0x/react-shared'; +import { colors, constants as sharedConstants, utils as sharedUtils } from '@0x/react-shared'; import * as _ from 'lodash'; import * as React from 'react'; import DocumentTitle = require('react-document-title'); @@ -6,13 +6,33 @@ import { DocsLogo } from 'ts/components/documentation/docs_logo'; import { DocsTopBar } from 'ts/components/documentation/docs_top_bar'; import { Container } from 'ts/components/ui/container'; import { Dispatcher } from 'ts/redux/dispatcher'; -import { ScreenWidths } from 'ts/types'; +import { styled } from 'ts/style/theme'; +import { BrowserType, OperatingSystemType, ScreenWidths } from 'ts/types'; import { Translate } from 'ts/utils/translate'; import { utils } from 'ts/utils/utils'; const THROTTLE_TIMEOUT = 100; const TOP_BAR_HEIGHT = 80; -const SCROLLER_WIDTH = 4; +const browserType = utils.getBrowserType(); +let SCROLLBAR_WIDTH; +switch (browserType) { + case BrowserType.Firefox: + // HACK: Firefox doesn't allow styling of their scrollbar's. + // Source: https://stackoverflow.com/questions/6165472/custom-css-scrollbar-for-firefox + const os = utils.getOperatingSystem(); + SCROLLBAR_WIDTH = os === OperatingSystemType.Windows ? 17 : 15; + break; + + case BrowserType.Edge: + // Edge's scrollbar is placed outside of the div content and doesn't + // need to be accounted for + SCROLLBAR_WIDTH = 0; + break; + + default: + SCROLLBAR_WIDTH = 4; +} +const SIDEBAR_PADDING = 22; export interface DevelopersPageProps { location: Location; @@ -24,11 +44,71 @@ export interface DevelopersPageProps { } export interface DevelopersPageState { - isHoveringSidebar: boolean; - isHoveringMainContent: boolean; isSidebarScrolling: boolean; } +const isUserOnMobile = sharedUtils.isUserOnMobile(); + +const scrollableContainerStyles = ` + position: absolute; + top: ${TOP_BAR_HEIGHT}px; + left: 0px; + bottom: 0px; + right: 0px; + overflow-x: hidden; + overflow-y: scroll; + -webkit-overflow-scrolling: touch; + /* Required for hide/show onHover of scrollbar on Microsoft Edge */ + -ms-overflow-style: -ms-autohiding-scrollbar; +`; + +interface SidebarContainerProps { + className?: string; +} + +const SidebarContainer = + styled.div < + SidebarContainerProps > + ` + ${scrollableContainerStyles} + padding-top: 27px; + padding-bottom: 100px; + padding-left: ${SIDEBAR_PADDING}px; + padding-right: ${SIDEBAR_PADDING}px; + overflow: hidden; + &:hover { + overflow: auto; + padding-right: ${SIDEBAR_PADDING - SCROLLBAR_WIDTH}px; + } +`; + +interface MainContentContainerProps { + className?: string; +} + +const MainContentContainer = + styled.div < + MainContentContainerProps > + ` + ${scrollableContainerStyles} + padding-top: 0px; + padding-left: 50px; + padding-right: 50px; + overflow: ${isUserOnMobile ? 'auto' : 'hidden'}; + &:hover { + padding-right: ${50 - SCROLLBAR_WIDTH}px; + overflow: auto; + } + @media (max-width: 40em) { + padding-left: 20px; + padding-right: 20px; + &:hover { + padding-right: ${20 - SCROLLBAR_WIDTH}px; + overflow: auto; + } + } +`; + export class DevelopersPage extends React.Component<DevelopersPageProps, DevelopersPageState> { private readonly _throttledScreenWidthUpdate: () => void; private readonly _throttledSidebarScrolling: () => void; @@ -38,8 +118,6 @@ export class DevelopersPage extends React.Component<DevelopersPageProps, Develop this._throttledScreenWidthUpdate = _.throttle(this._updateScreenWidth.bind(this), THROTTLE_TIMEOUT); this._throttledSidebarScrolling = _.throttle(this._onSidebarScroll.bind(this), THROTTLE_TIMEOUT); this.state = { - isHoveringSidebar: false, - isHoveringMainContent: false, isSidebarScrolling: false, }; } @@ -57,20 +135,8 @@ export class DevelopersPage extends React.Component<DevelopersPageProps, Develop window.clearInterval(this._sidebarScrollClearingInterval); } public render(): React.ReactNode { - const scrollableContainerStyles: React.CSSProperties = { - position: 'absolute', - top: 80, - left: 0, - bottom: 0, - right: 0, - overflowX: 'hidden', - overflowY: 'scroll', - minHeight: `calc(100vh - ${TOP_BAR_HEIGHT}px)`, - WebkitOverflowScrolling: 'touch', - }; const isSmallScreen = this.props.screenWidth === ScreenWidths.Sm; const mainContentPadding = isSmallScreen ? 20 : 50; - const sidebarPadding = 22; return ( <Container className="flex items-center overflow-hidden" @@ -79,7 +145,7 @@ export class DevelopersPage extends React.Component<DevelopersPageProps, Develop colors.white } 50%, ${colors.white} 100%)`} > - <DocumentTitle title="0x Docs DevelopersPage" /> + <DocumentTitle title="0x Docs" /> <Container className="flex mx-auto" height="100vh"> <Container className="sm-hide xs-hide relative" @@ -96,28 +162,9 @@ export class DevelopersPage extends React.Component<DevelopersPageProps, Develop <DocsLogo height={36} /> </Container> </Container> - <div - style={{ - ...scrollableContainerStyles, - paddingTop: 27, - overflow: this.state.isHoveringSidebar ? 'auto' : 'hidden', - }} - onMouseEnter={this._onSidebarHover.bind(this, true)} - onMouseLeave={this._onSidebarHover.bind(this, false)} - onWheel={this._throttledSidebarScrolling} - > - <div - style={{ - paddingBottom: 100, - paddingLeft: sidebarPadding, - paddingRight: this.state.isHoveringSidebar - ? sidebarPadding - SCROLLER_WIDTH - : sidebarPadding, - }} - > - {this.props.screenWidth !== ScreenWidths.Sm && this.props.sidebar} - </div> - </div> + <SidebarContainer onWheel={this._throttledSidebarScrolling}> + {this.props.screenWidth !== ScreenWidths.Sm && this.props.sidebar} + </SidebarContainer> </Container> <Container className="relative" @@ -133,43 +180,14 @@ export class DevelopersPage extends React.Component<DevelopersPageProps, Develop sidebar={this.props.sidebar} /> </Container> - <div - id={sharedConstants.SCROLL_CONTAINER_ID} - className="absolute" - style={{ - ...scrollableContainerStyles, - paddingTop: 0, - paddingLeft: mainContentPadding, - paddingRight: this.state.isHoveringMainContent - ? mainContentPadding - SCROLLER_WIDTH - : mainContentPadding, - overflow: this.state.isHoveringMainContent ? 'auto' : 'hidden', - }} - onMouseEnter={this._onMainContentHover.bind(this, true)} - onMouseOver={this._onMainContentHover.bind(this, true)} - onMouseLeave={this._onMainContentHover.bind(this, false)} - > + <MainContentContainer id={sharedConstants.SCROLL_CONTAINER_ID}> {this.props.mainContent} - </div> + </MainContentContainer> </Container> </Container> </Container> ); } - private _onSidebarHover(isHovering: boolean, _event: React.FormEvent<HTMLInputElement>): void { - if (isHovering !== this.state.isHoveringSidebar) { - this.setState({ - isHoveringSidebar: isHovering, - }); - } - } - private _onMainContentHover(isHovering: boolean, _event: React.FormEvent<HTMLInputElement>): void { - if (isHovering !== this.state.isHoveringMainContent) { - this.setState({ - isHoveringMainContent: isHovering, - }); - } - } private _onSidebarScroll(_event: React.FormEvent<HTMLInputElement>): void { this.setState({ isSidebarScrolling: true, |