Make input controls dark in the dark theme

This commit is contained in:
Kovid Goyal 2020-08-06 21:16:59 +05:30
parent c82c7d1a27
commit c96a1dc31e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,6 +7,7 @@ LIGHT = '#F6F3E9'
LIGHT_DARKER = '#b6b3a8' LIGHT_DARKER = '#b6b3a8'
LIGHT_GRADIENT = 'linear-gradient(to bottom, {}, {})'.format(LIGHT, LIGHT_DARKER) LIGHT_GRADIENT = 'linear-gradient(to bottom, {}, {})'.format(LIGHT, LIGHT_DARKER)
DT_DARK = '#2d2d2d' DT_DARK = '#2d2d2d'
DT_DARK_DARKER = 'black'
DT_DARK_LIGHTER = '#777' DT_DARK_LIGHTER = '#777'
DT_LIGHT = '#ddd' DT_LIGHT = '#ddd'
DARK_GRADIENT = 'linear-gradient(to bottom, {}, {})'.format(DT_DARK_LIGHTER, DT_DARK) DARK_GRADIENT = 'linear-gradient(to bottom, {}, {})'.format(DT_DARK_LIGHTER, DT_DARK)
@ -46,6 +47,10 @@ DEFAULT_COLORS = {
'dialog-background': c(LIGHT, DT_DARK), 'dialog-background': c(LIGHT, DT_DARK),
'dialog-background-image': c(LIGHT_GRADIENT, DARK_GRADIENT), 'dialog-background-image': c(LIGHT_GRADIENT, DARK_GRADIENT),
'dialog-foreground': c(DARK, DT_LIGHT), 'dialog-foreground': c(DARK, DT_LIGHT),
# Native controls
'input-background': c('field', DT_DARK_DARKER),
'input-foreground': c('fieldtext', DT_LIGHT),
} }
DEFAULT_SIZES = { DEFAULT_SIZES = {
@ -68,13 +73,14 @@ def set_ui_colors(is_dark_theme):
def css_for_variables(): def css_for_variables():
input_css = 'input, textarea { color: var(--calibre-color-input-foreground); background-color: var(--calibre-color-input-background); }'
is_dark_theme = window.matchMedia('(prefers-color-scheme: dark)').matches is_dark_theme = window.matchMedia('(prefers-color-scheme: dark)').matches
attr = 'dark' if is_dark_theme else 'light' attr = 'dark' if is_dark_theme else 'light'
ans = v'[]' ans = v'[]'
for k in DEFAULT_COLORS: for k in DEFAULT_COLORS:
val = DEFAULT_COLORS[k][attr] val = DEFAULT_COLORS[k][attr]
ans.push(f'--calibre-color-{k}: {val};') ans.push(f'--calibre-color-{k}: {val};')
return ':root { ' + ans.join('\n') + '}' return ':root { ' + ans.join('\n') + '}\n\n' + input_css
def get_color(name): def get_color(name):