Refactor icon components#760
Open
mkernohanbc wants to merge 10 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the React icon components to standardize their props, introduce token-driven sizing, and add baseline SVG accessibility support (title/role/aria attributes), and updates Storybook docs/usages accordingly.
Changes:
- Added
size/titleprops to multiple SVG icon components and standardized them onReact.SVGProps<SVGSVGElement>forwarding. - Introduced
getIconSizeto map semantic sizes (xsmall→xlarge) to design token CSS variables and updated icon usages in MDX/examples to pass semantic sizes. - Updated the build config to include the new hooks directory.
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-components/src/stories/Tooltip.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/ToggleButtonGroup.mdx | Updates icon size usage to semantic size (two links). |
| packages/react-components/src/stories/TimeField.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/TextField.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/TextArea.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/TagGroup.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/Switch.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/Select.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/RadioGroup.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/ProgressBar.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/NumberField.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/MenuTrigger.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/MenuItem.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/Menu.mdx | Updates icon size usage to semantic size (two links). |
| packages/react-components/src/stories/Dialogs.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/DatePicker.mdx | Updates icon size usage to semantic size (two links). |
| packages/react-components/src/stories/CheckboxGroup.mdx | Updates icon size usage to semantic size (two links). |
| packages/react-components/src/stories/Calendar.mdx | Updates icon size usage to semantic size (two links). |
| packages/react-components/src/stories/Button.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/AlertDialog.mdx | Updates icon size usage to semantic size. |
| packages/react-components/src/stories/AccordionGroup.mdx | Updates icon size usage to semantic size (two links). |
| packages/react-components/src/pages/Button/ButtonPrimary.tsx | Updates placeholder icon usage to semantic size. |
| packages/react-components/src/hooks/getIconSize.ts | Adds IconSize + token mapping helper used by icons. |
| packages/react-components/src/components/Icons/SvgUpRightFromSquareIcon/SvgUpRightFromSquareIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgTooltipArrowUp/SvgTooltipArrowUp.tsx | Adds title + accessibility attrs (keeps fixed dimensions). |
| packages/react-components/src/components/Icons/SvgReactAriaIcon/SvgReactAriaIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgPlusIcon/SvgPlusIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgPlaceholderIcon/SvgPlaceholderIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgMinusIcon/SvgMinusIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgInfoIcon/SvgInfoIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgExclamationIcon/SvgExclamationIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgExclamationCircleIcon/SvgExclamationCircleIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgDashIcon/SvgDashIcon.tsx | Adds title + accessibility attrs (keeps fixed dimensions). |
| packages/react-components/src/components/Icons/SvgCloseIcon/SvgCloseIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgChevronUpIcon/SvgChevronUpIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgChevronRightIcon/SvgChevronRightIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgChevronLeftIcon/SvgChevronLeftIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgChevronDownIcon/SvgChevronDownIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgCheckIcon/SvgCheckIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgCheckCircleIcon/SvgCheckCircleIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgCalendarIcon/SvgCalendarIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgBetaIcon/SvgBetaIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgBcOutlineIcon/SvgBcOutlineIcon.tsx | Adds size/title, accessibility attrs, token sizing. |
| packages/react-components/src/components/Icons/SvgBcLogo/SvgBcLogo.tsx | Adds title + accessibility attrs (keeps existing sizing/CSS). |
| packages/react-components/rollup.config.js | Includes src/hooks/**/* in the build inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3
to
+4
| import { useId } from "react"; | ||
| import getIconSize, { IconSize } from "../../../hooks/getIconSize"; |
Comment on lines
+12
to
+16
| export default function SvgCheckIcon({ | ||
| size = "medium", | ||
| title, | ||
| id, | ||
| ...props |
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.
This PR closes #436 and #614. It refactors our entire set of icon components to:
sizeandtitleand leverageReact.SVGPropsrole,aria-labelledby,aria-hiddenandfocusableattributesRationale
These icon components are primarily intended to be consumed by other components, which own the accessibility context. However, we are also exporting them as standalone components, meaning people may use them elsewhere — this change makes them more robust and less likely to cause accessibility issues when doing so.
Sizing
Sizing for most icon components is now handled via a new
getIconSizehook. This maps thesizeprop on each component to the correct design token value (--icons-size-xsmallto--icons-size-xlarge.) The values are hardcoded ingetIconSize.ts, because CSS variables can't be evaluated in SVG presentation attributes.Sizing is now set in an inlineChanged in 40ef335, see #760 (comment)styleattribute, rather than inwidthandheightSVG presentation attributes. This means that CSS variables can be properly evaluated, and we can leverage the tokens without hardcoding their values.These components are currently excluded from the new sizing pattern, because they have non-uniform aspect ratios and/or specialized use-cases:
SvgBcLogoSvgDashIconSvgTooltipArrowUpTitles and roles
Icon components now support a
titleprop, which populates a <title> element.<title>receives an ID generated via useId, which is used to setaria-labelledby.The presence or absence of
titleis a trigger for various other attributes:titleis present, the icon is considered non-decorative.role="img"andaria-labelledbyare set automaticallyroleis not set andaria-hiddenis applied