Skip to content

Commit a016245

Browse files
committed
refactor(Chip): use vanilla extract (#5532)
1 parent 568c2df commit a016245

File tree

6 files changed

+133
-610
lines changed

6 files changed

+133
-610
lines changed

.changeset/slimy-boats-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": minor
3+
---
4+
5+
Refactor `<Chip />` to use vanilla extract

packages/ui/src/components/Chip/ChipContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import { createContext } from 'react'
66
type ContextType = {
77
isActive: boolean
88
disabled: boolean
9-
iconRef?: RefObject<HTMLButtonElement | null>
9+
iconRef?: RefObject<HTMLDivElement | HTMLButtonElement | null>
1010
}
1111
export const ChipContext = createContext<ContextType | undefined>(undefined)
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
'use client'
22

3-
import styled from '@emotion/styled'
43
import * as Icon from '@ultraviolet/icons'
4+
import type { RefObject } from 'react'
55
import { useContext } from 'react'
66
import type { PascalToCamelCaseWithoutSuffix } from 'src/types'
77
import { ChipContext } from './ChipContext'
8-
9-
const Container = styled.button`
10-
background: none;
11-
border: none;
12-
cursor: pointer;
13-
padding: 0;
14-
border-radius: ${({ theme }) => theme.radii.default};
15-
16-
&[data-has-onclick="true"][data-active="false"]:hover{
17-
background-color: ${({ theme }) => theme.colors.neutral.backgroundStrongHover};
18-
}
19-
20-
&[data-has-onclick="true"][data-active="true"]:hover{
21-
background-color: ${({ theme }) => theme.colors.primary.backgroundStrong};
22-
}
23-
24-
&[data-disabled="true"]{
25-
cursor: not-allowed;
26-
}
27-
`
8+
import { buttonContainer } from './styles.css'
289

2910
type IconType = PascalToCamelCaseWithoutSuffix<keyof typeof Icon, 'Icon'>
3011

@@ -57,27 +38,46 @@ export const ChipIcon = ({
5738
}Icon` as keyof typeof Icon
5839
]
5940

41+
if (onClick) {
42+
return (
43+
<button
44+
className={buttonContainer}
45+
data-active={isActive}
46+
data-disabled={disabled}
47+
data-has-onclick={!!onClick && !disabled}
48+
data-testid={dataTestId}
49+
onClick={event => {
50+
if (!disabled && onClick) {
51+
event.stopPropagation()
52+
onClick()
53+
}
54+
}}
55+
ref={iconRef as RefObject<HTMLButtonElement | null>}
56+
>
57+
<IconUsed
58+
disabled={disabled}
59+
prominence={isActive ? 'stronger' : 'default'}
60+
sentiment="neutral"
61+
size="small"
62+
/>
63+
</button>
64+
)
65+
}
66+
6067
return (
61-
<Container
62-
as={onClick ? 'button' : 'div'}
68+
<div
69+
className={buttonContainer}
6370
data-active={isActive}
6471
data-disabled={disabled}
65-
data-has-onclick={!!onClick && !disabled}
6672
data-testid={dataTestId}
67-
onClick={event => {
68-
if (!disabled && onClick) {
69-
event.stopPropagation()
70-
onClick()
71-
}
72-
}}
73-
ref={iconRef}
73+
ref={iconRef as RefObject<HTMLDivElement | null>}
7474
>
7575
<IconUsed
7676
disabled={disabled}
7777
prominence={isActive ? 'stronger' : 'default'}
7878
sentiment="neutral"
7979
size="small"
8080
/>
81-
</Container>
81+
</div>
8282
)
8383
}

0 commit comments

Comments
 (0)