-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46b310a
commit af6b78c
Showing
8 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from ipywidgets import Widget | ||
from traitlets import Unicode, Bool | ||
from ._version import semver | ||
|
||
|
||
class Themes: | ||
def __init__(self): | ||
self.light = ThemeColors( | ||
_theme_name='light', | ||
primary='#1976D2', | ||
secondary='#424242', | ||
accent='#82B1FF', | ||
error='#FF5252', | ||
info='#2196F3', | ||
success='#4CAF50', | ||
warning='#FB8C00') | ||
|
||
self.dark = ThemeColors( | ||
_theme_name='dark', | ||
primary='#2196F3', | ||
secondary='#424242', | ||
accent='#FF4081', | ||
error='#FF5252', | ||
info='#2196F3', | ||
success='#4CAF50', | ||
warning='#FB8C00') | ||
|
||
|
||
class Theme(Widget): | ||
_model_name = Unicode('ThemeModel').tag(sync=True) | ||
|
||
_model_module = Unicode('jupyter-vuetify').tag(sync=True) | ||
|
||
_view_module_version = Unicode(semver).tag(sync=True) | ||
|
||
_model_module_version = Unicode(semver).tag(sync=True) | ||
|
||
dark = Bool(False).tag(sync=True) | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
self.themes = Themes() | ||
|
||
|
||
class ThemeColors(Widget): | ||
|
||
_model_name = Unicode('ThemeColorsModel').tag(sync=True) | ||
|
||
_model_module = Unicode('jupyter-vuetify').tag(sync=True) | ||
|
||
_view_module_version = Unicode(semver).tag(sync=True) | ||
|
||
_model_module_version = Unicode(semver).tag(sync=True) | ||
|
||
_theme_name = Unicode().tag(sync=True) | ||
|
||
primary = Unicode().tag(sync=True) | ||
secondary = Unicode().tag(sync=True) | ||
accent = Unicode().tag(sync=True) | ||
error = Unicode().tag(sync=True) | ||
info = Unicode().tag(sync=True) | ||
success = Unicode().tag(sync=True) | ||
warning = Unicode().tag(sync=True) | ||
anchor = Unicode(None, allow_none=True).tag(sync=True) | ||
|
||
|
||
theme = Theme() | ||
|
||
__all__ = ['theme'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* eslint camelcase: off */ | ||
import { WidgetModel } from '@jupyter-widgets/base'; | ||
import colors from '@mariobuikhuizen/vuetify/lib/util/colors'; | ||
import vuetify from './plugins/vuetify'; | ||
|
||
export class ThemeModel extends WidgetModel { | ||
defaults() { | ||
return { | ||
...super.defaults(), | ||
...{ | ||
_model_name: 'ThemeModel', | ||
_model_module: 'jupyter-vuetify', | ||
_view_module_version: '0.1.11', | ||
_model_module_version: '0.1.11', | ||
dark: null, | ||
}, | ||
}; | ||
} | ||
|
||
constructor(...args) { | ||
super(...args); | ||
|
||
if (!vuetify) { | ||
return; | ||
} | ||
vuetify.framework.theme.dark = this.get('dark'); | ||
this.on('change:dark', () => { | ||
vuetify.framework.theme.dark = this.get('dark'); | ||
}); | ||
} | ||
} | ||
|
||
ThemeModel.serializers = { | ||
...WidgetModel.serializers, | ||
}; | ||
|
||
export class ThemeColorsModel extends WidgetModel { | ||
defaults() { | ||
return { | ||
...super.defaults(), | ||
...{ | ||
_model_name: 'ThemeColorsModel', | ||
_model_module: 'jupyter-vuetify', | ||
_view_module_version: '0.1.11', | ||
_model_module_version: '0.1.11', | ||
_theme_name: null, | ||
primary: null, | ||
secondary: null, | ||
accent: null, | ||
error: null, | ||
info: null, | ||
success: null, | ||
warning: null, | ||
anchor: null, | ||
}, | ||
}; | ||
} | ||
|
||
constructor(...args) { | ||
super(...args); | ||
|
||
if (!vuetify) { | ||
return; | ||
} | ||
|
||
const themeName = this.get('_theme_name'); | ||
|
||
this.keys() | ||
.filter(prop => !prop.startsWith('_')) | ||
.forEach((prop) => { | ||
vuetify.framework.theme.themes[themeName][prop] = convertColor(this.get(prop)); | ||
this.on(`change:${prop}`, () => { | ||
vuetify.framework.theme.themes[themeName][prop] = convertColor(this.get(prop)); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
ThemeColorsModel.serializers = { | ||
...WidgetModel.serializers, | ||
}; | ||
|
||
function convertColor(colorStr) { | ||
if (colorStr == null) { | ||
return null; | ||
} | ||
|
||
if (colorStr.startsWith('colors')) { | ||
const parts = colorStr.split('.').slice(1); | ||
let result = colors; | ||
|
||
parts.forEach(part => { | ||
result = result[part]; | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
return colorStr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// import vuetify from 'vuetify'; | ||
|
||
/* The import above would break voila-vuetify and voila-embed users, so use the workaround below | ||
* until all users have upgraded to Voila-vuetify > 0.2.2 and voila-embed > 2020-02-11, or | ||
* ipyvuetify bumps a major version */ | ||
const vuetify = window.app && window.app.$vuetify && { framework: window.app.$vuetify }; | ||
|
||
export default vuetify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters