Repository navigation
@backstage/ui: Migrate all components from useStyles to useDefinition - #33050
Conversation
Replace ComponentDefinition with defineComponent pattern, move CSS module import and prop defaults into the definition, and switch the component to useDefinition hook. Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Make AvatarOwnProps the source of truth with inline type definitions, and have AvatarProps extend it. This follows the established pattern used by Button, Checkbox, and Alert components. Export AvatarOwnProps from the package entry point. Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Fix pre-existing variant default from 'body' to 'body-medium' to match actual CSS selectors. Add missing 'info' color to docs-ui props definition. Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
…xtension, useDefinition first - Add label to PasswordFieldOwnProps and propDefs - Remove Omit<FieldLabelProps, ...> from PasswordFieldProps - Move useDefinition call to top of component - Access aria-label/aria-labelledby from restProps instead of props Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
isRequired was consumed locally for the secondary label but never forwarded to the underlying AriaTextField/AriaSearchField, resulting in missing aria-required attribute and no built-in validation. Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
Split shared TagGroupDefinition into TagGroupDefinition (root) and TagDefinition (tag sub-component). Tag's size prop now uses dataAttribute with default in propDefs instead of manual data-size and default spreading. Signed-off-by: Johan Persson <[email protected]>
Split monolithic MenuDefinition (17 classNames) into 9 per-sub-component definitions (Menu, MenuListBox, MenuAutocomplete, MenuAutocompleteListbox, MenuItem, MenuListBoxItem, MenuSection, MenuSeparator, MenuEmptyState). MenuItem color prop uses dataAttribute with default in propDefs. Defaults for placement, virtualized, selectionMode moved to propDefs. Signed-off-by: Johan Persson <[email protected]>
Address review feedback: extract MenuPopoverOwnProps shared type for common props (placement, virtualized, maxWidth, maxHeight, style, className). Extract menuPopoverClassNames and menuPopoverPropDefs in definition.ts to ensure shared values stay in sync across Menu variants. Signed-off-by: Johan Persson <[email protected]>
Children was in propDefs (extracted to ownProps by useDefinition) but the component only spread restProps on a self-closing div, silently dropping children. Now explicitly renders children from ownProps. Signed-off-by: Johan Persson <[email protected]>
Children was incorrectly added to OwnProps/propDefs during migration, causing useDefinition to extract it from restProps. Since neither component consumes children directly, children should flow through restProps to the underlying div element. Signed-off-by: Johan Persson <[email protected]>
All components have been migrated to useDefinition. Remove the now-unused useStyles hook and its associated types (ComponentDefinition, ClassNamesMap, DataAttributeValues, DataAttributesMap) from the public API. Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
|
Important This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior. Changed Packages
|
🎨 Visual Testing with Chromatic
|
Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
orientation was listed in propDefs with dataAttribute: true, which caused useDefinition to extract it from restProps. React Aria's ToggleButtonGroup never received it and defaulted to horizontal. Remove orientation from propDefs and OwnProps so it flows through restProps to React Aria, which handles data-orientation itself. Signed-off-by: Johan Persson <[email protected]>
There was a problem hiding this comment.
Pull request overview
This pull request performs a comprehensive migration of all 58 UI components from the legacy useStyles hook to the modern useDefinition hook backed by defineComponent(). The migration unifies component prop resolution, enables automatic CSS module class merging, and provides cleaner prop separation through ownProps and restProps.
Changes:
- Migrated all 58 components from
useStylestouseDefinitionhook - Removed deprecated types (
ComponentDefinition,ClassNamesMap,DataAttributesMap,DataAttributeValues) and deleted theuseStyleshook - Fixed two bugs: Link variant default (
'body'→'body-medium') andisRequiredprop forwarding in TextField/SearchField/PasswordField
Reviewed changes
Copilot reviewed 135 out of 135 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/types.ts | Removed deprecated public types for component definitions |
| packages/ui/src/hooks/useStyles.ts | Deleted legacy styling hook |
| packages/ui/src/components/*/types.ts | Added OwnProps types for all components |
| packages/ui/src/components/*/definition.ts | Migrated from object literals to defineComponent() |
| packages/ui/src/components/*/Component.tsx | Updated to use useDefinition with ownProps/restProps pattern |
| packages/ui/src/components/SearchField/SearchField.module.css | Updated data attribute selector to lowercase |
| .changeset/*.md | Added changesets documenting breaking changes and bug fixes |
| packages/ui/report.api.md | Updated API surface to reflect type changes |
cdedreuille
left a comment
There was a problem hiding this comment.
Thanks a lot @Naycon 🙏 It would be hard to review every component but from the look of it the migration seems to have worked pretty well. I can see there was some visual regressions on the Link component though. I could not really tell what was wrong in the diff but and code change but just wanted to make sure we're good here.
|
|
||
| ```diff | ||
| - [data-startCollapsed='true'] { ... } | ||
| + [data-startcollapsed='true'] { ... } |
There was a problem hiding this comment.
Would it make sense to do data-start-collapsed ?
There was a problem hiding this comment.
It could, but I thought this was more in line with what html does in general (e.g. aria-describedby or tabindex, so therefore I went this route.
|
@cdedreuille there's no visual regression on Link, there's a visual progression. 😁 This is why (from the PR description):
There's no |
|
Ah perfect. Sorry for the confusion. I'm glad you fought this bug 🤗 |
|
Thank you for contributing to Backstage! The changes in this pull request will be part of the |
Hey, I just made a Pull Request!
Migrates all 58 components in
packages/uifrom the legacyuseStyleshook(backed by
ComponentDefinition) to theuseDefinitionhook (backed bydefineComponent()). This unifies every component on the richer prop-resolutionpattern that provides automatic CSS module class merging, declarative defaults,
clean prop separation (
ownProps/restProps), and background system integration.After migration, the now-unused
useStyleshook and legacy types(
ComponentDefinition,ClassNamesMap,DataAttributesMap,DataAttributeValues) are deleted.Breaking changes
ComponentDefinition,ClassNamesMap,DataAttributeValues, andDataAttributesMapfrom the public API.(
data-startCollapsed→data-startcollapsed).Bug fixes uncovered during migration
'body'to'body-medium'to matchactual CSS selectors.
isRequirednot being forwarded to React Aria field componentsin TextField, SearchField, and PasswordField.
✔️ Checklist
Signed-off-byline in the message.