Repository navigation
Select appearance (theme) via the preferences dialog #4919
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
18844c0
Add an appearance tab to the preferences dialog
niik f8314fa
An initial appearance page
niik ef46b8b
Initial persistence of theme in app-store/state
niik 75b5310
Move application theme into its own file
niik d63115e
Initital theme persistence
niik fa709c0
Use a component to update the appearance
niik 8f4b191
Wire up setting the selected theme
niik a4c3c5c
Always use the light theme in the welcome flow
niik 3a3ff26
Merge branch 'oh-darth-where-art-thou' into darth-preferences
niik f87f1c8
Prettify
niik e205147
Merge branch 'master' into darth-preferences
niik 2218c57
Fix typos
niik c7c936e
Drop weird language
niik 225a0fa
:art: Copy paste fail
niik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| export enum PreferencesTab { | ||
| Accounts = 0, | ||
| Git, | ||
| Advanced, | ||
| Git = 1, | ||
| Appearance = 2, | ||
| Advanced = 3, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import * as React from 'react' | ||
| import { ApplicationTheme, getThemeName } from './lib/application-theme' | ||
|
|
||
| interface IAppThemeProps { | ||
| readonly theme: ApplicationTheme | ||
| } | ||
|
|
||
| /** | ||
| * A pseudo-component responsible for adding the applicable CSS | ||
| * class names to the body tag in order to apply the currently | ||
| * selected theme. | ||
| * | ||
| * This component is a PureComponent, meaning that it'll only | ||
| * render when its props changes (shallow comparison). | ||
| * | ||
| * This component does not render anything into the DOM, it's | ||
| * purely (a)busing the component lifecycle to manipulate the | ||
| * body class list. | ||
| */ | ||
| export class AppTheme extends React.PureComponent<IAppThemeProps> { | ||
| public componentDidMount() { | ||
| this.ensureTheme() | ||
| } | ||
|
|
||
| public componentDidUpdate() { | ||
| this.ensureTheme() | ||
| } | ||
|
|
||
| public componentWillUnmount() { | ||
| this.clearThemes() | ||
| } | ||
|
|
||
| private ensureTheme() { | ||
| const newThemeClassName = `theme-${getThemeName(this.props.theme)}` | ||
| const body = document.body | ||
|
|
||
| if (body.classList.contains(newThemeClassName)) { | ||
| return | ||
| } | ||
|
|
||
| this.clearThemes() | ||
|
|
||
| body.classList.add(newThemeClassName) | ||
| } | ||
|
|
||
| private clearThemes() { | ||
| const body = document.body | ||
|
|
||
| for (const className of body.classList) { | ||
| if (className.startsWith('theme-')) { | ||
| body.classList.remove(className) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public render() { | ||
| return null | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { assertNever } from '../../lib/fatal-error' | ||
|
|
||
| /** | ||
| * A set of the user-selectable appearances (aka themes) | ||
| */ | ||
| export enum ApplicationTheme { | ||
| Light, | ||
| Dark, | ||
| } | ||
|
|
||
| /** | ||
| * Gets the friendly name of an application theme for use | ||
| * in persisting to storage and/or calculating the required | ||
| * body class name to set in order to apply the theme. | ||
| */ | ||
| export function getThemeName(theme: ApplicationTheme): string { | ||
| switch (theme) { | ||
| case ApplicationTheme.Light: | ||
| return 'light' | ||
| case ApplicationTheme.Dark: | ||
| return 'dark' | ||
| default: | ||
| return assertNever(theme, `Unknown theme ${theme}`) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import * as React from 'react' | ||
| import { DialogContent } from '../dialog' | ||
| import { | ||
| VerticalSegmentedControl, | ||
| ISegmentedItem, | ||
| } from '../lib/vertical-segmented-control' | ||
| import { ApplicationTheme } from '../lib/application-theme' | ||
| import { fatalError } from '../../lib/fatal-error' | ||
|
|
||
| interface IAppearanceProps { | ||
| readonly selectedTheme: ApplicationTheme | ||
| readonly onSelectedThemeChanged: (theme: ApplicationTheme) => void | ||
| } | ||
|
|
||
| const themes: ReadonlyArray<ISegmentedItem> = [ | ||
| { title: 'Light', description: 'The default theme of GitHub Desktop' }, | ||
| { | ||
| title: 'Dark (beta)', | ||
| description: | ||
| 'A beta version of our dark theme. Still under development. Please report any issues you may find to our issue tracker.', | ||
| }, | ||
| ] | ||
|
|
||
| export class Appearance extends React.Component<IAppearanceProps, {}> { | ||
| private onSelectedThemeChanged = (index: number) => { | ||
| if (index === 0) { | ||
| this.props.onSelectedThemeChanged(ApplicationTheme.Light) | ||
| } else if (index === 1) { | ||
| this.props.onSelectedThemeChanged(ApplicationTheme.Dark) | ||
| } else { | ||
| fatalError(`Unknown theme index ${index}`) | ||
| } | ||
| } | ||
|
|
||
| public render() { | ||
| const selectedIndex = | ||
| this.props.selectedTheme === ApplicationTheme.Dark ? 1 : 0 | ||
|
|
||
| return ( | ||
| <DialogContent> | ||
| <VerticalSegmentedControl | ||
| items={themes} | ||
| selectedIndex={selectedIndex} | ||
| onSelectionChanged={this.onSelectedThemeChanged} | ||
| /> | ||
| </DialogContent> | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.