Skip to content

Commit

Permalink
Merge pull request #549 from Atom-Learning/feat/remove-asWorkaround-uses
Browse files Browse the repository at this point in the history
feat: remove uses of asWorkaround in favour of stitches withConfig
  • Loading branch information
LimeWub authored Jul 26, 2023
2 parents 60b2391 + 4fdaeb0 commit 83e4a12
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
6 changes: 4 additions & 2 deletions lib/src/components/chip-toggle-group/ChipToggleGroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -51,7 +53,7 @@ export const ChipToggleGroupItem: React.FC<TChipToggleGroupItem> = ({
}) => {
return (
<ToggleGroup.Item {...rest} asChild>
<StyledChipToggleGroupItem asWorkaround="button">
<StyledChipToggleGroupItem as="button">
<StyledChipToggleIcon is={Ok} size={size === 'lg' ? 'md' : 'sm'} />
<Chip.Content>{children}</Chip.Content>
</StyledChipToggleGroupItem>
Expand Down
8 changes: 3 additions & 5 deletions lib/src/components/chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ export const ChipRootProvider: React.FC<TChipRootProviderProps> = ({
)
}

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<TChipRootProps> =
React.forwardRef(({ asWorkaround, size = 'md', ...rest }, ref) => {
React.forwardRef(({ size = 'md', ...rest }, ref) => {
return (
<ChipRootProvider size={size}>
<StyledRoot ref={ref} as={asWorkaround} size={size} {...rest} />
<StyledRoot ref={ref} size={size} {...rest} />
</ChipRootProvider>
)
})
Expand Down
8 changes: 5 additions & 3 deletions lib/src/components/tile-interactive/TileInteractive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 <StyledTileInteractive {...rest} {...elementSpecificProps} ref={ref} />
})
Expand Down
6 changes: 4 additions & 2 deletions lib/src/components/tile-toggle-group/TileToggleGroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -38,7 +40,7 @@ export const TileToggleGroupItem: React.FC<TTileToggleGroupItem> = ({
}) => {
return (
<ToggleGroup.Item {...rest} asChild>
<StyledTileToggleGroupItem asWorkaround="button">
<StyledTileToggleGroupItem as="button">
{children}
</StyledTileToggleGroupItem>
</ToggleGroup.Item>
Expand Down
7 changes: 3 additions & 4 deletions lib/src/components/tile/Tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ export const StyledTile = styled('div', {
})

type TTileProps = React.ComponentProps<typeof StyledTile> & {
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<HTMLButtonElement, TTileProps>(
({ children, asWorkaround, colorScheme = {}, ...rest }, ref) => (
export const Tile = React.forwardRef<HTMLDivElement, TTileProps>(
({ children, colorScheme = {}, ...rest }, ref) => (
<ColorScheme
asChild
base="grey1"
accent="blue2"
interactive="loContrast"
{...colorScheme}
>
<StyledTile ref={ref} as={asWorkaround} {...rest}>
<StyledTile ref={ref} {...rest}>
{children}
</StyledTile>
</ColorScheme>
Expand Down

0 comments on commit 83e4a12

Please sign in to comment.