Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce DapperScrollbars #12961

Merged
merged 13 commits into from
Mar 28, 2019
Merged
25 changes: 25 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"react-resize-detector": "^2.3.0",
"react-router": "^3.0.2",
"react-router-redux": "^4.0.8",
"react-scrollbars-custom": "^4.0.0-alpha.8",
"react-tooltip": "^3.2.1",
"react-virtualized": "^9.18.5",
"redux": "^4.0.0",
Expand Down
41 changes: 16 additions & 25 deletions ui/src/clockface/components/dropdowns/Dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
line-height: 12px;
font-weight: 600;
color: fade-out($g20-white, 0.18);
white-space: nowrap;
position: relative;
text-align: left;

Expand All @@ -64,13 +63,21 @@
cursor: pointer;
}

.dropdown--action & {
padding-left: 11px;
}
}

.dropdown-item--children {
.dropdown-wrap & {
word-break: break-all;
white-space: pre-wrap;
}

.dropdown--action & {
padding-left: 11px;
.dropdown-truncate & {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}

Expand Down Expand Up @@ -150,8 +157,7 @@
$dividerA,
$dividerB,
$dividerText,
$scrollA,
$scrollB
$checkbox
) {
@include gradient-h($backgroundA, $backgroundB);

Expand All @@ -167,13 +173,7 @@
background-color: $dividerA;
}
.dropdown-item--checkbox:after {
background-color: $scrollA;
}
.fancy-scroll--thumb-h {
@include gradient-h($scrollA, $scrollB);
}
.fancy-scroll--thumb-v {
@include gradient-v($scrollA, $scrollB);
background-color: $checkbox;
}
}

Expand All @@ -186,8 +186,7 @@
$c-amethyst,
$c-ocean,
$c-potassium,
$c-neutrino,
$c-hydrogen
$c-neutrino
);
}

Expand All @@ -200,8 +199,7 @@
$c-sapphire,
$c-ocean,
$c-laser,
$c-neutrino,
$c-hydrogen
$c-neutrino
);
}

Expand All @@ -214,8 +212,7 @@
$c-ocean,
$c-viridian,
$c-krypton,
$c-neutrino,
$c-krypton
$c-neutrino
);
}

Expand All @@ -228,12 +225,6 @@
$g0-obsidian,
$g2-kevlar,
$g11-sidewalk,
$c-pool,
$c-comet
$c-pool
);
}

/* TODO: Make fancyscroll more customizable */
.dropdown--menu-container .fancy-scroll--track-h {
display: none;
}
109 changes: 72 additions & 37 deletions ui/src/clockface/components/dropdowns/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Libraries
import React, {Component, CSSProperties, MouseEvent} from 'react'
import React, {Component, MouseEvent} from 'react'
import classnames from 'classnames'

// Components
import {ClickOutside} from 'src/shared/components/ClickOutside'
import DropdownDivider from 'src/clockface/components/dropdowns/DropdownDivider'
import DropdownItem from 'src/clockface/components/dropdowns/DropdownItem'
import DropdownButton from 'src/clockface/components/dropdowns/DropdownButton'
import FancyScrollbar from 'src/shared/components/fancy_scrollbar/FancyScrollbar'
import DapperScrollbars from 'src/shared/components/dapperScrollbars/DapperScrollbars'
import WaitingText from 'src/shared/components/WaitingText'

// Types
Expand All @@ -26,41 +26,52 @@ export enum DropdownMode {
Radio = 'radio',
}

export interface Props {
interface ThumbColors {
start: string
stop: string
}

export interface PassedProps {
children: JSX.Element[]
onChange: (value: any) => void
selectedID?: string
buttonColor?: ComponentColor
buttonSize?: ComponentSize
menuColor?: DropdownMenuColors
status?: ComponentStatus
widthPixels?: number
menuWidthPixels?: number
menuHeader?: JSX.Element
icon?: IconFont
wrapText?: boolean
customClass?: string
testID?: string
buttonTestID?: string
}

export interface DefaultProps {
buttonColor?: ComponentColor
buttonSize?: ComponentSize
status?: ComponentStatus
maxMenuHeight?: number
menuColor?: DropdownMenuColors
mode?: DropdownMode
titleText?: string
menuHeader?: JSX.Element
testID: string
buttonTestID: string
wrapMenuText?: boolean
}

export type Props = PassedProps & DefaultProps

interface State {
expanded: boolean
}

@ErrorHandling
class Dropdown extends Component<Props, State> {
public static defaultProps: Partial<Props> = {
public static defaultProps: DefaultProps = {
buttonColor: ComponentColor.Default,
buttonSize: ComponentSize.Small,
status: ComponentStatus.Default,
wrapText: false,
maxMenuHeight: 250,
menuColor: DropdownMenuColors.Sapphire,
mode: DropdownMode.Radio,
titleText: '',
wrapMenuText: false,
}

public static Button = DropdownButton
Expand Down Expand Up @@ -103,16 +114,17 @@ class Dropdown extends Component<Props, State> {
buttonColor,
buttonSize,
status,
wrapText,
customClass,
mode,
wrapMenuText,
} = this.props

return classnames(
`dropdown dropdown-${buttonSize} dropdown-${buttonColor}`,
{
disabled: status === ComponentStatus.Disabled,
'dropdown-wrap': wrapText,
'dropdown-wrap': wrapMenuText,
'dropdown-truncate': !wrapMenuText,
[customClass]: customClass,
[`dropdown--${mode}`]: mode,
}
Expand Down Expand Up @@ -171,6 +183,8 @@ class Dropdown extends Component<Props, State> {
const {
selectedID,
maxMenuHeight,
widthPixels,
menuWidthPixels,
menuHeader,
menuColor,
children,
Expand All @@ -183,15 +197,32 @@ class Dropdown extends Component<Props, State> {
return null
}

let width = '100%'

if (widthPixels) {
width = `${widthPixels}px`
}

if (menuWidthPixels) {
width = `${menuWidthPixels}px`
}

const {start, stop} = this.thumbColorsFromTheme

return (
<div
className={`dropdown--menu-container dropdown--${menuColor}`}
style={this.menuStyle}
style={{width}}
>
<FancyScrollbar
<DapperScrollbars
style={{
maxWidth: '100%',
maxHeight: `${maxMenuHeight}px`,
}}
autoSize={true}
autoHide={false}
autoHeight={true}
maxHeight={maxMenuHeight}
thumbStartColor={start}
thumbStopColor={stop}
>
<div
className="dropdown--menu"
Expand Down Expand Up @@ -219,28 +250,32 @@ class Dropdown extends Component<Props, State> {
}
})}
</div>
</FancyScrollbar>
</DapperScrollbars>
</div>
)
}

private get menuStyle(): CSSProperties {
const {wrapText, widthPixels} = this.props

let containerWidth = '100%'

if (widthPixels) {
containerWidth = `${widthPixels}px`
}

if (wrapText && widthPixels) {
return {
width: containerWidth,
}
}

return {
minWidth: containerWidth,
private get thumbColorsFromTheme(): ThumbColors {
const {menuColor} = this.props

switch (menuColor) {
case DropdownMenuColors.Amethyst:
case DropdownMenuColors.Sapphire:
return {
start: '#BEF0FF',
stop: '#6BDFFF',
}
case DropdownMenuColors.Malachite:
return {
start: '#BEF0FF',
stop: '#A5F3B4',
}
default:
case DropdownMenuColors.Onyx:
return {
start: '#22ADF6',
stop: '#9394FF',
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions ui/src/clockface/components/overlays/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import OverlayContainer from 'src/clockface/components/overlays/OverlayContainer
import OverlayHeading from 'src/clockface/components/overlays/OverlayHeading'
import OverlayBody from 'src/clockface/components/overlays/OverlayBody'
import OverlayFooter from 'src/clockface/components/overlays/OverlayFooter'
import FancyScrollbar from 'src/shared/components/fancy_scrollbar/FancyScrollbar'
import DapperScrollbars from 'src/shared/components/dapperScrollbars/DapperScrollbars'

// Styles
import 'src/clockface/components/overlays/Overlay.scss'
Expand Down Expand Up @@ -59,15 +59,15 @@ class Overlay extends Component<Props, State> {

public render() {
return (
<FancyScrollbar
<DapperScrollbars
className={this.overlayClass}
thumbStartColor="#ffffff"
thumbStopColor="#C9D0FF"
autoHide={false}
>
{this.childContainer}
<div className="overlay--mask" />
</FancyScrollbar>
</DapperScrollbars>
)
}

Expand Down
Loading