Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

refactor(core): migrate style-only wrappers onto component xstyle (#4775)

Cindy Zhang5fb9a2d093cf
diff --git a/.changeset/migrate-style-only-wrappers.md b/.changeset/migrate-style-only-wrappers.md
new file mode 100644
index 0000000000..da3771c825
--- /dev/null
+++ b/.changeset/migrate-style-only-wrappers.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Remove 15 `<div>`/`<span>` wrappers that existed only to style the single Astryx component inside them (Carousel, Lightbox, MobileNav, Pagination, Switch, TopNav, TopNavMegaMenu, Table row-expansion menu icon); the styles now sit on that component's own root via `xstyle` — or, for Pagination's page-size Selector, its documented `width` prop. No API change, but the rendered DOM has one fewer node at each site, so anything selecting on that structure is affected: `patch`, not `[breaking]`, because the removed nodes were internal implementation with no documented contract, no theme target, and no stable class. Two rendering defects the wrappers were causing are fixed as a side effect: the Lightbox prev/next chevrons and the Pagination first/last chevrons were 2.5-3px off their button's vertical centre.
+
+@cixzhang
diff --git a/packages/core/src/Carousel/Carousel.tsx b/packages/core/src/Carousel/Carousel.tsx
index b100810e66..fc2ab469cd 100644
--- a/packages/core/src/Carousel/Carousel.tsx
+++ b/packages/core/src/Carousel/Carousel.tsx
@@ -560,9 +560,11 @@ export function Carousel({
)}>
<Button
icon={
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon icon="chevronLeft" size="xsm" />
- </span>
+ <Icon
+ icon="chevronLeft"
+ size="xsm"
+ xstyle={rtlStyles.mirror}
+ />
}
label={t('@astryx.carousel.scrollLeft')}
variant="ghost"
@@ -585,9 +587,11 @@ export function Carousel({
)}>
<Button
icon={
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon icon="chevronRight" size="xsm" />
- </span>
+ <Icon
+ icon="chevronRight"
+ size="xsm"
+ xstyle={rtlStyles.mirror}
+ />
}
label={t('@astryx.carousel.scrollRight')}
variant="ghost"
diff --git a/packages/core/src/Lightbox/Lightbox.tsx b/packages/core/src/Lightbox/Lightbox.tsx
index cd43635780..f84d5c6bc1 100644
--- a/packages/core/src/Lightbox/Lightbox.tsx
+++ b/packages/core/src/Lightbox/Lightbox.tsx
@@ -215,7 +215,12 @@ const styles = stylex.create({
navButton: {
position: 'absolute',
top: '50%',
- transform: 'translateY(-50%)',
+ // The individual `translate` property, not `transform`: this style now
+ // lands on the Button root, and a `transform` here replaces the Button's
+ // own transform rules — measured: the `scale(0.98)` press feedback stops
+ // firing. `translate` composes with them, reproducing exactly what the
+ // removed wrapper element did (wrapper translated, button scaled).
+ translate: '0 -50%',
zIndex: 1,
},
navPrev: {
@@ -595,34 +600,33 @@ export function Lightbox({
{...props}>
<div ref={containerRef} {...stylex.props(styles.container)}>
{/* Close button */}
- <div {...stylex.props(styles.closeButton)}>
- <IconButton
- icon={<Icon icon="close" size="sm" color="inherit" />}
- label={t('@astryx.lightbox.close')}
- variant="ghost"
- onClick={handleClose}
- xstyle={styles.controlButton}
- />
- </div>
+ <IconButton
+ icon={<Icon icon="close" size="sm" color="inherit" />}
+ label={t('@astryx.lightbox.close')}
+ variant="ghost"
+ onClick={handleClose}
+ xstyle={[styles.closeButton, styles.controlButton]}
+ />
{/* Gallery nav: prev — stays mounted and is disabled at the start of
the range so pressing/arrowing to the boundary doesn't unmount the
focused control and drop focus to <body>. */}
{isGallery && (
- <div {...stylex.props(styles.navButton, styles.navPrev)}>
- <IconButton
- icon={
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon icon="chevronLeft" size="sm" color="inherit" />
- </span>
- }
- label={t('@astryx.lightbox.previous')}
- variant="ghost"
- isDisabled={!canPrev}
- onClick={goToPrev}
- xstyle={styles.controlButton}
- />
- </div>
+ <IconButton
+ icon={
+ <Icon
+ icon="chevronLeft"
+ size="sm"
+ color="inherit"
+ xstyle={rtlStyles.mirror}
+ />
+ }
+ label={t('@astryx.lightbox.previous')}
+ variant="ghost"
+ isDisabled={!canPrev}
+ onClick={goToPrev}
+ xstyle={[styles.navButton, styles.navPrev, styles.controlButton]}
+ />
)}
{/* Media + caption group (centered together) */}
@@ -676,20 +680,21 @@ export function Lightbox({
{/* Gallery nav: next — see "prev" above; stays mounted and disabled at
the end of the range instead of unmounting. */}
{isGallery && (
- <div {...stylex.props(styles.navButton, styles.navNext)}>
- <IconButton
- icon={
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon icon="chevronRight" size="sm" color="inherit" />
- </span>
- }
- label={t('@astryx.lightbox.next')}
- variant="ghost"
- isDisabled={!canNext}
- onClick={goToNext}
- xstyle={styles.controlButton}
- />
- </div>
+ <IconButton
+ icon={
+ <Icon
+ icon="chevronRight"
+ size="sm"
+ color="inherit"
+ xstyle={rtlStyles.mirror}
+ />
+ }
+ label={t('@astryx.lightbox.next')}
+ variant="ghost"
+ isDisabled={!canNext}
+ onClick={goToNext}
+ xstyle={[styles.navButton, styles.navNext, styles.controlButton]}
+ />
)}
{/* Gallery counter */}
diff --git a/packages/core/src/MobileNav/MobileNav.tsx b/packages/core/src/MobileNav/MobileNav.tsx
index 753e5fd957..0509c980a7 100644
--- a/packages/core/src/MobileNav/MobileNav.tsx
+++ b/packages/core/src/MobileNav/MobileNav.tsx
@@ -453,9 +453,9 @@ export function MobileNav({
{/* Header — content + close button */}
<div {...stylex.props(styles.header, !header && styles.headerNoTitle)}>
{typeof header === 'string' ? (
- <span {...stylex.props(styles.headerText)}>
- <Heading level={2}>{header}</Heading>
- </span>
+ <Heading level={2} xstyle={styles.headerText}>
+ {header}
+ </Heading>
) : (
(header ?? null)
)}
diff --git a/packages/core/src/Pagination/Pagination.tsx b/packages/core/src/Pagination/Pagination.tsx
index 527da36209..96452e7c65 100644
--- a/packages/core/src/Pagination/Pagination.tsx
+++ b/packages/core/src/Pagination/Pagination.tsx
@@ -165,6 +165,9 @@ export interface PaginationProps extends Omit<
// Styles
// =============================================================================
+/** Width (px) of the page-size Selector field. */
+const PAGE_SIZE_SELECTOR_WIDTH = 80;
+
const styles = stylex.create({
root: {
display: 'flex',
@@ -265,9 +268,6 @@ const styles = stylex.create({
alignItems: 'center',
gap: spacingVars['--spacing-2'],
},
- pageSizeSelectorControl: {
- width: 80,
- },
disabled: {
opacity: 0.5,
pointerEvents: 'none' as const,
@@ -791,17 +791,19 @@ export function Pagination({
data-testid={testId}>
{pageSizeOptions != null && pageSizeOptions.length > 0 && (
<div {...stylex.props(styles.pageSizeSelector)}>
- <div {...stylex.props(styles.pageSizeSelectorControl)}>
- <Selector
- label={itemsPerPageLabel}
- isLabelHidden
- options={pageSizeOptions.map(opt => String(opt))}
- value={String(pageSize)}
- onChange={handlePageSizeChange}
- size={buttonSize}
- isDisabled={isDisabled}
- />
- </div>
+ <Selector
+ label={itemsPerPageLabel}
+ isLabelHidden
+ options={pageSizeOptions.map(opt => String(opt))}
+ value={String(pageSize)}
+ onChange={handlePageSizeChange}
+ size={buttonSize}
+ isDisabled={isDisabled}
+ // `width`, not `xstyle`: Selector's xstyle lands on the trigger
+ // box, while `width` sizes the whole field — which is what the
+ // removed wrapper did.
+ width={PAGE_SIZE_SELECTOR_WIDTH}
+ />
</div>
)}
<div {...stylex.props(styles.controls)}>
@@ -812,9 +814,11 @@ export function Pagination({
variant="ghost"
size={buttonSize}
icon={
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon icon="chevronsLeft" size={isSm ? 'sm' : 'md'} />
- </span>
+ <Icon
+ icon="chevronsLeft"
+ size={isSm ? 'sm' : 'md'}
+ xstyle={rtlStyles.mirror}
+ />
}
onClick={handleFirst}
isDisabled={isDisabled || !hasPrevious}
@@ -865,9 +869,11 @@ export function Pagination({
variant="ghost"
size={buttonSize}
icon={
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon icon="chevronsRight" size={isSm ? 'sm' : 'md'} />
- </span>
+ <Icon
+ icon="chevronsRight"
+ size={isSm ? 'sm' : 'md'}
+ xstyle={rtlStyles.mirror}
+ />
}
onClick={handleLast}
isDisabled={isDisabled || !hasNext}
diff --git a/packages/core/src/Switch/Switch.tsx b/packages/core/src/Switch/Switch.tsx
index 9d0716a5d3..68cf02fadc 100644
--- a/packages/core/src/Switch/Switch.tsx
+++ b/packages/core/src/Switch/Switch.tsx
@@ -643,14 +643,13 @@ export function Switch({
)}
</div>
{status?.message && (
- <div {...stylex.props(styles.statusGap)}>
- <FieldStatus
- type={status.type}
- message={status.message}
- id={statusMessageID}
- variant="detached"
- />
- </div>
+ <FieldStatus
+ type={status.type}
+ message={status.message}
+ id={statusMessageID}
+ variant="detached"
+ xstyle={styles.statusGap}
+ />
)}
{showsDisabledMessage &&
disabledMessageTooltip.renderTooltip(disabledMessage)}
diff --git a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
index fb745fac53..bf875beabe 100644
--- a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
+++ b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
@@ -598,13 +598,12 @@ export function useTableRowExpansion<T extends Record<string, unknown>>(
? t('@astryx.tableRowExpansion.collapseRow')
: t('@astryx.tableRowExpansion.expandRow'),
icon: (
- <span {...stylex.props(rtlStyles.mirror)}>
- <Icon
- icon={isExpanded ? 'chevronDown' : 'chevronRight'}
- size="xsm"
- aria-hidden
- />
- </span>
+ <Icon
+ icon={isExpanded ? 'chevronDown' : 'chevronRight'}
+ size="xsm"
+ aria-hidden
+ xstyle={rtlStyles.mirror}
+ />
),
onSelect: () => onToggle(key),
},
diff --git a/packages/core/src/TopNav/TopNav.tsx b/packages/core/src/TopNav/TopNav.tsx
index 6f26cc315c..eb83716aaf 100644
--- a/packages/core/src/TopNav/TopNav.tsx
+++ b/packages/core/src/TopNav/TopNav.tsx
@@ -243,9 +243,7 @@ export function TopNav({
</div>
)}
{hasCollapsibleContent && mobileContent && (
- <div {...stylex.props(styles.drawerDivider)}>
- <Divider />
- </div>
+ <Divider xstyle={styles.drawerDivider} />
)}
{mobileContent && (
<div {...stylex.props(styles.drawerExtraContent)}>
diff --git a/packages/core/src/TopNav/TopNavMegaMenu.tsx b/packages/core/src/TopNav/TopNavMegaMenu.tsx
index 92d7a78206..7b3de1a530 100644
--- a/packages/core/src/TopNav/TopNavMegaMenu.tsx
+++ b/packages/core/src/TopNav/TopNavMegaMenu.tsx
@@ -493,11 +493,9 @@ function DefaultMegaMenu({
<div {...stylex.props(styles.panelContent)}>
{/* Menu items section */}
{items != null && (
- <div {...stylex.props(styles.menuWrapper)}>
- <Grid columns={2} gap={2}>
- {items}
- </Grid>
- </div>
+ <Grid columns={2} gap={2} xstyle={styles.menuWrapper}>
+ {items}
+ </Grid>
)}
{/* Featured section */}
diff --git a/packages/core/src/utils/rtlStyles.ts b/packages/core/src/utils/rtlStyles.ts
index e44422e265..8b30003c05 100644
--- a/packages/core/src/utils/rtlStyles.ts
+++ b/packages/core/src/utils/rtlStyles.ts
@@ -4,8 +4,8 @@
* @file rtlStyles.ts
* @input None
* @output Shared StyleX style that horizontally mirrors an element under RTL
- * @position Core utility; applied to directional-icon wrappers in Calendar,
- * Lightbox, and the Table expand/disclosure plugins
+ * @position Core utility; applied to directional icons in Calendar, Lightbox,
+ * Pagination, Carousel and the Table expand/disclosure plugins
*
* `mirror` flips its element on the horizontal axis only when an ancestor
* carries `dir="rtl"`. Using `scaleX(-1)` (not `scale(-1, -1)`) keeps the