Skip to content

Commit 02ca583

Browse files
authored
refactor: global alert and expandable to use vanilla extract (#5530)
1 parent c79b4fb commit 02ca583

File tree

8 files changed

+315
-701
lines changed

8 files changed

+315
-701
lines changed

.changeset/strong-cameras-crash.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 `<GlobalAlert />` and `<Expandable />` to use vanilla extract

packages/ui/src/components/Expandable/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
exports[`expandable > renders correctly opened 1`] = `
44
<DocumentFragment>
5-
.emotion-0 {
6-
height: auto;
7-
}
8-
9-
.emotion-0[data-is-animated="true"] {
10-
-webkit-transition: max-height 300ms ease-out,opacity 300ms ease-out;
11-
transition: max-height 300ms ease-out,opacity 300ms ease-out;
12-
}
13-
14-
<div
5+
<div
156
data-testid="testing"
167
>
178
<div
18-
class="emotion-0 emotion-1"
9+
class="styles__mlltm91"
1910
data-is-animated="false"
11+
style="--mlltm90: 300ms;"
2012
>
2113
Sample Expandable
2214
</div>
@@ -26,22 +18,13 @@ exports[`expandable > renders correctly opened 1`] = `
2618

2719
exports[`expandable > renders correctly with animationDuration 1`] = `
2820
<DocumentFragment>
29-
.emotion-0 {
30-
height: auto;
31-
}
32-
33-
.emotion-0[data-is-animated="true"] {
34-
-webkit-transition: max-height 500ms ease-out,opacity 500ms ease-out;
35-
transition: max-height 500ms ease-out,opacity 500ms ease-out;
36-
}
37-
38-
<div
21+
<div
3922
data-testid="testing"
4023
>
4124
<div
42-
class="emotion-0 emotion-1"
25+
class="styles__mlltm91"
4326
data-is-animated="false"
44-
style="max-height: 0px; overflow: hidden;"
27+
style="--mlltm90: 500ms; max-height: 0px; overflow: hidden;"
4528
>
4629
Sample Expandable
4730
</div>
@@ -65,22 +48,13 @@ exports[`expandable > renders correctly with animationDuration set to 0 1`] = `
6548

6649
exports[`expandable > renders correctly with className 1`] = `
6750
<DocumentFragment>
68-
.emotion-0 {
69-
height: auto;
70-
}
71-
72-
.emotion-0[data-is-animated="true"] {
73-
-webkit-transition: max-height 300ms ease-out,opacity 300ms ease-out;
74-
transition: max-height 300ms ease-out,opacity 300ms ease-out;
75-
}
76-
77-
<div
51+
<div
7852
data-testid="testing"
7953
>
8054
<div
81-
class="test emotion-0 emotion-1"
55+
class="test styles__mlltm91"
8256
data-is-animated="false"
83-
style="max-height: 0px; overflow: hidden;"
57+
style="--mlltm90: 300ms; max-height: 0px; overflow: hidden;"
8458
>
8559
Sample Expandable
8660
</div>
@@ -90,22 +64,13 @@ exports[`expandable > renders correctly with className 1`] = `
9064

9165
exports[`expandable > renders correctly with default values 1`] = `
9266
<DocumentFragment>
93-
.emotion-0 {
94-
height: auto;
95-
}
96-
97-
.emotion-0[data-is-animated="true"] {
98-
-webkit-transition: max-height 300ms ease-out,opacity 300ms ease-out;
99-
transition: max-height 300ms ease-out,opacity 300ms ease-out;
100-
}
101-
102-
<div
67+
<div
10368
data-testid="testing"
10469
>
10570
<div
106-
class="emotion-0 emotion-1"
71+
class="styles__mlltm91"
10772
data-is-animated="false"
108-
style="max-height: 0px; overflow: hidden;"
73+
style="--mlltm90: 300ms; max-height: 0px; overflow: hidden;"
10974
>
11075
Sample Expandable
11176
</div>
@@ -115,22 +80,13 @@ exports[`expandable > renders correctly with default values 1`] = `
11580

11681
exports[`expandable > renders correctly with minHeight 1`] = `
11782
<DocumentFragment>
118-
.emotion-0 {
119-
height: auto;
120-
}
121-
122-
.emotion-0[data-is-animated="true"] {
123-
-webkit-transition: max-height 300ms ease-out,opacity 300ms ease-out;
124-
transition: max-height 300ms ease-out,opacity 300ms ease-out;
125-
}
126-
127-
<div
83+
<div
12884
data-testid="testing"
12985
>
13086
<div
131-
class="emotion-0 emotion-1"
87+
class="styles__mlltm91"
13288
data-is-animated="false"
133-
style="max-height: 5px; overflow: hidden;"
89+
style="--mlltm90: 300ms; max-height: 5px; overflow: hidden;"
13490
>
13591
Sample Expandable
13692
</div>

packages/ui/src/components/Expandable/index.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use client'
22

3-
import styled from '@emotion/styled'
3+
import { assignInlineVars } from '@vanilla-extract/dynamic'
44
import type { ReactNode } from 'react'
55
import { useEffect, useRef, useState } from 'react'
6+
import { animationDurationVar, expandable } from './styles.css'
67

78
const ANIMATION_DURATION = 300 // in ms
89

@@ -27,17 +28,6 @@ type ExpandableProps = {
2728
animationDuration?: number
2829
}
2930

30-
export const StyledExpandable = styled('div', {
31-
shouldForwardProp: prop => !['animationDuration'].includes(prop),
32-
})<{ animationDuration: number }>`
33-
&[data-is-animated="true"] {
34-
transition:
35-
max-height ${({ animationDuration }) => animationDuration}ms ease-out,
36-
opacity ${({ animationDuration }) => animationDuration}ms ease-out;
37-
}
38-
height: auto;
39-
`
40-
4131
const NoAnimationExpandable = ({
4232
children,
4333
opened,
@@ -137,15 +127,17 @@ export const AnimatedExpandable = ({
137127
}, [animationDuration, height, minHeight, opened, shouldBeAnimated])
138128

139129
return (
140-
<StyledExpandable
141-
animationDuration={animationDuration}
142-
className={className}
130+
<div
131+
className={`${className ? `${className} ` : ''}${expandable}`}
143132
data-is-animated={shouldBeAnimated && !isFirstRender.current}
144133
data-testid={dataTestId}
145134
ref={ref}
135+
style={assignInlineVars({
136+
[animationDurationVar]: `${animationDuration}ms`,
137+
})}
146138
>
147139
{children}
148-
</StyledExpandable>
140+
</div>
149141
)
150142
}
151143

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createVar, style } from '@vanilla-extract/css'
2+
3+
export const animationDurationVar = createVar()
4+
5+
export const expandable = style({
6+
selectors: {
7+
'&[data-is-animated="true"]': {
8+
transition: `
9+
max-height ${animationDurationVar} ease-out,
10+
opacity ${animationDurationVar} ease-out
11+
`,
12+
},
13+
},
14+
height: 'auto',
15+
})

0 commit comments

Comments
 (0)