-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Theming support #428 #1360
Closed
Closed
Theming support #428 #1360
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c19746
Init theming module
usulpro 27fd1e9
Implemet theming
usulpro 4e0d4b4
Provide currentTheme as public API
usulpro 660c164
Add podda themeStore
usulpro 0d25661
Update black theme
usulpro c0b001b
Update docs
usulpro 93c6c14
Fix linting errors
usulpro c87b874
Get rid of theme.js
usulpro 6844098
Better theme providing in down_panel
usulpro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
:root { | ||
background: rgba(232,232,232,1); | ||
background: radial-gradient(ellipse at center, rgba(255,255,255,1) 11%,rgba(232,232,232,1) 100%); | ||
height: 100%; | ||
} |
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
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,5 @@ | ||
import theming from './theming'; | ||
|
||
export default { | ||
theming, | ||
}; |
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,86 @@ | ||
import Podda from 'podda'; | ||
|
||
const themesStore = new Podda({}); | ||
|
||
/** | ||
* themesStore - simple podda store with all "build-in" themes (located in modules/theming/themes/*.js) | ||
* we require them dynamically onLoad | ||
* | ||
* this module provides API: | ||
* | ||
* - selectTheme(themeName: string) selects the current theme | ||
* | ||
* - getTheme(): object returns current theme object | ||
* | ||
* - getThemesList(): arrayOf(strings) returns names of loaded themes | ||
* | ||
* - setTheme(theme: object) adds new or updates existing theme | ||
* | ||
* Usage: | ||
* | ||
* We don't store themes data in clientStore directly, we provide getTheme() API instead | ||
* All containers (modules/ui/containers) passes current theme data to components automatically via `gen_podda_loader` | ||
* it's available inside (root) components as `this.props.theme` | ||
* | ||
*/ | ||
|
||
const reqThemes = require.context('../themes/', true, /.js$/); | ||
reqThemes.keys().forEach((filename) => { | ||
const theme = reqThemes(filename).default; | ||
themesStore.set(theme.name, theme); | ||
}); | ||
|
||
|
||
|
||
themesStore.registerAPI('keys', (store) => { | ||
const keys = Object.keys(store.getAll()); | ||
return keys; | ||
}); | ||
|
||
themesStore.registerAPI('includes', (store, themeName) => { | ||
if (store.keys().indexOf(themeName) > -1) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
|
||
export function updateThemesList(clientStore) { | ||
const themingOptions = clientStore.get('themingOptions'); | ||
themingOptions.themesList = themesStore.keys(); | ||
clientStore.set('themingOptions', themingOptions); | ||
} | ||
|
||
function ensureTheme(currentTheme, themeName) { | ||
if (themesStore.includes(themeName)) { | ||
return themeName; | ||
} | ||
return currentTheme; | ||
} | ||
|
||
function setTheme(theme) { | ||
const themeName = theme.name = theme.name || 'Theme ' + themesStore.keys.length; | ||
themesStore.set(themeName, theme); | ||
return theme; | ||
} | ||
|
||
export default { | ||
selectTheme({ clientStore }, themeName) { | ||
const uiOptions = clientStore.get('uiOptions'); | ||
uiOptions.currentTheme = ensureTheme(clientStore.get('currentTheme'), themeName); | ||
clientStore.set('uiOptions', uiOptions); | ||
}, | ||
|
||
getTheme({ clientStore }) { | ||
var themeName = clientStore.get('uiOptions').currentTheme; | ||
return themesStore.get(themeName); | ||
}, | ||
|
||
getThemesList({ clientStore }) { | ||
return clientStore.get('themingOptions').themesList; | ||
}, | ||
|
||
setTheme({ clientStore }, theme) { | ||
setTheme(theme); | ||
updateThemesList(clientStore); | ||
} | ||
}; |
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,7 @@ | ||
import { themesMap, updateThemesList } from '../actions/theming'; | ||
|
||
|
||
export default function(clientStore, actions) { | ||
updateThemesList(clientStore); | ||
} | ||
|
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,39 @@ | ||
import actions from './actions'; | ||
import init_themes from './configs/init_themes'; | ||
|
||
export default { | ||
actions, | ||
defaultState: { | ||
themingOptions: { | ||
themesList: [], | ||
}, | ||
/** | ||
* Also theming module depends on defaultState.uiOptions.currentTheme = 'default' | ||
* see src/modules/api/index.js | ||
*/ | ||
}, | ||
load({clientStore}, _actions) { | ||
init_themes(clientStore, _actions); | ||
|
||
/** | ||
* Debug: | ||
* uncomment the line below to get access to API via browser console | ||
*/ | ||
// console.log('UI API:', _actions); | ||
/** | ||
* right click on 'UI API:' and 'Store as GlobalVariable' | ||
* api = temp1; | ||
* api.theming.getTheme(); | ||
* api.theming.selectTheme('dark'); | ||
* newTheme = api.theming.getTheme(); | ||
* newTheme.name = 'new'; | ||
* api.theming.setTheme(newTheme); | ||
* api.theming.getThemesList(); | ||
* api.theming.selectTheme('new'); | ||
* newTheme.palette.canvas = 'green'; | ||
* newTheme.palette.background = 'darkgreen'; | ||
* | ||
*/ | ||
} | ||
}; | ||
|
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,25 @@ | ||
import white from './default'; | ||
|
||
export default { | ||
...white, | ||
name: 'dark', | ||
palette: { | ||
background: '#585858', | ||
border: '#898989', | ||
canvas: '#333333', | ||
text: '#d6d6d6', | ||
|
||
|
||
secondaryBorder: '#777777', | ||
secondaryText: '#ffffff', | ||
secondaryBackground: '#585858', | ||
|
||
filterBackground: '#464646', | ||
|
||
logoText: '#d2d2d2', | ||
logoBorder: '#c1c1c1', | ||
|
||
resizerColor: 'rgba(1, 1, 1, 0.0980392)', | ||
resizerBackground: '#4a4a4a', | ||
}, | ||
}; |
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,32 @@ | ||
|
||
export default { | ||
name: 'default', | ||
palette: { | ||
/* Main color settings */ | ||
background: '#f7f7f7' /* background of panels */, | ||
border: '#eeeeee' /* border like in the stories list */, | ||
canvas: 'white' /* preview area */, | ||
text: '#444444' /* active text in panels */, | ||
|
||
secondaryBorder: '#eaeaea' /* border like in the addons panel */, | ||
secondaryText: 'black', | ||
secondaryBackground: 'white' /* addons area */, | ||
|
||
logoText: '#828282' /* text in logo */, | ||
logoBorder: '#c1c1c1' /* border of logo */, | ||
|
||
filterBackground: 'white', | ||
|
||
resizerColor: 'rgba(0, 0, 0, 0.0980392)' /* grips in resizers */, | ||
resizerBackground: '#f7f7f7', | ||
}, | ||
style: { | ||
/* other styling settings */ | ||
inactiveOpacity: 0.5, | ||
}, | ||
spacing: { | ||
/* default spacing settings */ | ||
leftPanelSize: 100, | ||
downPanelSize: 100, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { baseFonts } from '../theme'; | ||
|
||
export default { | ||
export default theme => ({ | ||
empty: { | ||
flex: 1, | ||
display: 'flex', | ||
...baseFonts, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't base font be in the theme ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ |
||
color: theme.palette.text, | ||
fontSize: 11, | ||
letterSpacing: '1px', | ||
textTransform: 'uppercase', | ||
|
@@ -16,9 +17,9 @@ export default { | |
flex: 1, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
background: 'white', | ||
background: theme.palette.canvas, | ||
borderRadius: 4, | ||
border: 'solid 1px rgb(236, 236, 236)', | ||
border: `solid 1px ${theme.palette.border}`, | ||
marginTop: 5, | ||
width: '100%', | ||
}, | ||
|
@@ -29,7 +30,7 @@ export default { | |
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
borderBottom: 'solid 1px #eaeaea', | ||
borderBottom: `solid 1px ${theme.palette.secondaryBorder}`, | ||
}, | ||
|
||
content: { | ||
|
@@ -40,6 +41,7 @@ export default { | |
|
||
tablink: { | ||
...baseFonts, | ||
color: theme.palette.text, | ||
fontSize: 11, | ||
letterSpacing: '1px', | ||
padding: '10px 15px', | ||
|
@@ -55,4 +57,4 @@ export default { | |
activetab: { | ||
opacity: 1, | ||
}, | ||
}; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you'll define the style once, instead of creating it in each call ?
something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