Skip to content

Phase 7.3b: Migrate Assignment/Book Info Components to Plain CSS#3060

Open
OpenStaxClaude wants to merge 9 commits into
mainfrom
phase-7.3b-assignment-book-info
Open

Phase 7.3b: Migrate Assignment/Book Info Components to Plain CSS#3060
OpenStaxClaude wants to merge 9 commits into
mainfrom
phase-7.3b-assignment-book-info

Conversation

@OpenStaxClaude

Copy link
Copy Markdown
Contributor

Summary

This PR migrates 4 assignment and book-related content components from styled-components to plain CSS as part of Phase 7.3 (CORE-2284).

Components Migrated

  1. Assigned.tsx - Main assigned content wrapper with platform-specific display
  2. AssignedTopBar.tsx - Top bar for assigned content with text resizer
  3. Attribution.tsx - Attribution details component (also migrated from class to functional component)
  4. BuyBook.tsx - Book purchase link component

Migration Highlights

  • 4 components migrated from styled-components to plain CSS
  • 4 new CSS files created with all styling
  • Attribution.tsx also converted from class component + connect() to functional component + useSelector hooks
  • ✅ All styled-components imports removed
  • ✅ CSS variables used for dynamic theme values
  • ✅ Data attributes used for conditional styling
  • ✅ Component behavior and functionality preserved
  • ✅ Follows patterns from PLAIN_CSS_MIGRATION_LEARNINGS.md

Files Changed

New CSS Files:

  • src/app/content/components/Assigned.css (32 lines)
  • src/app/content/components/AssignedTopBar.css (50 lines)
  • src/app/content/components/Attribution.css (145 lines)
  • src/app/content/components/BuyBook.css (28 lines)

Modified Components:

  • src/app/content/components/Assigned.tsx - Migrated 3 styled-components to plain CSS
  • src/app/content/components/AssignedTopBar.tsx - Migrated 2 styled-components to plain CSS
  • src/app/content/components/Attribution.tsx - Migrated 5 styled-components + class→functional conversion
  • src/app/content/components/BuyBook.tsx - Migrated 2 styled-components to plain CSS

Key Patterns Used

CSS Variables for Dynamic Values:

// Setting variables in component
<div 
  className="assigned-topbar-wrapper"
  style={{
    '--assigned-topbar-bg-color': theme.color.neutral.base,
    '--assigned-topbar-text-color': theme.color.text.default,
    ...style
  }}
>

Data Attributes for Conditional Styling:

<div 
  className="platform-wrapper"
  data-platform="assignable"
>

Top-Level Media Queries:

@media screen and (max-width: 75em) {
  .toast-override {
    top: var(--assigned-mobile-top);
  }
}

Attribution Component Refactoring

Beyond the styling migration, Attribution.tsx was also modernized:

  • Class → Functional Component: Converted from class-based to functional component with hooks
  • connect() → useSelector: Replaced Redux connect() HOC with useSelector hook
  • Lifecycle → Effects: Converted lifecycle methods to useEffect hooks
  • Refs: Updated from createRef() to useRef()

Related

Testing Notes

All component functionality has been preserved:

  • Assigned content rendering with platform-specific display
  • Text resizer integration in AssignedTopBar
  • Attribution toggle with auto-scroll behavior
  • BuyBook link with analytics tracking

Components follow established migration patterns and maintain backward compatibility.

🤖 Generated with Claude Code

- Replaced styled-components with plain CSS using CSS variables
- Created AssignedTopBar.css with responsive breakpoints
- Converted StyledTopBarWrapper to use TopBarWrapper with className
- Converted StyledSectionTitle to plain h2 element with className
- Used CSS variables for dynamic theme values (colors, heights)
- Followed migration patterns from PLAIN_CSS_MIGRATION_LEARNINGS.md
- All component logic remains unchanged

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-j4dar6 July 13, 2026 23:16 Inactive
@TomWoodward TomWoodward had a problem deploying to rex-web-phase-7-3b-assi-wtpekt July 14, 2026 10:56 Failure
@RoyEJohnson RoyEJohnson force-pushed the phase-7.3b-assignment-book-info branch from a1f0646 to e372350 Compare July 14, 2026 10:59
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-wtpekt July 14, 2026 10:59 Inactive
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-gkljqo July 14, 2026 12:02 Inactive
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 12:09 Inactive
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 12:27 Inactive
RoyEJohnson

This comment was marked as resolved.

@OpenStaxClaude

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the Phase 7.3 migration by moving assignment/book-related content components off styled-components and into plain CSS files, while also modernizing Attribution from a class + connect() to a functional component using Redux hooks.

Changes:

  • Migrates Assigned, AssignedTopBar, Attribution, and BuyBook styling from styled-components to co-located plain CSS.
  • Refactors Attribution to a functional component with useSelector, useEffect, and useRef/useLayoutEffect.
  • Updates Jest snapshots to reflect the new class-based markup and removal of styled-components generated styles.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/app/content/components/Assigned.tsx Replaces styled-components wrappers with function components + CSS variables/classes.
