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

Default Theme #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"dist/theming.js": {
"bundled": 51727,
"minified": 17238,
"gzipped": 5434
"bundled": 52050,
"minified": 17275,
"gzipped": 5454
},
"dist/theming.min.js": {
"bundled": 19263,
"minified": 7337,
"gzipped": 2662
"bundled": 19692,
"minified": 7449,
"gzipped": 2706
},
"dist/theming.cjs.js": {
"bundled": 5974,
"minified": 3855,
"gzipped": 1276
"bundled": 6283,
"minified": 3907,
"gzipped": 1298
},
"dist/theming.esm.js": {
"bundled": 5502,
"minified": 3457,
"gzipped": 1197,
"bundled": 5811,
"minified": 3509,
"gzipped": 1220,
"treeshaked": {
"rollup": {
"code": 1573,
"code": 1642,
"import_statements": 147
},
"webpack": {
"code": 3069
"code": 3181
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/create-use-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import warning from 'tiny-warning'
import isObject from './is-object'

export default function createUseTheme<Theme>(context: Context<Theme>) {
const useTheme = () => {
const useTheme = (defaultTheme: ?Theme = null) => {
const theme = React.useContext(context)

// Return default theme if not set in the context
// This can be useful if a themed component might not be wrapped in a theme provider
if (!isObject(theme) && isObject(defaultTheme)) {
return defaultTheme;
}

warning(isObject(theme), '[theming] Please use useTheme only with the ThemeProvider')

return theme
Expand Down