From 4fdaeb034d97e6f88e2150453fe38a9314810114 Mon Sep 17 00:00:00 2001 From: Myrto Kontouli Date: Tue, 25 Jul 2023 20:07:32 +0100 Subject: [PATCH] feat: remove uses of asWorkaround in favour of stitches withConfig --- .../components/chip-toggle-group/ChipToggleGroupItem.tsx | 6 ++++-- lib/src/components/chip/Chip.tsx | 8 +++----- lib/src/components/tile-interactive/TileInteractive.tsx | 8 +++++--- .../components/tile-toggle-group/TileToggleGroupItem.tsx | 6 ++++-- lib/src/components/tile/Tile.tsx | 7 +++---- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/src/components/chip-toggle-group/ChipToggleGroupItem.tsx b/lib/src/components/chip-toggle-group/ChipToggleGroupItem.tsx index f5f7a56ca..948c7037d 100644 --- a/lib/src/components/chip-toggle-group/ChipToggleGroupItem.tsx +++ b/lib/src/components/chip-toggle-group/ChipToggleGroupItem.tsx @@ -11,7 +11,9 @@ const StyledChipToggleIcon = styled(Icon, { display: 'none' }) -const StyledChipToggleGroupItem = styled(Chip, { +const StyledChipToggleGroupItem = styled.withConfig({ + shouldForwardStitchesProp: (propName) => ['as'].includes(propName) +})(Chip, { '&:not([disabled])': { cursor: 'pointer', '&:hover': { @@ -51,7 +53,7 @@ export const ChipToggleGroupItem: React.FC = ({ }) => { return ( - + {children} diff --git a/lib/src/components/chip/Chip.tsx b/lib/src/components/chip/Chip.tsx index f4d3032f0..41d356fa5 100644 --- a/lib/src/components/chip/Chip.tsx +++ b/lib/src/components/chip/Chip.tsx @@ -109,15 +109,13 @@ export const ChipRootProvider: React.FC = ({ ) } -export type TChipRootProps = TChipRootProviderProps & { - asWorkaround?: React.ElementType // (!?) `asWorkaround` rather than `as` because, it seems, when we extend this via `styled()` stitches overrides this component from the first argument for the value in `as` -} +export type TChipRootProps = TChipRootProviderProps const ChipRoot: React.ForwardRefExoticComponent = - React.forwardRef(({ asWorkaround, size = 'md', ...rest }, ref) => { + React.forwardRef(({ size = 'md', ...rest }, ref) => { return ( - + ) }) diff --git a/lib/src/components/tile-interactive/TileInteractive.tsx b/lib/src/components/tile-interactive/TileInteractive.tsx index 8e1026d91..e41861511 100644 --- a/lib/src/components/tile-interactive/TileInteractive.tsx +++ b/lib/src/components/tile-interactive/TileInteractive.tsx @@ -5,7 +5,9 @@ import { styled } from '~/stitches' import { NavigatorActions } from '~/types' import { focusVisibleStyleBlock } from '~/utilities' -const StyledTileInteractive = styled(Tile, { +const StyledTileInteractive = styled.withConfig({ + shouldForwardStitchesProp: (propName) => ['as'].includes(propName) +})(Tile, { '&[data-disabled]': { opacity: 0.3, cursor: 'not-allowed' @@ -49,11 +51,11 @@ export const TileInteractive = React.forwardRef< const isLink = !!href const elementSpecificProps = isLink ? { - asWorkaround: 'a' as React.ElementType, + as: 'a' as React.ElementType, href, onClick: undefined } - : { asWorkaround: 'button' as React.ElementType, type, onClick } + : { as: 'button' as React.ElementType, type, onClick } return }) diff --git a/lib/src/components/tile-toggle-group/TileToggleGroupItem.tsx b/lib/src/components/tile-toggle-group/TileToggleGroupItem.tsx index f113750dd..3081f1e9e 100644 --- a/lib/src/components/tile-toggle-group/TileToggleGroupItem.tsx +++ b/lib/src/components/tile-toggle-group/TileToggleGroupItem.tsx @@ -4,7 +4,9 @@ import * as React from 'react' import { TileInteractive } from '~/components/tile-interactive' import { styled } from '~/stitches' -const StyledTileToggleGroupItem = styled(TileInteractive, { +const StyledTileToggleGroupItem = styled.withConfig({ + shouldForwardStitchesProp: (propName) => ['as'].includes(propName) +})(TileInteractive, { '&:not([disabled])': { '&[data-state="on"]': { '&:hover': { @@ -38,7 +40,7 @@ export const TileToggleGroupItem: React.FC = ({ }) => { return ( - + {children} diff --git a/lib/src/components/tile/Tile.tsx b/lib/src/components/tile/Tile.tsx index cf6f3a57b..78557b58f 100644 --- a/lib/src/components/tile/Tile.tsx +++ b/lib/src/components/tile/Tile.tsx @@ -26,12 +26,11 @@ export const StyledTile = styled('div', { }) type TTileProps = React.ComponentProps & { - asWorkaround?: React.ElementType // (!?) `asWorkaround` rather than `as` because, it seems, when we extend this via `styled()` stitches overrides this component from the first argument for the value in `as` colorScheme?: TcolorScheme } -export const Tile = React.forwardRef( - ({ children, asWorkaround, colorScheme = {}, ...rest }, ref) => ( +export const Tile = React.forwardRef( + ({ children, colorScheme = {}, ...rest }, ref) => ( ( interactive="loContrast" {...colorScheme} > - + {children}