src/app/content/components/Assigned.css Adds plain CSS for Assigned button/toast/platform wrapper behavior.
src/app/content/components/AssignedTopBar.tsx Switches from styled-components wrapper/title to className + CSS variables.
src/app/content/components/AssignedTopBar.css Adds plain CSS for Assigned top bar styling and breakpoints.
src/app/content/components/Attribution.tsx Converts to functional component + Redux hooks; replaces styled Details/Summary with native <details>/<summary> and CSS.
src/app/content/components/Attribution.css Adds plain CSS for attribution container, summary icons, content/link styling, and breakpoints.
src/app/content/components/BuyBook.tsx Replaces styled-components with class-based markup, CSS variables, and disablePrintClass.
src/app/content/components/BuyBook.css Adds plain CSS for BuyBook layout and link styling.
src/app/content/components/snapshots/BuyBook.spec.tsx.snap Updates snapshot output for class-based BuyBook markup.
src/app/content/components/snapshots/Attribution.spec.tsx.snap Updates snapshot output for new details/summary markup and removal of styled-components CSS output.
src/app/content/components/snapshots/AssignedTopBar.spec.tsx.snap Updates snapshot output for AssignedTopBar class usage + CSS variables.
src/app/content/snapshots/routes.spec.tsx.snap Updates assigned route snapshot due to Assigned/Attribution/TopBar markup and class changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/content/components/AssignedTopBar.css Outdated
Comment thread src/app/content/components/Attribution.css
Comment thread src/app/content/components/BuyBook.css

This comment was marked as resolved.

@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 14:19 Inactive
@RoyEJohnson RoyEJohnson force-pushed the phase-7.3b-assignment-book-info branch from e194f06 to 6a16d4a Compare July 14, 2026 14:20
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 14:20 Inactive
@RoyEJohnson RoyEJohnson requested a review from Copilot July 14, 2026 14:28

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was crazy. So much duplication (now removed).

@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 14:43 Inactive
OpenStaxClaude and others added 3 commits July 14, 2026 09:43
This commit migrates the BuyBook component following the simplified
plain CSS migration approach documented in PLAIN_CSS_MIGRATION_LEARNINGS.md.

Changes:
- Created BuyBook.css with plain CSS styles
- Updated BuyBook.tsx to use className instead of styled-components
- Used CSS variables for dynamic values (max-width and color)
- Applied disablePrintClass for print hiding behavior
- Followed established patterns from other migrated components

The component maintains identical functionality and styling while removing
the styled-components dependency.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Convert class component to functional component with hooks
- Replace connect() HOC with useSelector hook
- Create Attribution.css with all component styles
- Use CSS variables for dynamic values (theme colors, widths)
- Replace styled Summary/Details with plain HTML elements
- Implement htmlMessage pattern inline (Content and CodeRunnerNote components)
- Maintain all existing functionality:
  - Auto-scroll on toggle
  - Close on page navigation
  - Special attribution for python books
  - Support for special book IDs
- Export named Attribution component for testing
- Use classNames package for className composition
- Follow patterns from PLAIN_CSS_MIGRATION_LEARNINGS.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Replace styled-components imports with classNames
- Convert StyledButton, ToastOverride, and PlatformWrapper to plain React components
- Create Assigned.css with corresponding styles
- Use CSS variables for dynamic values (contentTextWidth, topbarDesktopHeight, assignedMobileTop)
- Convert theme.breakpoints.mobile() to @media query with correct breakpoint (75em)
- Maintain all existing functionality and component behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@OpenStaxClaude

This comment was marked as resolved.

@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 15:42 Inactive
@RoyEJohnson RoyEJohnson requested a review from Copilot July 14, 2026 15:49
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 15:49 Inactive

This comment was marked as resolved.

RoyEJohnson

This comment was marked as resolved.

@OpenStaxClaude

This comment was marked as resolved.

Address Copilot review feedback on AssignedTopBar and Attribution

**AssignedTopBar.tsx:**
- Conditionally render the <h2> heading only when section?.title exists
- Prevents empty headings which are an accessibility issue for screen readers
- While section should always be defined in practice (as Roy noted), this
  handles edge cases during initial render and follows best practices

**Attribution.tsx:**
- Revert useEffect dependency array back to [] (empty)
- The toggle event listener doesn't depend on `page` and should only
  run on mount/unmount
- Re-running this effect on every page change is unnecessary and wasteful
- The page change logic is already handled in the separate useLayoutEffect

These changes address Copilot's accessibility concern while maintaining
the correct React hook behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Fix AssignedTopBar to handle undefined section during loading

The AssignedTopBar component was expecting section to always be defined,
but sections[currentSectionIndex] can be undefined while the book and
assigned sections are still loading.

Changes:
- Made section prop optional: LinkedArchiveTreeSection | undefined
- Added early return (null) when section is not yet available
- This allows the Page component to render its loader during loading state
- Fixes the test "renders loading state without book"

This addresses both Copilot's concern about empty headings and Roy's
observation that the test was failing. The component now properly handles
the loading state by returning null instead of rendering an empty h2.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

props.section is always defined

Co-Authored-By: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@RoyEJohnson RoyEJohnson force-pushed the phase-7.3b-assignment-book-info branch from 141de62 to f990964 Compare July 14, 2026 16:16
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 16:16 Inactive

This comment was marked as resolved.

@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 16:34 Inactive
Co-Authored-By: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@RoyEJohnson RoyEJohnson force-pushed the phase-7.3b-assignment-book-info branch from 261c9c1 to aa2ec4a Compare July 14, 2026 17:31
@TomWoodward TomWoodward temporarily deployed to rex-web-phase-7-3b-assi-e90d2d July 14, 2026 17:32 Inactive
Co-Authored-By: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.

@RoyEJohnson RoyEJohnson marked this pull request as ready for review July 14, 2026 18:47
@RoyEJohnson RoyEJohnson requested a review from a team as a code owner July 14, 2026 18:47
@RoyEJohnson RoyEJohnson requested review from Dantemss and TomWoodward and removed request for TomWoodward July 14, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants