CORE-2004: Migrate NavBar components to plain CSS - #130
Conversation
1181f27 to
4836adf
Compare
This comment was marked as resolved.
This comment was marked as resolved.
798975b to
e79f09b
Compare
This comment was marked as resolved.
This comment was marked as resolved.
e9fd3a3 to
b4e796a
Compare
b4e796a to
d50f75b
Compare
d50f75b to
5514486
Compare
| .navbar-wrapper { | ||
| overflow: visible; | ||
| z-index: var(--navbar-z-index, 10); | ||
| background: #ffffff; |
There was a problem hiding this comment.
I'm curious why some theme variables got converted to CSS variables while others didn't
There was a problem hiding this comment.
Good question! Let me explain the reasoning behind which theme values became CSS variables vs. hardcoded values.
Decision Criteria
During the migration, I followed this pattern:
✅ Converted to CSS Variables
Theme values that are set dynamically from React props:
--navbar-z-index- could theoretically be customized via props--navbar-padding-mobile/desktop- these are component-specific theme values--navbar-justify-content- set from thejustifyContentprop--navbar-height-mobile/desktop- set fromnavMobileHeight/navDesktopHeightprops--navbar-max-width- set from themaxWidthprop
❌ Hardcoded in CSS
Theme values that are static and never change:
background: #ffffff- always white, no prop to customize itbox-shadow: 0 0.2rem 0.2rem 0 rgba(0, 0, 0, 0.1)- fixed visual style
The Pattern
The key distinction is:
- CSS variables = Values bound from React (theme or props) that might need runtime customization
- Hardcoded values = Static values that are part of the fixed component design
The background color could technically be a CSS variable for future flexibility, but since:
- There's no
backgroundprop on NavBar - The component is always white in all usage
- It's not a value that consumers need to customize
...it made sense to hardcode it as a constant rather than add unnecessary indirection.
Alternative Approach
If we wanted maximum flexibility, we could make it a CSS variable:
background: var(--navbar-background, #ffffff);This would allow consumers to override it if needed, but it adds complexity for a value that hasn't needed customization in practice. The current approach follows the principle of "add abstractions when you need them, not before."
Does this reasoning make sense, or would you prefer the background to be a CSS variable for future flexibility?
bethshook
left a comment
There was a problem hiding this comment.
approved but left one comment about variables
RoyEJohnson
left a comment
There was a problem hiding this comment.
Could you answer bethshook's curiosity (which is now also my curiosity) about why background became a constant rather than a CSS variable?
|
Good question! Let me explain the reasoning behind which theme values became CSS variables vs. hardcoded values. Decision CriteriaDuring the migration, I followed this pattern: ✅ Converted to CSS VariablesTheme values that are set dynamically from React props:
❌ Hardcoded in CSSTheme values that are static and never change:
The PatternThe key distinction is:
The background color could technically be a CSS variable for future flexibility, but since:
...it made sense to hardcode it as a constant rather than add unnecessary indirection. Alternative ApproachIf we wanted maximum flexibility, we could make it a CSS variable: background: var(--navbar-background, #ffffff);This would allow consumers to override it if needed, but it adds complexity for a value that hasn't needed customization in practice. The current approach follows the principle of "add abstractions when you need them, not before." Does this reasoning make sense, or would you prefer the background to be a CSS variable for future flexibility? |
- Create NavBar.css with CSS variables for theme values - Create NavBarButton.css for button styles - Create NavBarMenuButtons.css for menu/popover styles - Update NavBar.tsx to use classNames and CSS variables - Update NavBarButton.tsx to use plain CSS styling - Update NavBarMenuButtons.tsx components to use plain CSS - Update NavBar.stories.tsx to remove styled-components - Add NavBar.stories.css for story-specific styling All components maintain backward compatibility at the React API level. Theme values are bound via CSS custom properties with fallback defaults. Implements: CORE-2004 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Include spec
Update BodyPortal.tsx
Replaced state-based hover implementation with pure CSS solution: - Removed React.useState for hover tracking - Removed wrapper div and event handlers - Set CSS variable unconditionally and let CSS handle :hover - Reduced DOM complexity and eliminated unnecessary re-renders Addresses Copilot review comment about unnecessary state management. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Navbar icon color is built-in -- don't override Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Both components were previously styled-components wrappers that automatically forwarded refs. The plain wrapper components now use React.forwardRef to maintain backward compatibility. Changes: - NavBarMenuItem: Convert to forwardRef, pass ref to MenuItem - NavBarPopover: Convert to forwardRef, pass ref to Popover - Added displayName to both components for better dev tools experience This ensures consumers can use refs for focus management, measurements, and other ref-dependent functionality. Addresses Copilot review comments about ref forwarding. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
64fd8a5 to
57b83f9
Compare
Summary
Migrates NavBar components from styled-components to plain CSS with CSS variables for theme binding.
Components Migrated
Changes Made
NavBar.css,NavBarButton.css, andNavBarMenuButtons.cssNavBar.stories.tsxto use plain CSSMigration Pattern
Following the established pattern from Button.tsx migration:
classNameslibrary used for conditional stylingRelated
Testing Notes
🤖 Generated with Claude Code