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
Dark mode editor support. #198
Merged
Lego6245
merged 13 commits into
microsoft:roosterjs-darkmode-alpha
from
Lego6245:darkmode-rooster
Jan 24, 2019
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
be049ed
Dark mode edtior support
Lego6245 8839afb
set background color
Lego6245 7558d4f
address pr comments
Lego6245 3de9795
fixes
Lego6245 cc3685b
docs
Lego6245 89c983b
addressed some more comments
Lego6245 00886b7
removed redundant option
Lego6245 31ddc3d
updating applyFormat call for dark mode
Lego6245 bed5f0d
fix
Lego6245 ef7ff35
fix paste
Lego6245 30b5144
Merge branch 'master' into darkmode-rooster
Lego6245 de32c96
we should blank this style by default
Lego6245 76d19d0
remove cast
Lego6245 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
26 changes: 21 additions & 5 deletions
26
packages/roosterjs-editor-api/lib/format/setBackgroundColor.ts
This file contains 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,14 +1,30 @@ | ||
import applyInlineStyle from '../utils/applyInlineStyle'; | ||
import { Editor } from 'roosterjs-editor-core'; | ||
import { ModeIndependentColor } from 'roosterjs-editor-types'; | ||
|
||
/** | ||
* Set background color at current selection | ||
* @param editor The editor instance | ||
* @param color The color string, can be any of the predefined color names (e.g, 'red') | ||
* @param color One of two options: | ||
* The color string, can be any of the predefined color names (e.g, 'red') | ||
* or hexadecimal color string (e.g, '#FF0000') or rgb value (e.g, 'rgb(255, 0, 0)') supported by browser. | ||
* Currently there's no validation to the string, if the passed string is invalid, it won't take affect | ||
*/ | ||
export default function setBackgroundColor(editor: Editor, color: string) { | ||
color = color.trim(); | ||
applyInlineStyle(editor, element => (element.style.backgroundColor = color)); | ||
* Alternatively, you can pass a @typedef ModeIndepenentColor. If in light mode, the lightModeColor property will be used. | ||
* If in dark mode, the darkModeColor will be used and the lightModeColor will be set as the ogsc. | ||
**/ | ||
export default function setBackgroundColor(editor: Editor, color: string | ModeIndependentColor) { | ||
if (typeof color === 'string') { | ||
const trimmedColor = color.trim(); | ||
applyInlineStyle(editor, element => { element.style.backgroundColor = trimmedColor }); | ||
} else { | ||
const darkMode = editor.isDarkMode(); | ||
const appliedColor = darkMode ? color.darkModeColor : color.lightModeColor; | ||
applyInlineStyle(editor, (element) => { | ||
element.style.backgroundColor = appliedColor; | ||
if (darkMode) { | ||
element.dataset.ogsb = color.lightModeColor; | ||
} | ||
}); | ||
} | ||
|
||
Lego6245 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains 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,14 +1,30 @@ | ||
import applyInlineStyle from '../utils/applyInlineStyle'; | ||
import { Editor } from 'roosterjs-editor-core'; | ||
import { ModeIndependentColor } from 'roosterjs-editor-types'; | ||
|
||
/** | ||
* Set text color at selection | ||
* @param editor The editor instance | ||
* @param color The color string, can be any of the predefined color names (e.g, 'red') | ||
* @param color One of two options: | ||
* The color string, can be any of the predefined color names (e.g, 'red') | ||
* or hexadecimal color string (e.g, '#FF0000') or rgb value (e.g, 'rgb(255, 0, 0)') supported by browser. | ||
* Currently there's no validation to the string, if the passed string is invalid, it won't take affect | ||
* Alternatively, you can pass a @typedef ModeIndepenentColor. If in light mode, the lightModeColor property will be used. | ||
* If in dark mode, the darkModeColor will be used and the lightModeColor will be set as the ogsc. | ||
Lego6245 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
export default function setTextColor(editor: Editor, color: string) { | ||
color = color.trim(); | ||
applyInlineStyle(editor, element => (element.style.color = color)); | ||
export default function setTextColor(editor: Editor, color: string | ModeIndependentColor) { | ||
Lego6245 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (typeof color === 'string') { | ||
const trimmedColor = color.trim(); | ||
applyInlineStyle(editor, element => { element.style.color = trimmedColor }); | ||
} else { | ||
const darkMode = editor.isDarkMode(); | ||
const appliedColor = darkMode ? color.darkModeColor : color.lightModeColor; | ||
applyInlineStyle(editor, (element) => { | ||
element.style.color = appliedColor; | ||
if (darkMode) { | ||
element.dataset.ogsc = color.lightModeColor; | ||
} | ||
}); | ||
} | ||
|
||
Lego6245 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains 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 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 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 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 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 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 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 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,13 @@ | ||
import DarkModeOptions from '../interface/DarkModeOptions'; | ||
import DefaultFormat from '../interface/DefaultFormat'; | ||
|
||
export const DARK_MODE_DEFAULT_FORMAT = <DefaultFormat>{ | ||
Lego6245 marked this conversation as resolved.
Show resolved
Hide resolved
Lego6245 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
backgroundColor: 'rgb(51,51,51)', | ||
textColor: 'rgb(255,255,255)', | ||
originalSourceBackgroundColor: 'rgb(255,255,255)', | ||
originalSourceTextColor: 'rgb(0,0,0)', | ||
} | ||
|
||
export const DARK_MODE_DEFAULT_OPTIONS = <DarkModeOptions>{ | ||
defaultFormat: DARK_MODE_DEFAULT_FORMAT | ||
} |
Oops, something went wrong.
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.
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.
nit: setTextColor(editor, defaultFormat.textColors || defaultFormat.textColor);
(current way is also ok to me)