-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compact inline style
- Loading branch information
Showing
4 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 16 additions & 3 deletions
19
src/components/collaborative-editing/use-yjs/formats/collab-caret/CollabCaret.stories.tsx
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
16 changes: 16 additions & 0 deletions
16
src/components/collaborative-editing/use-yjs/formats/collab-caret/color-utils.js
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,16 @@ | ||
function getContrastYIQ( hexcolor ) { | ||
const r = parseInt( hexcolor.substr( 0, 2 ), 16 ); | ||
const g = parseInt( hexcolor.substr( 2, 2 ), 16 ); | ||
const b = parseInt( hexcolor.substr( 4, 2 ), 16 ); | ||
return ( r * 299 + g * 587 + b * 114 ) / 1000; | ||
} | ||
|
||
/** | ||
* Determine whether white text should be used on a given background color, based on YIQ contrast. | ||
* | ||
* @param {string} backgroundColorHex | ||
*/ | ||
export function shouldUseWhiteText( backgroundColorHex ) { | ||
const hex = backgroundColorHex.charAt( 0 ) === '#' ? backgroundColorHex.substr( 1 ) : backgroundColorHex; | ||
return getContrastYIQ( hex ) < 128; | ||
} |
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