-
Notifications
You must be signed in to change notification settings - Fork 3
ENG-836 make button like css for node tag #443
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
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughReplaces prior simple tag-color assignment with a new color-theming flow using Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Node as DiscourseNode
participant Util as getPleasingColors
participant Popup as TagPopupRenderer
Node->>Util: provide node.canvasSettings.color (hex / formatted)
note right of Util #D6F5D6: compute pleasing color scheme\n(primary, background, text, border, contrast)
Util-->>Node: PleasingColorScheme
Node->>Popup: render tag popup with inline styles (background, color, border, ...)
Popup-->>Node: UI updated
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/roam/src/utils/initializeObserversAndListeners.ts(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Graphite / mergeability_check
- GitHub Check: Graphite / mergeability_check
- GitHub Check: Graphite / mergeability_check
- GitHub Check: Graphite / mergeability_check
e4d5c93 to
9a87a36
Compare
c08ba49 to
006d860
Compare
006d860 to
5be0c75
Compare
5be0c75 to
cc93d09
Compare
mdroidian
left a comment
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.
I think many colors will still fail using this.
Try the contrast-color package (we use it in DiscourseNodeUtil) or a package like it to generate the corresponding background that is WCAG compliant.
Make sure to test them with https://webaim.org/resources/contrastchecker/
cc93d09 to
20aac2b
Compare
mdroidian
left a comment
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.
While this does look good on our discourse-graphs graph
The default shipped node colors turn out to be mostly black or white backgrounds :(
Can you think of any tweaks we could make so that these are compliant colored backgrounds?
If not, a couple other options could be
- manually set the foreground/background for the default shipped nodes (not ideal)
- change the default shipped colors (also not ideal)
Swap the main color
Another idea would be to use the node color (the color that is set in the node setting) as the background color instead of the text color. Then calculate the text color based on that.
That way the fallback would be that the text color is black or white, not the background color. This would be much cleaner than a bunch of black/white background tags.
I think we should do both:
- swap the main color to be background instead of text
- test
discourse-graphsand the default shipped node colors and aim for 75% to not be black/white
Let me know what you think
|
@mdroidian can we change the default text color? this is what the colors look like (in
and in default plugin
|
This looks better. Have you tried tweaking the algorithm at all? |
|
no the tweak we can do is make the steps smaller, currently we use By steps I mean if we don't find a contrasting color then either lighten or darken the current color by |
mdroidian
left a comment
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.
Looks like this PR needs a rebase and the new "pleasing" algorithm, is that correct @sid597 ?
2ee1869 to
3906aa6
Compare
|
@mdroidian now using the pleasing algorithm but there are lint issues related to colord |
|
@mdroidian I did not rename the function or removed the comments from the pleasing algorithm file I think for this case the all comments make sense. |
mdroidian
left a comment
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.
Just move colord to apps/roam and packages/util and remove contrast-color then good to go! 👍
|
Actually let's run the pleasing algo through code rabbit too. @coderabbitai full review |
|
@mdroidian: I'll trigger a full review of the PR, paying special attention to the pleasing algorithm implementation and the colord integration. The review will cover the color contrast logic, TypeScript type safety issues, and the overall implementation. ✅ Actions performedFull review triggered. |
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.
Actionable comments posted: 1
♻️ Duplicate comments (2)
apps/roam/src/utils/initializeObserversAndListeners.ts (1)
122-143: Prefer CSS variables + class pattern to avoid style thrashing.The inline style application remains unaddressed from previous reviews. Repeatedly applying inline styles on observer callbacks can cause style thrashing and complicates theming. The suggested CSS variable pattern from prior reviews would make this more maintainable and performant.
Consider applying the previously suggested pattern:
if (node.canvasSettings?.color) { const formattedColor = formatHexColor(node.canvasSettings.color); if (!formattedColor) { break; } const contrastingColor = getPleasingColors( colord(formattedColor), ); - Object.assign(s.style, { - backgroundColor: contrastingColor.background, - color: contrastingColor.text, - border: `1px solid ${contrastingColor.border}`, - fontWeight: "500", - padding: "2px 6px", - borderRadius: "12px", - margin: "0 2px", - fontSize: "0.9em", - whiteSpace: "nowrap", - boxShadow: "0 1px 2px rgba(0, 0, 0, 0.05)", - display: "inline-block", - cursor: "pointer", - }); + if (s.dataset.dgTagStyled !== "1") { + s.dataset.dgTagStyled = "1"; + s.classList.add("dg-node-tag-btn"); + } + s.style.setProperty("--dg-tag-bg", contrastingColor.background); + s.style.setProperty("--dg-tag-fg", contrastingColor.text); + s.style.setProperty("--dg-tag-border", contrastingColor.border); }Then add corresponding CSS to your stylesheet:
.dg-node-tag-btn { background-color: var(--dg-tag-bg); color: var(--dg-tag-fg); border: 1px solid var(--dg-tag-border); font-weight: 500; padding: 2px 6px; border-radius: 12px; margin: 0 2px; font-size: 0.9em; white-space: nowrap; box-shadow: 0 1px 2px rgba(0,0,0,0.05); display: inline-block; cursor: pointer; }package.json (1)
33-34: Movecolordto workspace-specific dependencies.Adding
colordto the rootpackage.jsonviolates the turbo convention mentioned in previous reviews. Sincecolordis only used inapps/roamandpackages/utils, add it to those specific package.json files instead.Based on learnings.
Apply this change:
- Remove
colordfrom rootpackage.json- Add to
apps/roam/package.json:"dependencies": { "colord": "^2.9.3" }
- Add to
packages/utils/package.json:"dependencies": { "colord": "^2.9.3" }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx(3 hunks)apps/roam/src/utils/initializeObserversAndListeners.ts(2 hunks)package.json(1 hunks)packages/utils/src/getPleasingColors.ts(1 hunks)
🔇 Additional comments (4)
apps/roam/src/utils/initializeObserversAndListeners.ts (1)
53-54: LGTM! Proper integration of color utilities.The imports of
getPleasingColorsandcolordare correct and enable the new WCAG-compliant color theming flow.apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (2)
34-34: LGTM! Proper imports for the new color utility.The imports of
colordandgetPleasingColorsare correctly placed and support the refactored color calculation flow.Also applies to: 47-47
352-361: LGTM! Clean refactor to use accessible color algorithm.The
getColors()method now properly:
- Formats and validates the color input
- Falls back to palette color when needed
- Derives accessible background and text colors via
getPleasingColorsThis is a significant improvement over the previous approach.
packages/utils/src/getPleasingColors.ts (1)
1-191: Validate getPleasingColors on edge-case colors for WCAG compliance.Manually test locally with these inputs:
Bright Yellow (#ffff00), Bright Cyan (#00ffff), Very Dark Blue (#33), Pure Black (#000000), Pure White (#ffffff), Mid Gray (#808080), Saturated Red (#ff0000).
Ensure returned background/text colors meet at least AA (4.5:1) and AAA (7:1) thresholds.
71f75d1 to
1f4b964
Compare
|
cc @mdroidian merging |



Summary by CodeRabbit