Skip to content

Commit 2500e7d

Browse files
Remove redundant CSS variables from NavBar component
Following the hybrid CSS pattern from PLAIN_CSS_MIGRATION_GUIDE.md, removed CSS variables that were: - Set to hardcoded static values in JSX - Had identical fallback values in CSS - Not derived from theme.ts - Never changed at runtime Removed redundant variables: - --navbar-logo-height-desktop / --navbar-logo-height-mobile - --navbar-overlay-logo-top - --navbar-height-desktop / --navbar-height-mobile - --navbar-max-width Kept theme-derived variables (correct usage): - --navbar-z-index (from theme.zIndex.navbar) - --navbar-bg (from theme.color.neutral.base) - --navbar-padding-desktop/mobile (from theme.padding.page) - --nav-text-color (from theme.color.primary.gray.base) - --mobile-overlay-bg (computed with Color library) - --mobile-overlay-z-index (computed from theme) This makes the code cleaner and follows the migration guide's principle: "CSS variables should be used when values need to be looked up from theme.ts at runtime or require JavaScript computation" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f986d1f commit 2500e7d

2 files changed

Lines changed: 9 additions & 23 deletions

File tree

src/app/components/NavBar/NavBar.css

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
display: flex;
4040
justify-content: space-between;
4141
align-items: center;
42-
height: var(--navbar-height-desktop, 6rem);
43-
max-width: var(--navbar-max-width, 128rem);
42+
height: 6rem;
43+
max-width: 128rem;
4444
margin: 0 auto;
4545
}
4646

4747
@media screen and (max-width: 75em) {
4848
.navbar-topbar {
49-
height: var(--navbar-height-mobile, 5.2rem);
49+
height: 5.2rem;
5050
}
5151
}
5252

@@ -60,12 +60,12 @@
6060
.navbar-header-image {
6161
display: block;
6262
width: auto;
63-
height: var(--navbar-logo-height-desktop, 3.5rem);
63+
height: 3.5rem;
6464
}
6565

6666
@media screen and (max-width: 75em) {
6767
.navbar-header-image {
68-
height: var(--navbar-logo-height-mobile, 2.8rem);
68+
height: 2.8rem;
6969
}
7070
}
7171

@@ -165,10 +165,10 @@
165165
/* Overlay Logo */
166166
.navbar-overlay-logo {
167167
width: auto;
168-
height: var(--navbar-logo-height-mobile, 2.8rem);
168+
height: 2.8rem;
169169
position: absolute;
170170
left: 1.6rem;
171-
top: var(--navbar-overlay-logo-top, 1.2rem); /* (navMobileHeight - headerImageMobileHeight) / 2 = (5.2 - 2.8) / 2 = 1.2rem */
171+
top: 1.2rem; /* (navMobileHeight - headerImageMobileHeight) / 2 = (5.2 - 2.8) / 2 = 1.2rem */
172172
}
173173

174174
/* Overlay Heading */
@@ -224,8 +224,8 @@
224224
padding: 0;
225225
background: none;
226226
position: absolute;
227-
height: var(--navbar-height-mobile, 5.2rem);
228-
width: var(--navbar-height-mobile, 5.2rem);
227+
height: 5.2rem;
228+
width: 5.2rem;
229229
top: 0;
230230
right: 0;
231231
color: var(--nav-text-color, #5f6163);

src/app/components/NavBar/index.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ export const MobileDropdown: FunctionComponent<{
6666
src={openstaxLogo}
6767
alt={intl.formatMessage({ id: 'i18n:nav:logo:alt' })}
6868
className="navbar-overlay-logo"
69-
style={{
70-
'--navbar-logo-height-mobile': '2.8rem',
71-
'--navbar-overlay-logo-top': '1.2rem',
72-
} as React.CSSProperties}
7369
/>
7470
</a>
7571
<button
@@ -78,7 +74,6 @@ export const MobileDropdown: FunctionComponent<{
7874
onClick={() => onOpenChange(false)}
7975
className="navbar-times-icon"
8076
style={{
81-
'--navbar-height-mobile': '5.2rem',
8277
'--nav-text-color': theme.color.primary.gray.base,
8378
} as React.CSSProperties}
8479
>
@@ -283,11 +278,6 @@ const NavigationBar = ({user, loggedOut, currentPath, hasUnsavedHighlight, param
283278
<div
284279
className="navbar-topbar"
285280
data-testid='navbar'
286-
style={{
287-
'--navbar-height-desktop': '6rem',
288-
'--navbar-height-mobile': '5.2rem',
289-
'--navbar-max-width': '128rem',
290-
} as React.CSSProperties}
291281
>
292282
<a
293283
href={logoUrl}
@@ -297,10 +287,6 @@ const NavigationBar = ({user, loggedOut, currentPath, hasUnsavedHighlight, param
297287
src={openstaxLogo}
298288
alt={intl.formatMessage({id: 'i18n:nav:logo:alt'})}
299289
className="navbar-header-image"
300-
style={{
301-
'--navbar-logo-height-desktop': '3.5rem',
302-
'--navbar-logo-height-mobile': '2.8rem',
303-
} as React.CSSProperties}
304290
/>
305291
</a>
306292
{loggedOut && <LoggedOutState currentPath={currentPath} />}

0 commit comments

Comments
 (0)