Repository navigation
refactor(web): move styles into per-component CSS modules - #211
Merged
Merged
Conversation
Every component's styles now live in a CSS module beside it, with exact types generated by typed-css-modules, so a misspelt class fails the typecheck. A look used in more than one place is a shared component that owns its whole look and takes variants as data-* attributes, rather than a class several components share. styles.css keeps only what is global. Settings moves into pages/settings/, and Storybook is set up with stories for the components and screens.
There was a problem hiding this comment.
Triage requests changes:
- CI green: required checks are failing
e2e
- Conventions: added code matches a code pattern
apps/web/src/App.tsx:874-907 nested-ternary: Nested ternary; use if statements or a lookup.apps/web/src/App.tsx:875-906 nested-ternary: Nested ternary; use if statements or a lookup.apps/web/src/pages/project-library.tsx:176 empty-list-fallback: Invented fallback `?? []`; handle the missing value instead.apps/web/src/pages/settings/settings-row.tsx:17-23 nested-ternary: Nested ternary; use if statements or a lookup.
A root bunfig preload that registered a Bun plugin stopped the hub's macros from running in the shared test process. Tests find elements by data-* attributes, so they no longer need class names in markup. Also replace nested ternaries and an invented empty-list fallback that the move touched.
|
Merged before Triage finished on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSS styling refactor, part 1 of 2
Why
Humans and agents should be able to move fast an reason about visual components and behaviors easily. In my attempt to create a simple storybook based flow for that, I encountered a big spaghetti of intertwined styles, styles that depend on a component being in a specific different component and a general lack of encapsulation.
We drifted this way because we had inertia from how styles were handled in
react-ui, which is supposed to introduce far less styling opinion because it could be used by outside organizations for their AI user interfaces, and we don't want to dictate how they should reason about styles.However, Corbits Builder is a much more complex application, and isn't a library, so the same constraints don't apply.
This PR makes the first crucial step to a first iteration workflow on visuals:
Encapsulating CSS for components and preventing cross-talk by using CSS modules, and creating a space for rapid visual iteration within Storybook.
The next PR will focus on extending what is true for components in this PR to entire pages by decoupling state, networking and logic from visuals - extending the ability to rapidly iterate on visuals without them being intertwined with logic, state and networking.
What changed
*.module.cssbeside it.styles.csskeeps only what is global: fonts, tokens, element defaults, library-wide overrides and shared keyframes. Dead global rules are removed.typed-css-modulesgenerates a gitignored.d.tsper module, sostyles.xis astringand a misspelt class fails the typecheck.typecheckregenerates them first, anddevkeeps them current with a watcher.clsxjoins conditional classes.Banner/BannerAction,InlineNote,Fault,Field,QuietState,QuietButton/QuietSelect,DangerMenuItem,MenuItemLabel,Composer,StageView,Sketching,SourceLinkand the approval fields each own their whole look. They take noclassName; variants aredata-*attributes, and every root carriesdata-slot, which parents use only to position it.WorkspaceFaultbecameFault,ProviderFieldbecameField,StatusTextbecameQuietState, and theQUIET_CONTROLclass became components.pages/settings/.apps/web/AGENTS.md, with a test that fails on a plain.cssfile or an unused module class.bun run --cwd apps/web storybook), with stories for components and screens.Visible changes
Sectionheading (about 7px taller).How it was verified
main. They match apart from the changes above and invisible differences (zero-width borders, padding swapped for margin over the same box).bun run typecheck,lint,format:check,pins:verify,vendor:verifyandbun test ./apps/web/src(136 pass).