-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Implement system
option for theme:darkMode
uiSetting
#173044
Changes from 24 commits
243d36c
6af5e73
03e61fc
b0a0017
aa16ab2
f65a833
c8cead5
0d580a6
600c942
87fb6db
f46a24a
9f21ff0
3ea35d3
292510a
aeaabcb
57f52f2
dfb1645
370796f
56c58b5
ff22176
1b5cb27
2b75535
a684d24
cc9fde6
8e3b644
102c6f8
344e1c0
ee143d2
1572925
b8163ae
e4822ee
7d0eefc
26f02dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
*, *:before, *:after { | ||
box-sizing: border-box; | ||
} | ||
|
||
html, body, div, span, svg { | ||
margin: 0; | ||
padding: 0; | ||
border: none; | ||
vertical-align: baseline; | ||
} | ||
|
||
body, html { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
display: block; | ||
} | ||
|
||
.kbnWelcomeView { | ||
line-height: 1.5; | ||
height: 100%; | ||
display: -webkit-box; | ||
display: -webkit-flex; | ||
display: -ms-flexbox; | ||
display: flex; | ||
-webkit-box-flex: 1; | ||
-webkit-flex: 1 0 auto; | ||
-ms-flex: 1 0 auto; | ||
flex: 1 0 auto; | ||
-webkit-box-orient: vertical; | ||
-webkit-box-direction: normal; | ||
-webkit-flex-direction: column; | ||
-ms-flex-direction: column; | ||
flex-direction: column; | ||
-webkit-box-align: center; | ||
-webkit-align-items: center; | ||
-ms-flex-align: center; | ||
align-items: center; | ||
-webkit-box-pack: center; | ||
-webkit-justify-content: center; | ||
-ms-flex-pack: center; | ||
justify-content: center; | ||
} | ||
|
||
.kbnWelcomeTitle { | ||
color: #000; | ||
font-size: 20px; | ||
font-family: sans-serif; | ||
margin: 16px 0; | ||
animation: fadeIn 1s ease-in-out; | ||
animation-fill-mode: forwards; | ||
opacity: 0; | ||
animation-delay: 1.0s; | ||
} | ||
|
||
.kbnWelcomeText { | ||
display: block; | ||
font-size: 14px; | ||
font-family: sans-serif; | ||
line-height: 40px !important; | ||
height: 40px !important; | ||
color: #98A2B3; | ||
} | ||
|
||
.kbnLoaderWrap { | ||
text-align: center; | ||
line-height: 1; | ||
font-family: sans-serif; | ||
letter-spacing: -.005em; | ||
-webkit-text-size-adjust: 100%; | ||
-ms-text-size-adjust: 100%; | ||
font-kerning: normal; | ||
font-weight: 400; | ||
} | ||
|
||
.kbnLoaderWrap svg { | ||
width: 64px; | ||
height: 64px; | ||
margin: auto; | ||
line-height: 1; | ||
} | ||
|
||
.kbnLoader path { | ||
stroke: #FFFFFF; | ||
} | ||
|
||
.kbnProgress { | ||
display: inline-block; | ||
position: relative; | ||
width: 32px; | ||
height: 4px; | ||
overflow: hidden; | ||
line-height: 1; | ||
} | ||
|
||
.kbnProgress:before { | ||
position: absolute; | ||
content: ''; | ||
height: 4px; | ||
width: 100%; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
transform: scaleX(0) translateX(0%); | ||
animation: kbnProgress 1s cubic-bezier(.694, .0482, .335, 1) infinite; | ||
} | ||
|
||
@keyframes kbnProgress { | ||
0% { | ||
transform: scaleX(1) translateX(-100%); | ||
} | ||
|
||
100% { | ||
transform: scaleX(1) translateX(100%); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/* eslint-disable no-var */ | ||
|
||
function systemIsDark() { | ||
try { | ||
return window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
function createInlineStyles(content) { | ||
var head = document.getElementsByTagName('head')[0]; | ||
var style = document.createElement('style'); | ||
style.textContent = content; | ||
head.appendChild(style); | ||
} | ||
|
||
// must be kept in sync with | ||
// packages/core/rendering/core-rendering-server-internal/src/views/styles.tsx | ||
|
||
var lightStyles = [ | ||
'html { background-color: #F8FAFD; }', | ||
'.kbnWelcomeText { color: #69707D; }', | ||
'.kbnProgress { background-color: #F5F7FA; }', | ||
'.kbnProgress:before { background-color: #006DE4; }', | ||
].join('\n'); | ||
|
||
var darkStyles = [ | ||
'html { background-color: #141519; }', | ||
'.kbnWelcomeText { color: #98A2B3; }', | ||
'.kbnProgress { background-color: #25262E; }', | ||
'.kbnProgress:before { background-color: #1BA9F5; }', | ||
].join('\n'); | ||
|
||
if (systemIsDark()) { | ||
createInlineStyles(darkStyles); | ||
} else { | ||
createInlineStyles(lightStyles); | ||
} | ||
Comment on lines
+43
to
+47
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. So this was required to work around point
So the only solution I found was:
I would have loved to have a single place to do that, but until we properly implement an |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import type { PluginName, DiscoveredPlugin } from '@kbn/core-base-common'; | |
import type { ThemeVersion } from '@kbn/ui-shared-deps-npm'; | ||
import type { EnvironmentMode, PackageInfo } from '@kbn/config'; | ||
import type { CustomBranding } from '@kbn/core-custom-branding-common'; | ||
import type { DarkModeValue } from '@kbn/core-ui-settings-common'; | ||
|
||
/** @internal */ | ||
export interface InjectedMetadataClusterInfo { | ||
|
@@ -35,6 +36,16 @@ export interface InjectedMetadataExternalUrlPolicy { | |
protocol?: string; | ||
} | ||
|
||
/** @internal */ | ||
export interface InjectedMetadataTheme { | ||
darkMode: DarkModeValue; | ||
version: ThemeVersion; | ||
stylesheetPaths: { | ||
default: string[]; | ||
dark: string[]; | ||
}; | ||
} | ||
|
||
/** @internal */ | ||
export interface InjectedMetadata { | ||
version: string; | ||
|
@@ -53,10 +64,7 @@ export interface InjectedMetadata { | |
i18n: { | ||
translationsUrl: string; | ||
}; | ||
theme: { | ||
darkMode: boolean; | ||
version: ThemeVersion; | ||
}; | ||
theme: InjectedMetadataTheme; | ||
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. I guess InjectedMetadata will stay with us for a while longer 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. True, but fwiw this PR isn't introducing anything new that wasn't already in the list of things we need to figure out to get rid of this injection system. |
||
csp: { | ||
warnLegacyBrowsers: boolean; | ||
}; | ||
|
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.
I extracted the static inline styles (from
packages/core/rendering/core-rendering-server-internal/src/views/styles.tsx
), and added them in a css file instead of having them inlined in the template. Better isolation of concern, and now it's cache-able.