From 7057fa7c5b476d6b326901125c0869096e5acd89 Mon Sep 17 00:00:00 2001 From: Juan Andrade Date: Fri, 31 Jan 2025 17:01:55 -0500 Subject: [PATCH] [WB-1814.4] Refactor Accordion, Banner, BirthdayPicker to use semantic colors (#2446) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: Next step is to refactor the `Accordion`, `Banner`, and `BirthdayPicker` components to use semantic colors. ### Implementation plan: 1. #2439 2. #2440 3. #2441 4. Accordion, Banner, BirthdayPicker (current PR) 5. IconButton 6. Clickable, Link 7. Modal 8. Popover, Tooltip 9. Pill, Toolbar Issue: WB-1814 ## Test plan: Verify that the Chromatic snapshots are unchanged. Author: jandrade Reviewers: jandrade, beaesguerra Required Reviewers: Approved By: beaesguerra Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Chromatic - Build and test on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ⏭️ Chromatic - Skip on Release PR (changesets), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ⏭️ dependabot Pull Request URL: https://github.com/Khan/wonder-blocks/pull/2446 --- .changeset/gorgeous-adults-lay.md | 7 +++ .../accordion.stories.tsx | 4 ++ .../components/accordion-section-header.tsx | 55 ++++++------------- .../src/components/accordion-section.tsx | 38 +++++++------ .../src/components/banner.tsx | 18 +++--- .../src/components/birthday-picker.tsx | 12 +++- 6 files changed, 66 insertions(+), 68 deletions(-) create mode 100644 .changeset/gorgeous-adults-lay.md diff --git a/.changeset/gorgeous-adults-lay.md b/.changeset/gorgeous-adults-lay.md new file mode 100644 index 0000000000..aa61f00516 --- /dev/null +++ b/.changeset/gorgeous-adults-lay.md @@ -0,0 +1,7 @@ +--- +"@khanacademy/wonder-blocks-birthday-picker": patch +"@khanacademy/wonder-blocks-accordion": patch +"@khanacademy/wonder-blocks-banner": patch +--- + +Replace `color` with `semanticColor` tokens diff --git a/__docs__/wonder-blocks-accordion/accordion.stories.tsx b/__docs__/wonder-blocks-accordion/accordion.stories.tsx index d208ed7257..9357ecd9be 100644 --- a/__docs__/wonder-blocks-accordion/accordion.stories.tsx +++ b/__docs__/wonder-blocks-accordion/accordion.stories.tsx @@ -611,6 +611,10 @@ export const BackgroundColorExample: StoryComponentType = { render: () => { const accordionSectionStyle = { backgroundColor: tokens.color.fadedBlue, + // NOTE: This border color uses the opacity token to match the + // background color. By default, the border color is + // `fadedOffBlack16`, which is the HEX value of `offBlack16`. + borderColor: tokens.color.offBlack16, }; const sections = [ diff --git a/packages/wonder-blocks-accordion/src/components/accordion-section-header.tsx b/packages/wonder-blocks-accordion/src/components/accordion-section-header.tsx index 4c07ab9dcf..bed43b6e85 100644 --- a/packages/wonder-blocks-accordion/src/components/accordion-section-header.tsx +++ b/packages/wonder-blocks-accordion/src/components/accordion-section-header.tsx @@ -6,7 +6,7 @@ import Clickable from "@khanacademy/wonder-blocks-clickable"; import {View} from "@khanacademy/wonder-blocks-core"; import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon"; import {HeadingSmall} from "@khanacademy/wonder-blocks-typography"; -import * as tokens from "@khanacademy/wonder-blocks-tokens"; +import {spacing, semanticColor} from "@khanacademy/wonder-blocks-tokens"; import type {StyleType} from "@khanacademy/wonder-blocks-core"; import type {AccordionCornerKindType} from "./accordion"; @@ -125,7 +125,7 @@ const AccordionSectionHeader = React.forwardRef(function AccordionSectionHeader( {collapsible && ( { switch (kind) { case "success": return { - color: color.green, + color: semanticColor.status.success.foreground, icon: successIcon, role: "status", }; case "warning": return { - color: color.gold, + color: semanticColor.status.warning.foreground, icon: warningIcon, role: "alert", ariaLive: "polite", }; case "critical": return { - color: color.red, + color: semanticColor.status.critical.foreground, icon: criticalIcon, role: "alert", }; default: return { - color: color.blue, + color: semanticColor.status.notice.foreground, icon: infoIcon, role: "status", }; @@ -313,7 +313,9 @@ const styles = StyleSheet.create({ // the base color needs to be hard-coded as white for the // intended pastel background color to show up correctly // on dark backgrounds. - backgroundColor: color.white, + // TODO(WB-1865): Verify if we can change this to use semanticColor + // status tokens. + backgroundColor: semanticColor.surface.primary, }, containerInner: { flexDirection: "row", @@ -328,7 +330,7 @@ const styles = StyleSheet.create({ marginInlineStart: spacing.xxxxSmall_2, marginInlineEnd: spacing.xSmall_8, alignSelf: "flex-start", - color: color.offBlack64, + color: semanticColor.icon.primary, }, labelAndButtonsContainer: { flex: 1, @@ -359,7 +361,7 @@ const styles = StyleSheet.create({ justifyContent: "center", }, link: { - fontSize: 14, + fontSize: font.size.small, }, dismiss: { flexShrink: 1, diff --git a/packages/wonder-blocks-birthday-picker/src/components/birthday-picker.tsx b/packages/wonder-blocks-birthday-picker/src/components/birthday-picker.tsx index a53f6f8d0e..aeab09e0fa 100644 --- a/packages/wonder-blocks-birthday-picker/src/components/birthday-picker.tsx +++ b/packages/wonder-blocks-birthday-picker/src/components/birthday-picker.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import {StyleSheet} from "aphrodite"; import {StyleType, View} from "@khanacademy/wonder-blocks-core"; import {Strut} from "@khanacademy/wonder-blocks-layout"; -import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; +import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens"; import {Body} from "@khanacademy/wonder-blocks-typography"; import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon"; import {SingleSelect, OptionItem} from "@khanacademy/wonder-blocks-dropdown"; @@ -284,11 +284,17 @@ export default class BirthdayPicker extends React.Component {