Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to vanilla sprinkles (Extreme edition) #159

Open
wants to merge 1 commit into
base: refactor-with-vanilla-extract
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions components/src/components/atoms/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react'

import { rainbowSprinkles } from '@/src/css/rainbow-spinkles.css'

import { rawColorToRGBA } from '@/src/tokens/color'

Check failure on line 3 in components/src/components/atoms/Avatar/Avatar.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'rawColorToRGBA' is defined but never used

import { Box, type BoxProps } from '../Box/Box'
import { avatar } from './styles.css'
Expand Down Expand Up @@ -36,19 +34,19 @@
$url?: string
}
const Placeholder = ({
$disabled,

Check failure on line 37 in components/src/components/atoms/Avatar/Avatar.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$disabled' is defined but never used
$url,

Check failure on line 38 in components/src/components/atoms/Avatar/Avatar.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$url' is defined but never used
...props
}: PlaceholderProps & BoxProps) => (
<Box
alignItems="center"
background={$url || 'blueGradient'}
// background={$url || 'blueGradient'}
display="flex"
filter={$disabled ? 'grayscale(1)' : 'unset'}
height="100%"
// filter={$disabled ? 'grayscale(1)' : 'unset'}
// height="100%"
justifyContent="center"
position="absolute"
width="100%"
// width="100%"
{...props}
/>
)
Expand All @@ -67,7 +65,7 @@
/** An element that overlays the avatar */
checked?: boolean
/** An svg to overlay over the avatar */
icon?: React.ReactElement
icon?: React.FC
/** The deconding attribute of an img element */
decoding?: NativeImgAttributes['decoding']
/** A custom sizing for the avatar */
Expand All @@ -84,7 +82,7 @@
icon,
checked,
size,
...props
// ...props
}) => {
const ref = React.useRef<HTMLImageElement>(null)
const [showImage, setShowImage] = React.useState(!!src)
Expand Down Expand Up @@ -115,35 +113,38 @@

const isImageVisible = showImage && !!src

const {
className: imgClassName,
style: imgStyle,
otherProps: imgOtherProps,
} = rainbowSprinkles({
display: isImageVisible ? 'block' : 'none',
position: 'absolute',
height: '100%',
objectFit: 'cover',
width: '100%',
filter: disabled ? 'grayscale(1)' : undefined,
...props,
})
// const {
// className: imgClassName,
// style: imgStyle,
// otherProps: imgOtherProps,
// } = rainbowSprinkles({
// display: isImageVisible ? 'block' : 'none',
// position: 'absolute',
// height: '100%',
// objectFit: 'cover',
// width: '100%',
// filter: disabled ? 'grayscale(1)' : undefined,
// ...props,
// })

const overlay = React.useMemo(() => {
if (disabled || (!icon && !checked)) return null
return (
<Box
alignItems="center"
bg={
checked
? rawColorToRGBA([56, 137, 255], 0.75)
: rawColorToRGBA([0, 0, 0], 0.25)
}
// bg={
// checked
// ? rawColorToRGBA([56, 137, 255], 0.75)
// : rawColorToRGBA([0, 0, 0], 0.25)
// }
color="white"
display="flex"
justifyContent="center"
>
<Box as={icon ?? <CheckSVG />} wh="40%" />
<Box
as={icon ?? CheckSVG}
// wh="40%"
/>
</Box>
)
}, [checked, disabled, icon])
Expand All @@ -157,9 +158,9 @@
/>
)}
<img
className={imgClassName}
style={imgStyle}
{...imgOtherProps}
// className={imgClassName}
// style={imgStyle}
// {...imgOtherProps}
alt={label}
decoding={decoding}
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const BackdropSurface = React.forwardRef<HTMLElement, BackdropSurfaceProp
className={backdropSurface({
entered: !$empty && $state === 'entered',
})}
height="100vh"
// height="100vh"
left="0"
overflow="hidden"
position="fixed"
Expand All @@ -24,8 +24,8 @@ export const BackdropSurface = React.forwardRef<HTMLElement, BackdropSurfaceProp
transitionDuration={300}
transitionProperty="all"
transitionTimingFunction="popIn"
width="100vw"
zIndex="999"
// width="100vw"
// zIndex="999"
/>
),
)
Expand Down
60 changes: 30 additions & 30 deletions components/src/components/atoms/Banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react'

