generated from haydenull/logseq-plugin-react-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Optimize the experience of setting colors
- Loading branch information
Showing
3 changed files
with
60 additions
and
5 deletions.
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
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,15 @@ | ||
const getTextColor = (bgColor: number[]) => { | ||
// 当color值大于128时,color值偏向255,即#ffffff,此时字体颜色应为#333333 | ||
// 当color值小于128时,color值偏向0,即#000000,此时字体颜色应为#ffffff | ||
const isWhiteBg = 0.213 * bgColor[0] + 0.715 * bgColor[1] + 0.072 * bgColor[2] > 255 / 2; | ||
return isWhiteBg ? '#333333': '#ffffff' | ||
} | ||
|
||
/** | ||
* get text color base on background color | ||
* @param rbgColor rgba(11, 22, 33, 1) | ||
*/ | ||
export const autoTextColor = (rbgColor: string) => { | ||
const [red, green, blue, alpha] = rbgColor.replace(/(?:\(|\)|rgba)*/g, "").split(",") | ||
return getTextColor([Number(red), Number(green), Number(blue)]) | ||
} |
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