1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/ReactNativeClient/lib/components/global-style.js

106 lines
2.3 KiB
JavaScript
Raw Normal View History

const Setting = require('lib/models/Setting.js');
const { Platform } = require('react-native');
const { themeById } = require('lib/theme');
2017-08-01 19:59:01 +02:00
const baseStyle = {
appearance: 'light',
2017-07-30 23:04:26 +02:00
fontSize: 16,
noteViewerFontSize: 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,
fontSizeSmaller: 14,
disabledOpacity: 0.2,
lineHeight: '1.6em',
2017-07-21 23:40:02 +02:00
};
const themeCache_ = {};
2017-08-01 19:59:01 +02:00
function addExtraStyles(style) {
style.marginRight = style.margin;
style.marginLeft = style.margin;
style.marginTop = style.margin;
style.marginBottom = style.margin;
style.icon = {
color: style.color,
fontSize: 30,
};
style.lineInput = {
color: style.color,
backgroundColor: style.backgroundColor,
borderBottomWidth: 1,
borderColor: style.dividerColor,
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.urlColor,
2018-03-27 19:41:19 +02:00
fontSize: style.fontSize,
};
style.headerStyle = {
color: style.color,
fontSize: style.fontSize * 1.2,
fontWeight: 'bold',
};
style.headerWrapperStyle = {
backgroundColor: style.headerBackgroundColor,
};
style.keyboardAppearance = style.appearance;
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
const cacheKey = [theme].join('-');
if (themeCache_[cacheKey]) return themeCache_[cacheKey];
const output = Object.assign({}, baseStyle, themeById(theme));
themeCache_[cacheKey] = addExtraStyles(output);
return themeCache_[cacheKey];
2017-08-01 19:59:01 +02:00
}
module.exports = { themeStyle, editorFont };