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
35f6039d
Commit
35f6039d
authored
Mar 21, 2019
by
Dominik Prokop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable sass theme change in Storybook
parent
56251ca5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
9 deletions
+29
-9
packages/grafana-ui/.storybook/config.ts
+14
-2
packages/grafana-ui/.storybook/webpack.config.js
+5
-5
packages/grafana-ui/src/utils/storybook/withTheme.tsx
+10
-2
No files found.
packages/grafana-ui/.storybook/config.ts
View file @
35f6039d
...
...
@@ -2,13 +2,25 @@ import { configure, addDecorator } from '@storybook/react';
import
{
withKnobs
}
from
'@storybook/addon-knobs'
;
import
{
withTheme
}
from
'../src/utils/storybook/withTheme'
;
import
'../../../public/sass/grafana.light.scss'
;
// @ts-ignore
import
lightTheme
from
'../../../public/sass/grafana.light.scss'
;
// @ts-ignore
import
darkTheme
from
'../../../public/sass/grafana.dark.scss'
;
const
handleThemeChange
=
(
theme
:
string
)
=>
{
if
(
theme
!==
'light'
)
{
lightTheme
.
unuse
();
darkTheme
.
use
();
}
else
{
darkTheme
.
unuse
();
lightTheme
.
use
();
}
};
// automatically import all files ending in *.stories.tsx
const
req
=
require
.
context
(
'../src/components'
,
true
,
/.story.tsx$/
);
addDecorator
(
withKnobs
);
addDecorator
(
withTheme
);
addDecorator
(
withTheme
(
handleThemeChange
)
);
function
loadStories
()
{
req
.
keys
().
forEach
(
req
);
...
...
packages/grafana-ui/.storybook/webpack.config.js
View file @
35f6039d
...
...
@@ -14,15 +14,15 @@ module.exports = (baseConfig, env, config) => {
test
:
/
\.
scss$/
,
use
:
[
{
loader
:
'style-loader'
,
loader
:
'style-loader
/useable
'
,
},
{
loader
:
'css-loader'
,
options
:
{
importLoaders
:
2
,
url
:
false
,
sourceMap
:
false
,
minimize
:
false
,
//
url: false,
//
sourceMap: false,
//
minimize: false,
},
},
{
...
...
@@ -35,7 +35,7 @@ module.exports = (baseConfig, env, config) => {
{
loader
:
'sass-loader'
,
options
:
{
sourceMap
:
false
sourceMap
:
false
,
},
},
],
...
...
packages/grafana-ui/src/utils/storybook/withTheme.tsx
View file @
35f6039d
...
...
@@ -5,7 +5,11 @@ import { select } from '@storybook/addon-knobs';
import
{
getTheme
}
from
'../../themes/index'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
const
ThemableStory
:
React
.
FunctionComponent
<
{}
>
=
({
children
})
=>
{
type
SassThemeChangeHandler
=
(
theme
:
GrafanaThemeType
)
=>
void
;
const
ThemableStory
:
React
.
FunctionComponent
<
{
handleSassThemeChange
:
SassThemeChangeHandler
}
>
=
({
children
,
handleSassThemeChange
,
})
=>
{
const
themeKnob
=
select
(
'Theme'
,
{
...
...
@@ -15,6 +19,8 @@ const ThemableStory: React.FunctionComponent<{}> = ({ children }) => {
GrafanaThemeType
.
Dark
);
handleSassThemeChange
(
themeKnob
);
return
<
ThemeContext
.
Provider
value=
{
getTheme
(
themeKnob
)
}
>
{
children
}
</
ThemeContext
.
Provider
>;
};
...
...
@@ -33,4 +39,6 @@ export const renderComponentWithTheme = (component: React.ComponentType<any>, pr
);
};
export
const
withTheme
=
(
story
:
RenderFunction
)
=>
<
ThemableStory
>
{
story
()
}
</
ThemableStory
>;
export
const
withTheme
=
(
handleSassThemeChange
:
SassThemeChangeHandler
)
=>
(
story
:
RenderFunction
)
=>
(
<
ThemableStory
handleSassThemeChange=
{
handleSassThemeChange
}
>
{
story
()
}
</
ThemableStory
>
);
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