From 6b29736975037b10593309362b36373f1786ccba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 30 Jan 2018 17:52:34 +0100 Subject: [PATCH] Clean custom scrollbar --- package.json | 2 + src/components/SelectAccount/index.js | 16 +-- src/components/SideBar/index.js | 3 +- src/components/Wrapper.js | 3 +- src/components/base/GrowScroll/index.js | 91 ++++++++++++++ src/components/base/GrowScroll/stories.js | 13 ++ src/components/base/Modal/index.js | 1 + src/components/base/Select/index.js | 143 ++++++++++++++-------- src/styles/global.js | 23 ++-- yarn.lock | 18 ++- 10 files changed, 243 insertions(+), 70 deletions(-) create mode 100644 src/components/base/GrowScroll/index.js create mode 100644 src/components/base/GrowScroll/stories.js diff --git a/package.json b/package.json index aae04fb4..ff1b4d03 100644 --- a/package.json +++ b/package.json @@ -75,10 +75,12 @@ "react-router": "^4.2.0", "react-router-dom": "^4.2.2", "react-router-redux": "5.0.0-alpha.9", + "react-smooth-scrollbar": "^8.0.6", "redux": "^3.7.2", "redux-actions": "^2.2.1", "redux-thunk": "^2.2.0", "shortid": "^2.2.8", + "smooth-scrollbar": "^8.2.5", "source-map-support": "^0.5.3", "styled-components": "^3.1.4", "styled-system": "^1.1.1" diff --git a/src/components/SelectAccount/index.js b/src/components/SelectAccount/index.js index 67185905..f0032c7d 100644 --- a/src/components/SelectAccount/index.js +++ b/src/components/SelectAccount/index.js @@ -21,13 +21,6 @@ const mapStateToProps: MapStateToProps<*, *, *> = state => ({ accounts: Object.entries(getAccounts(state)).map(([, account]: [string, any]) => account), }) -type Props = { - accounts: Array, - onChange?: () => Account | void, - value?: Account | null, - t: T, -} - const renderItem = item => ( @@ -43,7 +36,14 @@ const renderItem = item => ( ) -export const SelectAccount = ({ accounts, value, onChange, t }: Props) => ( +type Props = { + accounts: Array, + onChange?: () => Account | void, + value?: Account | null, + t: T, +} + +export const SelectAccount = ({ accounts, onChange, value, t }: Props) => ( - - - - - ) : ( - - - {selectedItem && renderSelected ? ( - renderSelected(selectedItem) - ) : ( - {placeholder} - )} + }) => { + if (!isOpen) { + this._scrollToSelectedItem = true + } + + return ( + (this._useKeyboard = true)} + onKeyUp={() => (this._useKeyboard = false)} + > + {searchable ? ( + + + + + - - - )} - {isOpen && - (searchable ? ( - this.renderItems(items, selectedItem, downshiftProps)} - /> ) : ( - this.renderItems(items, selectedItem, downshiftProps) - ))} - - )} + + + {selectedItem && renderSelected ? ( + renderSelected(selectedItem) + ) : ( + {placeholder} + )} + + + + )} + {isOpen && + (searchable ? ( + this.renderItems(items, selectedItem, downshiftProps)} + /> + ) : ( + this.renderItems(items, selectedItem, downshiftProps) + ))} + + ) + }} /> ) } diff --git a/src/styles/global.js b/src/styles/global.js index 2442895c..929a570b 100644 --- a/src/styles/global.js +++ b/src/styles/global.js @@ -45,17 +45,22 @@ injectGlobal` font-style: italic; } - ::-webkit-scrollbar { - background-color: rgba(0, 0, 0, 0); - width: 6px; + .scrollbar-thumb-y { + width: 5px !important; } - ::-webkit-scrollbar:hover { - background-color: rgba(0, 0, 0, 0.09); + .scrollbar-thumb-x { + height: 5px !important; } - ::-webkit-scrollbar-thumb:vertical { - background: rgba(0, 0, 0, 0.5); + .scrollbar-track { + background: transparent !important; + transition: opacity 0.2s ease-in-out !important; } - ::-webkit-scrollbar-thumb:vertical:active { - background: rgba(0, 0, 0, 0.61); + .scrollbar-track-y { + right: 2px !important; + width: 5px !important; + } + .scrollbar-track-x { + bottom: 2px !important; + height: 5px !important; } ` diff --git a/yarn.lock b/yarn.lock index acbd9d29..8bdda5fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2606,7 +2606,7 @@ core-js@^1.0.0: version "1.2.7" resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" -core-js@^2.4.0, core-js@^2.4.1, core-js@^2.5.0, core-js@^2.5.3: +core-js@^2.4.0, core-js@^2.4.1, core-js@^2.5.0, core-js@^2.5.1, core-js@^2.5.3: version "2.5.3" resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.3.tgz#8acc38345824f16d8365b7c9b4259168e8ed603e" @@ -7443,6 +7443,10 @@ react-router@^4.2.0: prop-types "^15.5.4" warning "^3.0.0" +react-smooth-scrollbar@^8.0.6: + version "8.0.6" + resolved "https://registry.yarnpkg.com/react-smooth-scrollbar/-/react-smooth-scrollbar-8.0.6.tgz#179072e6a547b3af589ea303c50fd86366275edc" + react-split-pane@^0.1.74: version "0.1.74" resolved "https://registry.yarnpkg.com/react-split-pane/-/react-split-pane-0.1.74.tgz#cf79fc98b51ab0763fdc778749b810a102b036ca" @@ -8184,6 +8188,14 @@ slice-ansi@1.0.0: dependencies: readable-stream "~1.0.31" +smooth-scrollbar@^8.2.5: + version "8.2.5" + resolved "https://registry.yarnpkg.com/smooth-scrollbar/-/smooth-scrollbar-8.2.5.tgz#676a2595b1aad97fe0835d2425e403b0d9c70eb3" + dependencies: + core-js "^2.5.1" + lodash-es "^4.17.4" + tslib "^1.7.1" + snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" @@ -8826,6 +8838,10 @@ truncate-utf8-bytes@^1.0.0: dependencies: utf8-byte-length "^1.0.1" +tslib@^1.7.1: + version "1.9.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" + tty-browserify@0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"