-
Notifications
You must be signed in to change notification settings - Fork 364
[ColorSync] Convert label-image widget to CSS Modules #3444
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
Draft
Myranae
wants to merge
10
commits into
tb/testing-font-color-conversion
Choose a base branch
from
tb/stacked-css-module-conversion
base: tb/testing-font-color-conversion
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cf35324
[tb/stacked-css-module-conversion] Bring in the new script
Myranae 0e6cfdc
[tb/stacked-css-module-conversion] First pass of conversion script
Myranae 29eceb4
[tb/stacked-css-module-conversion] Clean up after conversion
Myranae 8ddabc2
[tb/stacked-css-module-conversion] docs(changeset): Converted label-i…
Myranae b6bf033
[tb/stacked-css-module-conversion] Add in the progress report for ref…
Myranae c49b50b
[tb/stacked-css-module-conversion] Prettier fixes
Myranae f8b301a
[tb/stacked-css-module-conversion] Merge branch 'tb/testing-font-colo…
Myranae 7b37fcf
[tb/stacked-css-module-conversion] Switch to pull from legacy style a…
Myranae 7a45d01
[tb/stacked-css-module-conversion] Remove extension for lint
Myranae ff8580e
[tb/stacked-css-module-conversion] Update imports
Myranae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@khanacademy/perseus": patch | ||
| --- | ||
|
|
||
| Converted label-image widget Aphrodite styles to CSS modules across answer-pill, hide-answers-toggle, marker, and label-image. |
119 changes: 119 additions & 0 deletions
119
.claude/plans/label-image-css-modules-progress-report-2.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Label Image Widget — CSS Modules Progress Report 2 | ||
|
|
||
| Co-Authored-By: Claude Sonnet 4.6 <[email protected]> | ||
|
|
||
| --- | ||
|
|
||
| ## Step 1 — CSS Module Conversion | ||
|
|
||
| ### Files identified for conversion (StyleSheet.create usage) | ||
|
|
||
| - `packages/perseus/src/widgets/label-image/marker.tsx` | ||
| - `packages/perseus/src/widgets/label-image/hide-answers-toggle.tsx` | ||
| - `packages/perseus/src/widgets/label-image/label-image.tsx` | ||
| - `packages/perseus/src/widgets/label-image/answer-pill.tsx` | ||
| - `packages/perseus/src/widgets/label-image/__stories__/marker.stories.tsx` | ||
|
|
||
| ### Conversion Results | ||
|
|
||
| #### answer-pill.tsx | ||
| - Command: `pnpm extract-css packages/perseus/src/widgets/label-image/answer-pill.tsx --keep-aphrodite` | ||
| - Output: `answer-pill.module.css`, `answer-pill_legacy-styles.js` | ||
| - TODOs: None | ||
| - Issues: None | ||
|
|
||
| #### hide-answers-toggle.tsx | ||
| - Command: `pnpm extract-css packages/perseus/src/widgets/label-image/hide-answers-toggle.tsx --keep-aphrodite` | ||
| - Output: `hide-answers-toggle.module.css`, `hide-answers-toggle_legacy-styles.js` | ||
| - TODOs: None | ||
| - Issues: None | ||
|
|
||
| #### marker.tsx | ||
| - Command: `pnpm extract-css packages/perseus/src/widgets/label-image/marker.tsx --keep-aphrodite` | ||
| - Output: `marker.module.css`, `marker_legacy-styles.js` | ||
| - TODOs: None | ||
| - Manual fixes required (same as run 1 — these are fundamental script limitations for dynamic values): | ||
| 1. `margin-left` and `margin-top` were unresolvable binary expressions (`MARKER_SIZE / -2`). Resolved to `-1.2rem`. Also added to `marker_legacy-styles.js`. | ||
| 2. Aphrodite `animationName` inline keyframes emitted as invalid class names. Replaced with a proper `@keyframes marker-pulsate` block and added `animation-name: marker-pulsate` to `.marker-pulsate-base`. | ||
|
|
||
| #### label-image.tsx | ||
| - Command: `pnpm extract-css packages/perseus/src/widgets/label-image/label-image.tsx --keep-aphrodite` | ||
| - Output: `label-image.module.css`, `label-image_legacy-styles.js` | ||
| - Script ran successfully (updated script fixed the `satisfies` expression crash) | ||
| - TODOs: None | ||
| - Manual fix required: `.instructions-caption` received spread properties from `bodyXsmallBold` in camelCase JS format (`fontFamily`, `fontSize`, etc.) instead of CSS kebab-case. Corrected to `font-family`, `font-size` (with `px` unit), `font-weight`, `line-height`. | ||
|
|
||
| #### __stories__/marker.stories.tsx | ||
| - Command: `pnpm extract-css packages/perseus/src/widgets/label-image/__stories__/marker.stories.tsx --keep-aphrodite` | ||
| - Output: `__stories__/marker.module.css`, `__stories__/marker_legacy-styles.js` | ||
| - TODOs: None | ||
| - Issues: None | ||
|
|
||
| --- | ||
|
|
||
| ## Step 2 — Pre-Push Quality Checks | ||
|
|
||
| ### `pnpm lint` | ||
| - Result: PASS (0 errors, 0 warnings) | ||
| - Issues fixed: | ||
| - All files: removed unused `stylesLegacy` imports and `.js` extensions; moved CSS module imports to correct position after relative imports. | ||
| - `marker.tsx`: removed unused `boxShadow` import. | ||
| - `label-image.tsx`: removed unused `semanticColor`, `bodyXsmallBold` imports; replaced all `css(styles.xxx)` calls with `styles.xxx` / `classNames(...)`. | ||
| - `answer-pill.tsx`: replaced `CSSProperties` (from removed aphrodite import) with `React.CSSProperties`. | ||
| - `marker.stories.tsx`: replaced `css(styles.wrapper)` with `styles.wrapper`. | ||
|
|
||
| ### `pnpm tsc` | ||
| - Result: PASS (no output) | ||
|
|
||
| ### `pnpm test` | ||
| - Result: PASS | ||
| - Test Suites: 472 passed, 472 total | ||
| - Tests: 6441 passed, 36 skipped, 6477 total | ||
|
|
||
| --- | ||
|
|
||
| ## Step 3 — Deviation Check | ||
|
|
||
| ### Pre-workflow — Progress Report Creation | ||
| - **Followed as instructed:** Partially | ||
| - **Deviations:** Filename is `label-image-css-modules-progress-report-2.md` instead of the required `label-image-css-modules-progress-report.md`. The `-2` suffix was added to preserve the first run as historical context. | ||
| - **Type:** Intentional — user requested. | ||
| - **Recommended Action:** No action needed | ||
|
|
||
| ### Step 1 — CSS Module Conversion | ||
|
|
||
| #### GATE CHECK | ||
| - **Followed as instructed:** Yes | ||
| - **Deviations:** None — file list recorded in progress report before any script runs. | ||
| - **Type:** N/A | ||
| - **Recommended Action:** No action needed | ||
|
|
||
| #### File identification | ||
| - **Followed as instructed:** Yes | ||
| - **Deviations:** None — used built-in Grep tool as specified in updated instructions. | ||
| - **Type:** N/A | ||
| - **Recommended Action:** No action needed | ||
|
|
||
| #### Script execution and TODO review | ||
| - **Followed as instructed:** Yes | ||
| - **Deviations:** None — script run once per file with `--keep-aphrodite`, both `.module.css` and `.tsx` outputs checked for `// TODO` comments after each run. Legacy styles files left with their `// TODO (LEMS-3815)` comment untouched. | ||
| - **Type:** N/A | ||
| - **Recommended Action:** No action needed | ||
|
|
||
| #### `marker.tsx` — binary expressions and keyframes | ||
| - **Followed as instructed:** Partially | ||
| - **Deviations:** Same two issues as run 1. `margin-left`/`margin-top` binary expressions (`MARKER_SIZE / -2`) and Aphrodite inline keyframes could not be resolved by the script. Manually fixed to `-1.2rem` and a proper `@keyframes` block. | ||
| - **Type:** Unintentional — fundamental script limitation for runtime-computed values; not fixable by the script update. | ||
| - **Recommended Action:** Document in PR. Worth noting to the script author as a known limitation. | ||
|
|
||
| #### `label-image.tsx` — spread properties in camelCase | ||
| - **Followed as instructed:** Partially | ||
| - **Deviations:** The updated script handled the `satisfies` crash, but `bodyXsmallBold` spread properties were emitted in camelCase JS format (`fontFamily`, `fontSize: 15` without unit) instead of valid CSS. Manually corrected to kebab-case with proper units. | ||
| - **Type:** Unintentional — script bug in how it converts spread element property names. | ||
| - **Recommended Action:** Document in PR. Worth reporting to the script author as a new bug found in the spread handling feature. | ||
|
|
||
| ### Step 2 — Pre-Push Quality Checks | ||
| - **Followed as instructed:** Yes | ||
| - **Deviations:** None — all three checks run, all failures fixed before proceeding. | ||
| - **Type:** N/A | ||
| - **Recommended Action:** No action needed |
5 changes: 5 additions & 0 deletions
5
packages/perseus/src/widgets/label-image/__stories__/marker.module.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .wrapper { | ||
| height: 3.2rem; | ||
| position: relative; | ||
| width: 3.2rem; | ||
| } |
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
6 changes: 6 additions & 0 deletions
6
packages/perseus/src/widgets/label-image/__stories__/marker_legacy-styles.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // TODO (LEMS-3815): Remove this file | ||
| const styles = { | ||
| wrapper: {height: "3.2rem", position: "relative", width: "3.2rem"}, | ||
| }; | ||
|
|
||
| export default styles; |
15 changes: 15 additions & 0 deletions
15
packages/perseus/src/widgets/label-image/answer-pill.module.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| .correct { | ||
| background-color: var(--wb-semanticColor-core-background-success-strong); | ||
| } | ||
|
|
||
| .incorrect { | ||
| background-color: var(--wb-semanticColor-core-background-neutral-default); | ||
| } | ||
|
|
||
| .pill { | ||
| /* | ||
| Reset the Pill's default height in order to account | ||
| for multi-line pills. | ||
| */ | ||
| height: auto; | ||
| } |
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
14 changes: 14 additions & 0 deletions
14
packages/perseus/src/widgets/label-image/answer-pill_legacy-styles.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // TODO (LEMS-3815): Remove this file | ||
| const styles = { | ||
| correct: { | ||
| backgroundColor: | ||
| "var(--wb-semanticColor-core-background-success-strong)", | ||
| }, | ||
| incorrect: { | ||
| backgroundColor: | ||
| "var(--wb-semanticColor-core-background-neutral-default)", | ||
| }, | ||
| pill: {height: "auto"}, | ||
| }; | ||
|
|
||
| export default styles; |
8 changes: 8 additions & 0 deletions
8
packages/perseus/src/widgets/label-image/hide-answers-toggle.module.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .switch-wrapper { | ||
| align-items: center; | ||
| display: flex; | ||
| flex-direction: row; | ||
| flex-wrap: wrap-reverse; | ||
| gap: 0.5em; | ||
| margin-top: 1em; | ||
| } |
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
13 changes: 13 additions & 0 deletions
13
packages/perseus/src/widgets/label-image/hide-answers-toggle_legacy-styles.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // TODO (LEMS-3815): Remove this file | ||
| const styles = { | ||
| switchWrapper: { | ||
| alignItems: "center", | ||
| display: "flex", | ||
| flexDirection: "row", | ||
| flexWrap: "wrap-reverse", | ||
| gap: "0.5em", | ||
| marginTop: "1em", | ||
| }, | ||
| }; | ||
|
|
||
| export default styles; |
51 changes: 51 additions & 0 deletions
51
packages/perseus/src/widgets/label-image/label-image.module.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| .image-container { | ||
| /* | ||
| Remove the additional height added due to white-spacing, this ensures | ||
| markers canvas will have the same height as the question image. | ||
| */ | ||
| display: flex; | ||
| } | ||
|
|
||
| .image-interaction-disabled { | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| .instructions { | ||
| padding-bottom: 1.6rem; | ||
| } | ||
|
|
||
| .instructions-caption { | ||
| font-family: inherit; | ||
| font-size: 15px; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My latest script update changes he |
||
| font-weight: bold; | ||
| line-height: 22px; | ||
| padding-bottom: 1.6rem; | ||
| } | ||
|
|
||
| .instructions-choice { | ||
| align-items: center; | ||
| display: flex; | ||
| margin: 0.8rem 0; | ||
| } | ||
|
|
||
| .instructions-choice:not(:last-child)::after { | ||
| background: var(--wb-semanticColor-core-border-neutral-default); | ||
| border-radius: 2px; | ||
| content: ""; | ||
| display: inline-block; | ||
| height: 0.2rem; | ||
| margin-left: 0.5rem; | ||
| margin-right: 0.5rem; | ||
| position: relative; | ||
| width: 0.2rem; | ||
| } | ||
|
|
||
| .instructions-choices { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| margin: -0.8rem 0; | ||
| } | ||
|
|
||
| .markers-canvas { | ||
| position: relative; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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'm inclined to make this a set of inline styles. I'm not sure what the purpose of this wrapper is, but since it is just used here in this story file, there is no need to make a CSS file for it. I recommend: