1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/ReactNativeClient/lib/components/global-style.js

160 lines
4.0 KiB
JavaScript
Raw Normal View History

const Setting = require('lib/models/Setting.js');
const { Platform } = require('react-native');
2017-08-01 19:59:01 +02:00
2017-07-21 23:40:02 +02:00
const globalStyle = {
2017-07-30 23:04:26 +02:00
fontSize: 16,
2017-07-21 23:40:02 +02:00
margin: 15, // No text and no interactive component should be within this margin
2017-07-30 23:04:26 +02:00
itemMarginTop: 10,
itemMarginBottom: 10,
2019-07-29 15:43:53 +02:00
backgroundColor: '#ffffff',
color: '#555555', // For regular text
colorError: 'red',
colorWarn: '#9A5B00',
colorFaded: '#777777', // For less important text
2017-07-30 23:04:26 +02:00
fontSizeSmaller: 14,
2019-07-29 15:43:53 +02:00
dividerColor: '#dddddd',
strongDividerColor: '#aaaaaa',
selectedColor: '#e5e5e5',
headerBackgroundColor: '#F0F0F0',
disabledOpacity: 0.2,
colorUrl: '#7B81FF',
2019-07-29 15:43:53 +02:00
textSelectionColor: '#0096FF',
2017-07-21 23:40:02 +02:00
2019-07-29 15:43:53 +02:00
raisedBackgroundColor: '#0080EF',
raisedColor: '#003363',
raisedHighlightedColor: '#ffffff',
2019-07-29 15:43:53 +02:00
warningBackgroundColor: '#FFD08D',
2017-12-30 21:57:34 +02:00
2017-07-21 23:40:02 +02:00
// For WebView - must correspond to the properties above
htmlFontSize: '16px',
2019-02-07 01:52:29 +02:00
htmlColor: '#222222',
htmlBackgroundColor: 'white',
2019-02-07 01:52:29 +02:00
htmlDividerColor: 'rgb(230,230,230)',
htmlLinkColor: 'rgb(80,130,190)',
htmlLineHeight: '1.6em',
htmlCodeBackgroundColor: 'rgb(243, 243, 243)',
htmlCodeBorderColor: 'rgb(220, 220, 220)',
htmlCodeColor: 'rgb(0,0,0)',
codeThemeCss: 'atom-one-light.css',
2017-07-21 23:40:02 +02:00
};
globalStyle.marginRight = globalStyle.margin;
globalStyle.marginLeft = globalStyle.margin;
2017-07-22 17:55:09 +02:00
globalStyle.marginTop = globalStyle.margin;
globalStyle.marginBottom = globalStyle.margin;
2019-09-19 23:51:18 +02:00
globalStyle.htmlMarginLeft = `${((globalStyle.marginLeft / 10) * 0.6).toFixed(2)}em`;
2017-07-21 23:40:02 +02:00
2017-08-01 19:59:01 +02:00
let themeCache_ = {};
function addExtraStyles(style) {
style.icon = {
color: style.color,
fontSize: 30,
};
style.lineInput = {
color: style.color,
backgroundColor: style.backgroundColor,
borderBottomWidth: 1,
borderColor: style.strongDividerColor,
paddingBottom: 0,
};
if (Platform.OS === 'ios') {
2019-02-03 18:57:29 +02:00
delete style.lineInput.borderBottomWidth;
delete style.lineInput.borderColor;
}
style.buttonRow = {
flexDirection: 'row',
borderTopWidth: 1,
borderTopColor: style.dividerColor,
paddingTop: 10,
};
style.normalText = {
color: style.color,
fontSize: style.fontSize,
};
2018-03-27 19:41:19 +02:00
style.urlText = {
color: style.colorUrl,
fontSize: style.fontSize,
};
style.headerStyle = {
color: style.color,
fontSize: style.fontSize * 1.2,
fontWeight: 'bold',
};
style.headerWrapperStyle = {
backgroundColor: style.headerBackgroundColor,
};
return style;
}
function editorFont(fontId) {
// IMPORTANT: The font mapping must match the one in Setting.js
const fonts = {
[Setting.FONT_DEFAULT]: null,
[Setting.FONT_MENLO]: 'Menlo',
[Setting.FONT_COURIER_NEW]: 'Courier New',
[Setting.FONT_AVENIR]: 'Avenir',
[Setting.FONT_MONOSPACE]: 'monospace',
};
if (!fontId) {
console.warn('Editor font not set! Falling back to default font."');
fontId = Setting.FONT_DEFAULT;
}
return fonts[fontId];
}
2017-08-01 19:59:01 +02:00
function themeStyle(theme) {
if (!theme) {
console.warn('Theme not set! Defaulting to Light theme.');
theme = Setting.THEME_LIGHT;
}
2018-03-27 19:41:19 +02:00
2017-08-01 19:59:01 +02:00
if (themeCache_[theme]) return themeCache_[theme];
let output = Object.assign({}, globalStyle);
if (theme == Setting.THEME_LIGHT) return addExtraStyles(output);
2017-08-01 19:59:01 +02:00
output.backgroundColor = '#1D2024';
output.color = '#dddddd';
output.colorFaded = '#777777';
output.dividerColor = '#555555';
output.strongDividerColor = '#888888';
output.selectedColor = '#333333';
output.textSelectionColor = '#00AEFF';
output.headerBackgroundColor = '#2D3136';
2017-08-01 19:59:01 +02:00
2019-07-29 15:43:53 +02:00
output.raisedBackgroundColor = '#0F2051';
output.raisedColor = '#788BC3';
output.raisedHighlightedColor = '#ffffff';
2017-08-01 19:59:01 +02:00
output.htmlColor = 'rgb(220,220,220)';
output.htmlBackgroundColor = 'rgb(29,32,36)';
output.htmlLinkColor = 'rgb(166,166,255)';
2017-08-01 20:53:50 +02:00
2019-02-07 01:52:29 +02:00
output.htmlDividerColor = '#3D444E';
output.htmlLinkColor = 'rgb(166,166,255)';
output.htmlCodeColor = '#ffffff';
output.htmlCodeBackgroundColor = 'rgb(47, 48, 49)';
output.htmlCodeBorderColor = 'rgb(70, 70, 70)';
output.codeThemeCss = 'hljs-atom-one-dark-reasonable.css';
output.colorUrl = '#7B81FF';
2017-08-01 19:59:01 +02:00
themeCache_[theme] = output;
return addExtraStyles(themeCache_[theme]);
2017-08-01 19:59:01 +02:00
}
module.exports = { globalStyle, themeStyle, editorFont };