Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
8fca79e8
Unverified
Commit
8fca79e8
authored
Sep 06, 2018
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scrollbar refactor: replace HOC by component with children
parent
a186bc01
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
45 deletions
+33
-45
public/app/core/components/ScrollBar/GrafanaScrollbar.test.tsx
+4
-11
public/app/core/components/ScrollBar/GrafanaScrollbar.tsx
+25
-30
public/app/core/components/ScrollBar/__snapshots__/GrafanaScrollbar.test.tsx.snap
+4
-4
No files found.
public/app/core/components/ScrollBar/
withScrollB
ar.test.tsx
→
public/app/core/components/ScrollBar/
GrafanaScrollb
ar.test.tsx
View file @
8fca79e8
import
React
from
'react'
;
import
renderer
from
'react-test-renderer'
;
import
withScrollBar
from
'./withScrollB
ar'
;
import
GrafanaScrollbar
from
'./GrafanaScrollb
ar'
;
class
TestComponent
extends
React
.
Component
{
render
()
{
return
<
div
className=
"my-component"
/>;
}
}
describe
(
'withScrollBar'
,
()
=>
{
describe
(
'GrafanaScrollbar'
,
()
=>
{
it
(
'renders correctly'
,
()
=>
{
const
TestComponentWithScroll
=
withScrollBar
(
TestComponent
);
const
tree
=
renderer
.
create
(
<
TestComponentWithScroll
>
<
GrafanaScrollbar
>
<
p
>
Scrollable content
</
p
>
</
TestComponentWithScroll
>
</
GrafanaScrollbar
>
)
.
toJSON
();
expect
(
tree
).
toMatchSnapshot
();
...
...
public/app/core/components/ScrollBar/
withScrollB
ar.tsx
→
public/app/core/components/ScrollBar/
GrafanaScrollb
ar.tsx
View file @
8fca79e8
import
React
from
'react'
;
import
Scrollbars
from
'react-custom-scrollbars'
;
interface
With
ScrollBarProps
{
interface
Grafana
ScrollBarProps
{
customClassName
?:
string
;
autoHide
?:
boolean
;
autoHideTimeout
?:
number
;
...
...
@@ -9,7 +9,7 @@ interface WithScrollBarProps {
hideTracksWhenNotNeeded
?:
boolean
;
}
const
withScrollBarDefaultProps
:
Partial
<
With
ScrollBarProps
>
=
{
const
grafanaScrollBarDefaultProps
:
Partial
<
Grafana
ScrollBarProps
>
=
{
customClassName
:
'custom-scrollbars'
,
autoHide
:
true
,
autoHideTimeout
:
200
,
...
...
@@ -20,34 +20,29 @@ const withScrollBarDefaultProps: Partial<WithScrollBarProps> = {
/**
* Wraps component into <Scrollbars> component from `react-custom-scrollbars`
*/
export
default
function
withScrollBar
<
P
extends
object
>
(
WrappedComponent
:
React
.
ComponentType
<
P
>
)
{
return
class
extends
React
.
Component
<
P
&
WithScrollBarProps
>
{
static
defaultProps
=
withScrollBarDefaultProps
;
class
GrafanaScrollbar
extends
React
.
Component
<
GrafanaScrollBarProps
>
{
static
defaultProps
=
grafanaScrollBarDefaultProps
;
render
()
{
// Use type casting here in order to get rest of the props working. See more
// https://github.com/Microsoft/TypeScript/issues/14409
// https://github.com/Microsoft/TypeScript/pull/13288
const
{
autoHide
,
autoHideTimeout
,
autoHideDuration
,
hideTracksWhenNotNeeded
,
customClassName
,
...
props
}
=
this
.
props
as
WithScrollBarProps
;
const
scrollProps
=
{
autoHide
,
autoHideTimeout
,
autoHideDuration
,
hideTracksWhenNotNeeded
};
render
()
{
const
{
customClassName
,
children
,
...
scrollProps
}
=
this
.
props
;
return
(
<
Scrollbars
className=
{
customClassName
}
autoHeight=
{
true
}
autoHeightMin=
{
'100%'
}
autoHeightMax=
{
'100%'
}
renderTrackHorizontal=
{
props
=>
<
div
{
...
props
}
className=
"track-horizontal"
/>
}
renderTrackVertical=
{
props
=>
<
div
{
...
props
}
className=
"track-vertical"
/>
}
renderThumbHorizontal=
{
props
=>
<
div
{
...
props
}
className=
"thumb-horizontal"
/>
}
renderThumbVertical=
{
props
=>
<
div
{
...
props
}
className=
"thumb-vertical"
/>
}
renderView=
{
props
=>
<
div
{
...
props
}
className=
"view"
/>
}
{
...
scrollProps
}
>
<
WrappedComponent
{
...
props
}
/>
</
Scrollbars
>
);
}
};
return
(
<
Scrollbars
className=
{
customClassName
}
autoHeight=
{
true
}
autoHeightMin=
{
'100%'
}
autoHeightMax=
{
'100%'
}
renderTrackHorizontal=
{
props
=>
<
div
{
...
props
}
className=
"track-horizontal"
/>
}
renderTrackVertical=
{
props
=>
<
div
{
...
props
}
className=
"track-vertical"
/>
}
renderThumbHorizontal=
{
props
=>
<
div
{
...
props
}
className=
"thumb-horizontal"
/>
}
renderThumbVertical=
{
props
=>
<
div
{
...
props
}
className=
"thumb-vertical"
/>
}
renderView=
{
props
=>
<
div
{
...
props
}
className=
"view"
/>
}
{
...
scrollProps
}
>
{
children
}
</
Scrollbars
>
);
}
}
export
default
GrafanaScrollbar
;
public/app/core/components/ScrollBar/__snapshots__/
withScrollB
ar.test.tsx.snap
→
public/app/core/components/ScrollBar/__snapshots__/
GrafanaScrollb
ar.test.tsx.snap
View file @
8fca79e8
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`
withScrollB
ar renders correctly 1`] = `
exports[`
GrafanaScrollb
ar renders correctly 1`] = `
<div
className="custom-scrollbars"
style={
...
...
@@ -32,9 +32,9 @@ exports[`withScrollBar renders correctly 1`] = `
}
}
>
<
div
className="my-component"
/
>
<
p>
Scrollable content
</p
>
</div>
<div
className="track-horizontal"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment