Skip to content

Commit

Permalink
remove styled-components completely from thorin
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Oct 17, 2023
1 parent ba82748 commit b2f0211
Show file tree
Hide file tree
Showing 71 changed files with 824 additions and 1,742 deletions.
3 changes: 3 additions & 0 deletions components/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const config: Config.InitialOptions = {
roots: ['<rootDir>'],
testEnvironment: 'jsdom',
testRegex: '.*\\.test\\.(ts|tsx)$',
transform: {
'\\.css\\.ts$': '@vanilla-extract/jest-transform',
},
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
Expand Down
7 changes: 2 additions & 5 deletions components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@types/rimraf": "^3.0.2",
"@types/styled-components": "^5",
"@types/testing-library__jest-dom": "^5.14.1",
"@vanilla-extract/css": "^1.13.0",
"@vanilla-extract/css-utils": "^0.1.3",
Expand All @@ -68,12 +67,11 @@
"@vanilla-extract/recipes": "^0.5.0",
"@vanilla-extract/sprinkles": "^1.6.1",
"@vanilla-extract/vite-plugin": "^3.9.0",
"babel-plugin-styled-components": "^2.0.6",
"@vanilla-extract/jest-transform": "^1.1.1",
"deepmerge": "^4.2.2",
"esbuild-darwin-arm64": "^0.14.27",
"glob": "^7.2.0",
"jest": "^27.3.1",
"jest-styled-components": "^7.0.8",
"jest-watch-typeahead": "^1.0.0",
"rainbow-sprinkles": "0.17.0",
"react": "^17.0.2",
Expand All @@ -92,7 +90,6 @@
"peerDependencies": {
"react": "^17",
"react-dom": "^17",
"react-transition-state": "^1.1.4",
"styled-components": "^5.3.3"
"react-transition-state": "^1.1.4"
}
}
14 changes: 4 additions & 10 deletions components/src/components/atoms/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import * as React from 'react'

import { ThemeProvider } from 'styled-components'

import { cleanup, render, screen, waitFor } from '@/test'

import { lightTheme } from '@/src/tokens'

import { Avatar } from './Avatar'