import type { WithAlert } from './utils/getValueForAlert'
import { getValueForAlert } from './utils/getValueForAlert'

Check failure on line 4 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'getValueForAlert' is defined but never used
import { Typography } from '../Typography/Typography'

import { AlertSVG, CrossSVG, EthSVG, UpRightArrowSVG } from '../../../index'
import type { BoxProps } from '../Box/Box'
import { Box } from '../Box/Box'

type NativeDivProps = React.HTMLAttributes<HTMLDivElement>

Check failure on line 11 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'NativeDivProps' is defined but never used

type IconTypes = 'filledCircle' | 'normal' | 'none'

Expand All @@ -18,9 +18,9 @@
as?: 'a'
onDismiss?: () => void
actionIcon?: React.ReactNode
icon?: React.ReactNode
icon?: React.FC
iconType?: IconTypes
} & NativeDivProps
} & BoxProps

type WithIcon = {
icon?: React.ReactNode
Expand Down Expand Up @@ -56,14 +56,14 @@
$hasAction: boolean
}
const ContainerBox = React.forwardRef<HTMLElement, ContainerProps>(
({ $alert, $hasAction, ...props }, ref) => (

Check failure on line 59 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$alert' is defined but never used
<Box
alignItems={{ base: 'stretch', sm: 'center' }}
backgroundColor={{
base: getValueForAlert($alert, 'background'),
hover: getValueForAlert($alert, 'hover'),
}}
borderColor={getValueForAlert($alert, 'border')}
// backgroundColor={{
// base: getValueForAlert($alert, 'background'),
// hover: getValueForAlert($alert, 'hover'),
// }}
// borderColor={getValueForAlert($alert, 'border')}
borderRadius="2xLarge"
borderStyle="solid"
borderWidth="1x"
Expand All @@ -73,13 +73,13 @@
position="relative"
pr={$hasAction ? '8' : undefined}
ref={ref}
transform={{
base: 'translateY(0)',
hover: $hasAction ? 'translateY(-1px)' : 'translateY(0px)',
}}
// transform={{
// base: 'translateY(0)',
// hover: $hasAction ? 'translateY(-1px)' : 'translateY(0px)',
// }}
transitionDuration={150}
transitionProperty="all"
transitionTimingFunction="ease-in-out"
// transitionTimingFunction="ease-in-out"
width="full"
{...props}
/>
Expand All @@ -87,13 +87,13 @@
)

const IconBox = ({
$alert,

Check failure on line 90 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$alert' is defined but never used
...props
}: BoxProps & { $alert: NonNullableAlert }) => (
<Box
backgroundColor={getValueForAlert($alert, 'icon')}
// backgroundColor={getValueForAlert($alert, 'icon')}
borderRadius="full"
color={getValueForAlert($alert, 'svg')}
// color={getValueForAlert($alert, 'svg')}
flex={0}
flexBasis={{ base: '8', sm: '10' }}
height={{ base: '8', sm: '10' }}
Expand All @@ -103,13 +103,13 @@
)

const SVGBox = ({
$alert,

Check failure on line 106 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$alert' is defined but never used
...props
}: BoxProps & { $alert: NonNullableAlert }) => (
<Box
display="block"
height="full"
transform={$alert === 'info' ? 'scale(1)' : 'scale(0.5)'}
// transform={$alert === 'info' ? 'scale(1)' : 'scale(0.5)'}
width="full"
{...props}
/>
Expand All @@ -128,32 +128,32 @@
)

const ActionButtonIconBox = ({
$alert,

Check failure on line 131 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$alert' is defined but never used
$hasAction,

Check failure on line 132 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

'$hasAction' is defined but never used
...props
}: BoxProps & { $alert: NonNullableAlert, $hasAction: boolean }) => (
<Box
alignItems="center"
backgroundColor={{
base: getValueForAlert($alert, 'actionIcon'),
hover: getValueForAlert($alert, 'actionIconHover'),
}}
// backgroundColor={{
// base: getValueForAlert($alert, 'actionIcon'),
// hover: getValueForAlert($alert, 'actionIconHover'),
// }}
borderRadius="full"
color={{
base: getValueForAlert($alert, 'actionSvg'),
hover: getValueForAlert($alert, 'actionSvgHover'),
}}
// color={{
// base: getValueForAlert($alert, 'actionSvg'),
// hover: getValueForAlert($alert, 'actionSvgHover'),
// }}
cursor="pointer"
display="flex"
height="5"
justifyContent="center"
transform={{
base: 'translateY(0)',
hover: $hasAction ? 'translateY(-1px)' : 'translateY(0px)',
}}
// transform={{
// base: 'translateY(0)',
// hover: $hasAction ? 'translateY(-1px)' : 'translateY(0px)',
// }}
transitionDuration={150}
transitionProperty="all"
transitionTimingFunction="ease-in-out"
// transitionTimingFunction="ease-in-out"
width="5"
{...props}
/>
Expand All @@ -170,7 +170,7 @@
onDismiss,
}: Pick<BannerProps, 'alert' | 'onDismiss'> & { hasHref: boolean } & WithIcon) => {
if (onDismiss) {
const Icon = (icon || <CrossSVG />) as React.ReactElement
const Icon = (icon || CrossSVG) as React.FC
return (
<ActionButtonBox onClick={() => onDismiss()}>
<ActionButtonIconBox $alert={alert} $hasAction>
Expand All @@ -180,7 +180,7 @@
)
}
if (hasHref || icon) {
const Icon = (icon || <UpRightArrowSVG />) as React.ReactElement
const Icon = (icon || UpRightArrowSVG) as React.FC
return (
<ActionButtonBox as="div">
<ActionButtonIconBox $alert={alert} $hasAction={false}>
Expand Down Expand Up @@ -223,11 +223,11 @@
{...props}
$alert={alert}
$hasAction={hasAction}
as={asProp as any}

Check warning on line 226 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected any. Specify a different type
ref={ref}
>
<IconBox $alert={alert}>
<SVGBox $alert={alert} as={Icon as any} />

Check warning on line 230 in components/src/components/atoms/Banner/Banner.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected any. Specify a different type
</IconBox>
<Box
display="flex"
Expand Down
12 changes: 7 additions & 5 deletions components/src/components/atoms/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {
AllHTMLAttributes,
ElementType,
ReactElement } from 'react'
FunctionComponent,
ComponentClass,
} from 'react'
import React, {
forwardRef,
} from 'react'
Expand All @@ -18,11 +19,11 @@
>

export type BoxProps = Sprinkles &
HTMLProperties & { as?: ElementType | ReactElement<any> }
HTMLProperties & { as?: string | FunctionComponent<any> | ComponentClass<any, any> }

Check warning on line 22 in components/src/components/atoms/Box/Box.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected any. Specify a different type

Check warning on line 22 in components/src/components/atoms/Box/Box.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected any. Specify a different type

Check warning on line 22 in components/src/components/atoms/Box/Box.tsx

View workflow job for this annotation

GitHub Actions / Lint (18)

Unexpected any. Specify a different type

export const Box = forwardRef<HTMLElement, BoxProps >(
(
{ as = 'div', className, ...props },
{ as = 'div', className, children, ...props },
ref,
) => {
const atomProps: Record<string, unknown> = {}
Expand All @@ -37,12 +38,13 @@
}
}

const atomicCss = sprinkles(props)
const atomicCss = sprinkles(atomProps)

return React.createElement(as, {
className: clsx(atomicCss, className),
...nativeProps,
ref,
children,
})
},
)
Loading
Loading