Skip to content

Commit

Permalink
fix: better contrast in note text
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfran committed Jan 8, 2025
1 parent bf11ab9 commit 1302424
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 3 additions & 6 deletions libs/nodes/src/lib/note/note.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

.name {
bottom: 0.5rem;
color: var(--orange);
font-size: 1.125rem;
height: 1.75rem;
left: 1rem;
Expand Down Expand Up @@ -176,14 +175,12 @@ textarea {
height: var(--emoji-height);
}

.name,
.characters {
color: var(--black);
.name{
color: var(--contrast-color);
}

.vote,
.name,
.characters {
.name {
pointer-events: none;
z-index: 1;
}
Expand Down
16 changes: 11 additions & 5 deletions libs/nodes/src/lib/note/note.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { defaultNoteColor } from '.';
'[style.--custom-fg]': '"#000"',
'[style.--custom-light]': 'lightColor()',
'[style.--custom-main]': 'color()',
'[style.--contrast-color]': 'contrastColor()',
'[style.transform]': '"rotate(" + this.rotation() + "deg)"',
'[style.--rotate-angle]': 'rotateAngle()',
},
Expand Down Expand Up @@ -91,21 +92,26 @@ export class NoteComponent {
width = computed(() => {
return this.node().content.width;
});
bgColor = computed(() => {
return this.node().content.color ?? defaultNoteColor;
});

rotation = signal(0);
rotateAngle = signal('0deg');
contrast = computed(() => {
return contrast(this.bgColor(), '#ffffff');
});
contrastColor = computed(() => {
return this.contrast() > 2 ? '#ffffff' : '#000000';
});

defaultTextColor = computed(() => {
// if the note has text, the color is by the current text color
if (this.node().content.text.length) {
return null;
}

const color = this.node().content.color ?? defaultNoteColor;

const contrastColor = contrast(color, '#ffffff');

return contrastColor > 2 ? '#ffffff' : '#000000';
return this.contrast() > 2 ? '#ffffff' : '#000000';
});

generateRandomRotation() {
Expand Down

0 comments on commit 1302424

Please sign in to comment.