describe('<Avatar />', () => {
afterEach(cleanup)

it('renders', async () => {
render(
<ThemeProvider theme={lightTheme}>
<Avatar
label="Avatar"
src="https://images.mirror-media.xyz/publication-images/H-zIoEYWk4SpFkljJiwB9.png"
/>
</ThemeProvider>,
<Avatar
label="Avatar"
src="https://images.mirror-media.xyz/publication-images/H-zIoEYWk4SpFkljJiwB9.png"
/>,
)
await waitFor(() => expect(screen.getByRole(/img/i)).toBeInTheDocument())
})
Expand Down
121 changes: 46 additions & 75 deletions components/src/components/atoms/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,54 @@
import * as React from 'react'
import styled, { css } from 'styled-components'

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

import { Box, BoxProps } from '../Box'

type NativeImgAttributes = React.ImgHTMLAttributes<HTMLImageElement>

type Shape = 'circle' | 'square'

interface Container {
$shape: Shape
$noBorder?: boolean
}

const Container = styled.div<Container>(
({ theme, $shape, $noBorder }) => css`
${() => {
switch ($shape) {
case 'circle':
return css`
border-radius: ${theme.radii.full};
&:after {
border-radius: ${theme.radii.full};
}
`
case 'square':
return css`
border-radius: ${theme.radii['2xLarge']}
&:after {
border-radius: ${theme.radii['2xLarge']}
}
`
default:
return css``
}
}}
${!$noBorder &&
css`
&::after {
box-shadow: ${theme.shadows['-px']} ${theme.colors.backgroundSecondary};
content: '';
inset: 0;
position: absolute;
}
`}
background-color: ${theme.colors.backgroundSecondary};
width: 100%;
padding-bottom: 100%;
> * {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
overflow: hidden;
position: relative;
`,
const Container = ({ $shape, ...props }: BoxProps & Container) => (
<Box
{...props}
backgroundColor="$backgroundSecondary"
borderRadius={$shape === 'circle' ? '$full' : '$2xLarge'}
overflow="hidden"
paddingBottom="$full"
position="relative"
width="$full"
/>
)

const placeholderStyles = ({
disabled,
url,
}: {
disabled: boolean
url?: string
}) =>
rainbowSprinkles({
filter: disabled ? 'grayscale(1)' : undefined,
backgroundColor: url || '$blueGradient',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
height: '100%',
})
type PlaceholderProps = {
$disabled: boolean
$url?: string
}
const Placeholder = ({
$disabled,
$url,
...props
}: PlaceholderProps & BoxProps) => (
<Box
alignItems="center"
background={$url || '$blueGradient'}
display="flex"
filter={$disabled ? 'grayscale(1)' : 'unset'}
height="100%"
justifyContent="center"
position="absolute"
width="100%"
{...props}
/>
)

export type Props = {
/** Accessibility text. */
label: string
/** If true, removes the border around the avatar. */
noBorder?: boolean
/** Uses tokens space settings to set the size */
src?: NativeImgAttributes['src']
/** The shape of the avatar. */
Expand All @@ -99,7 +63,6 @@ export type Props = {

export const Avatar = ({
label,
noBorder = false,
shape = 'circle',
src,
placeholder,
Expand Down Expand Up @@ -137,8 +100,13 @@ export const Avatar = ({

const isImageVisible = showImage && !!src

const imgProps = rainbowSprinkles({
const {
className: imgClassName,
style: imgStyle,
otherProps: imgOtherProps,
} = rainbowSprinkles({
display: isImageVisible ? 'block' : 'none',
position: 'absolute',
height: '100%',
objectFit: 'cover',
width: '100%',
Expand All @@ -147,16 +115,19 @@ export const Avatar = ({
})

return (
<Container $noBorder={!showImage || noBorder} $shape={shape}>
<Container $shape={shape}>
{overlay}
{!isImageVisible && (
<div
{...placeholderStyles({ disabled, url: placeholder })}
<Placeholder
$disabled={disabled}
$url={placeholder}
aria-label={label}
/>
)}
<img
{...imgProps}
className={imgClassName}
style={imgStyle}
{...imgOtherProps}
alt={label}
decoding={decoding}
ref={ref}
Expand Down
53 changes: 22 additions & 31 deletions components/src/components/atoms/BackdropSurface/BackdropSurface.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
import type { TransitionState } from 'react-transition-state'
import * as React from 'react'

import styled, { css } from 'styled-components'
import type { TransitionState } from 'react-transition-state'

export const BackdropSurface = styled.div<{
$state: TransitionState
$empty: boolean
}>(
({ theme, $state, $empty }) => css`
width: 100vw;
height: 100vh;
position: fixed;
overflow: hidden;
z-index: 999;
top: 0;
left: 0;
transition: ${theme.transitionDuration['300']} all
${theme.transitionTimingFunction.popIn};
import { backdropSurface } from './styles.css'
import { Box, BoxProps } from '../Box'

${!$empty && $state === 'entered'
? css`
background-color: rgba(0, 0, 0, ${theme.opacity.overlayFallback});
type Props = { $state: TransitionState; $empty: boolean } & BoxProps

@supports (-webkit-backdrop-filter: none) or (backdrop-filter: none) {
backdrop-filter: blur(16px);
background-color: rgba(0, 0, 0, ${theme.opacity.overlay});
}
`
: css`
background-color: rgba(0, 0, 0, 0);
@supports (-webkit-backdrop-filter: none) or (backdrop-filter: none) {
backdrop-filter: blur(0px);
}
`}
`,
export const BackdropSurface = ({ $empty, $state, ...props }: Props) => (
<Box
{...props}
className={backdropSurface({ entered: !$empty && $state === 'entered' })}
height="100vh"
left="$0"
overflow="hidden"
position="fixed"
top="$0"
transitionDuration="$300"
transitionProperty="all"
transitionTimingFunction="$popIn"
width="100vw"
zIndex="999"
/>
)

BackdropSurface.displayName = 'BackdropSurface'
25 changes: 25 additions & 0 deletions components/src/components/atoms/BackdropSurface/styles.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { recipe } from '@vanilla-extract/recipes'

export const backdropSurface = recipe({
variants: {
entered: {
true: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
'@supports': {
'(-webkit-backdrop-filter: none) or (backdrop-filter: none)': {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
backdropFilter: 'blur(16px)',
},
},
},
false: {
backgroundColor: 'rgba(0, 0, 0, 0)',
'@supports': {
'(-webkit-backdrop-filter: none) or (backdrop-filter: none)': {
backdropFilter: 'blur(0px)',
},
},
},
},
},
})
12 changes: 3 additions & 9 deletions components/src/components/atoms/Banner/Banner.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import * as React from 'react'

import { ThemeProvider } from 'styled-components'

import { cleanup, render, screen } from '@/test'

import { lightTheme } from '@/src/tokens'

import { Banner } from './Banner'

describe('<Banner />', () => {
afterEach(cleanup)

it('renders', () => {
render(
<ThemeProvider theme={lightTheme}>
<Banner alert="warning" title="Title">
Message
</Banner>
</ThemeProvider>,
<Banner alert="warning" title="Title">
Message
</Banner>,
)
expect(screen.getByText('Title')).toBeInTheDocument()
expect(screen.getByText('Message')).toBeInTheDocument()
Expand Down
10 changes: 1 addition & 9 deletions components/src/components/atoms/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import * as React from 'react'

import { ThemeProvider } from 'styled-components'

import { cleanup, render, screen } from '@/test'

import { lightTheme } from '@/src/tokens'

import { Button } from './Button'

describe('<Button />', () => {
afterEach(cleanup)

it('renders', () => {
render(
<ThemeProvider theme={lightTheme}>
<Button>Connect Wallet</Button>
</ThemeProvider>,
)
render(<Button>Connect Wallet</Button>)
expect(screen.getByText(/connect/i)).toBeInTheDocument()
})
})
1 change: 1 addition & 0 deletions components/src/components/atoms/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const ButtonBox = React.forwardRef<
borderColor={{
base: getValueForColourStyle($colorStyle, 'border'),
disabled: getValueForColourStyle('disabled', 'border'),
hover: getValueForColourStyle($colorStyle, 'hover'),
}}
borderRadius={['circle', 'rounded'].includes($shape) ? '$full' : '$large'}
borderStyle="solid"
Expand Down
Loading

0 comments on commit b2f0211

Please sign in to comment.