Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scientia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zhige Yu
scientia
Commits
01e6cd0f
Commit
01e6cd0f
authored
4 years ago
by
danieldeng2
Browse files
Options
Downloads
Patches
Plain Diff
Defaults theme to follow system
parent
7b967e46
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/App.tsx
+13
-1
13 additions, 1 deletion
src/components/App.tsx
src/components/pages/SettingsModal/index.tsx
+18
-3
18 additions, 3 deletions
src/components/pages/SettingsModal/index.tsx
with
31 additions
and
4 deletions
src/components/App.tsx
+
13
−
1
View file @
01e6cd0f
...
@@ -38,8 +38,12 @@ class App extends React.Component<{}, AppState> {
...
@@ -38,8 +38,12 @@ class App extends React.Component<{}, AppState> {
}
%`
;
}
%`
;
const
currentTheme
=
localStorage
.
getItem
(
"
theme
"
);
const
currentTheme
=
localStorage
.
getItem
(
"
theme
"
);
if
(
currentTheme
)
{
if
(
currentTheme
==
"
light
"
||
currentTheme
==
"
dark
"
)
{
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
currentTheme
);
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
currentTheme
);
}
else
{
let
mq
=
window
.
matchMedia
(
"
(prefers-color-scheme: dark)
"
);
mq
.
addListener
((
mq
)
=>
this
.
setDarkTheme
(
mq
.
matches
));
this
.
setDarkTheme
(
mq
.
matches
);
}
}
window
.
addEventListener
(
"
resize
"
,
()
=>
{
window
.
addEventListener
(
"
resize
"
,
()
=>
{
...
@@ -51,6 +55,13 @@ class App extends React.Component<{}, AppState> {
...
@@ -51,6 +55,13 @@ class App extends React.Component<{}, AppState> {
this
.
showOrHideSideBars
();
this
.
showOrHideSideBars
();
}
}
setDarkTheme
(
toSet
:
boolean
)
{
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
toSet
?
"
dark
"
:
"
light
"
);
}
toggleLeftBar
()
{
toggleLeftBar
()
{
if
(
window
.
innerWidth
<=
1024
)
{
if
(
window
.
innerWidth
<=
1024
)
{
this
.
setState
({
this
.
setState
({
...
@@ -108,6 +119,7 @@ class App extends React.Component<{}, AppState> {
...
@@ -108,6 +119,7 @@ class App extends React.Component<{}, AppState> {
fileView
=
{
this
.
state
.
fileView
}
fileView
=
{
this
.
state
.
fileView
}
onCardViewClick
=
{
()
=>
this
.
setFileView
(
"
card
"
)
}
onCardViewClick
=
{
()
=>
this
.
setFileView
(
"
card
"
)
}
onListViewClick
=
{
()
=>
this
.
setFileView
(
"
list
"
)
}
onListViewClick
=
{
()
=>
this
.
setFileView
(
"
list
"
)
}
setDarkTheme
=
{
(
b
)
=>
this
.
setDarkTheme
(
b
)
}
/>
/>
<
Switch
>
<
Switch
>
...
...
This diff is collapsed.
Click to expand it.
src/components/pages/SettingsModal/index.tsx
+
18
−
3
View file @
01e6cd0f
...
@@ -13,6 +13,7 @@ interface Props {
...
@@ -13,6 +13,7 @@ interface Props {
show
:
boolean
;
show
:
boolean
;
onHide
:
any
;
onHide
:
any
;
fileView
:
string
;
fileView
:
string
;
setDarkTheme
:
(
toSet
:
boolean
)
=>
any
;
onCardViewClick
:
(
event
:
React
.
MouseEvent
)
=>
void
;
onCardViewClick
:
(
event
:
React
.
MouseEvent
)
=>
void
;
onListViewClick
:
(
event
:
React
.
MouseEvent
)
=>
void
;
onListViewClick
:
(
event
:
React
.
MouseEvent
)
=>
void
;
}
}
...
@@ -21,6 +22,7 @@ const SettingsModal: React.FC<Props> = ({
...
@@ -21,6 +22,7 @@ const SettingsModal: React.FC<Props> = ({
show
,
show
,
onHide
,
onHide
,
fileView
,
fileView
,
setDarkTheme
,
onCardViewClick
,
onCardViewClick
,
onListViewClick
,
onListViewClick
,
})
=>
{
})
=>
{
...
@@ -29,7 +31,7 @@ const SettingsModal: React.FC<Props> = ({
...
@@ -29,7 +31,7 @@ const SettingsModal: React.FC<Props> = ({
"
90
"
"
90
"
);
);
const
[
theme
,
setTheme
]
=
useLocalStorage
(
"
theme
"
,
"
ligh
t
"
);
const
[
theme
,
setTheme
]
=
useLocalStorage
(
"
theme
"
,
"
defaul
t
"
);
return
(
return
(
<
Modal
<
Modal
...
@@ -72,11 +74,24 @@ const SettingsModal: React.FC<Props> = ({
...
@@ -72,11 +74,24 @@ const SettingsModal: React.FC<Props> = ({
<
Form
.
Group
style
=
{
{
alignItems
:
"
center
"
}
}
>
<
Form
.
Group
style
=
{
{
alignItems
:
"
center
"
}
}
>
<
Form
.
Label
>
Theme
</
Form
.
Label
>
<
Form
.
Label
>
Theme
</
Form
.
Label
>
<
ButtonGroup
style
=
{
{
float
:
"
right
"
}
}
>
<
ButtonGroup
style
=
{
{
float
:
"
right
"
}
}
>
<
Button
className
=
{
styles
.
modalToggleButton
}
active
=
{
theme
===
"
default
"
}
onClick
=
{
()
=>
{
let
mq
=
window
.
matchMedia
(
"
(prefers-color-scheme: dark)
"
);
mq
.
addListener
((
mq
)
=>
setDarkTheme
(
mq
.
matches
));
setDarkTheme
(
mq
.
matches
);
setTheme
(
"
default
"
);
}
}
variant
=
"secondary"
>
Default
</
Button
>
<
Button
<
Button
className
=
{
styles
.
modalToggleButton
}
className
=
{
styles
.
modalToggleButton
}
active
=
{
theme
===
"
light
"
}
active
=
{
theme
===
"
light
"
}
onClick
=
{
()
=>
{
onClick
=
{
()
=>
{
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
"
light
"
);
setDarkTheme
(
false
);
setTheme
(
"
light
"
);
setTheme
(
"
light
"
);
}
}
}
}
variant
=
"secondary"
variant
=
"secondary"
...
@@ -87,7 +102,7 @@ const SettingsModal: React.FC<Props> = ({
...
@@ -87,7 +102,7 @@ const SettingsModal: React.FC<Props> = ({
className
=
{
styles
.
modalToggleButton
}
className
=
{
styles
.
modalToggleButton
}
active
=
{
theme
===
"
dark
"
}
active
=
{
theme
===
"
dark
"
}
onClick
=
{
()
=>
{
onClick
=
{
()
=>
{
document
.
documentElement
.
setAttribute
(
"
data-theme
"
,
"
dark
"
);
setDarkTheme
(
true
);
setTheme
(
"
dark
"
);
setTheme
(
"
dark
"
);
}
}
}
}
variant
=
"secondary"
variant
=
"secondary"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment