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
390c80d7
Unverified
Commit
390c80d7
authored
Jul 06, 2020
by
Andreas Opferkuch
Committed by
GitHub
Jul 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ThemeContext: Make useStyles type-aware (#26056)
PLUS: Make it more consise Add unit test
parent
a2737c08
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
+31
-5
packages/grafana-ui/src/themes/ThemeContext.test.tsx
+27
-0
packages/grafana-ui/src/themes/ThemeContext.tsx
+4
-5
No files found.
packages/grafana-ui/src/themes/ThemeContext.test.tsx
0 → 100644
View file @
390c80d7
import
React
from
'react'
;
import
{
config
}
from
'@grafana/runtime'
;
import
{
css
}
from
'emotion'
;
import
{
mount
}
from
'enzyme'
;
import
{
useStyles
}
from
'./ThemeContext'
;
describe
(
'useStyles'
,
()
=>
{
it
(
'passes in theme and returns style object'
,
()
=>
{
const
Dummy
:
React
.
FC
=
function
()
{
const
styles
=
useStyles
(
theme
=>
{
expect
(
theme
).
toEqual
(
config
.
theme
);
return
{
someStyle
:
css
`
color:
${
theme
?.
palette
.
critical
};
`,
};
});
expect(typeof styles.someStyle).toBe('string');
return <div>dummy</div>;
};
mount(<Dummy />);
});
});
packages/grafana-ui/src/themes/ThemeContext.tsx
View file @
390c80d7
...
...
@@ -38,12 +38,11 @@ export const withTheme = <P extends Themeable, S extends {} = {}>(Component: Rea
export function useTheme(): GrafanaTheme
{
return
useContext
(
ThemeContextMock
||
ThemeContext
);
}
/** Hook for using memoized styles with access to the theme. */
export const useStyles = (getStyles: (theme?: GrafanaTheme) =
>
any) =
>
{
const
currentTheme
=
useTheme
();
const
callback
=
stylesFactory
(
stylesTheme
=>
getStyles
(
stylesTheme
));
return
callback
(
currentTheme
);
}
;
export function useStyles
<
T
>
(getStyles: (theme: GrafanaTheme) =
>
T)
{
return
stylesFactory
(
getStyles
)(
useTheme
());
}
/**
* Enables theme context mocking
...
...
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