Skip to content

Commit 2974892

Browse files
authored
refactor: animations (#5766)
* feat: animations vanilla extract * fix: redo animations
1 parent 7020d50 commit 2974892

File tree

14 files changed

+944
-316
lines changed

14 files changed

+944
-316
lines changed

.changeset/moody-carrots-drive.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
"@ultraviolet/ui": major
3+
---
4+
5+
**BREAKING CHANGE** Remove all emotion animation, replace with vanilla-extract animation by default.
6+
```js
7+
import { fadeIn } from '@ultraviolet/ui' // vanilla-extract animation
8+
```
9+
10+
To use animation in another context, add `Default` at the end of the animation name:
11+
```js
12+
import { fadeInDefault } from "@ultraviolet/ui"
13+
````
14+
This returns a string that can be used in many different places.
15+
1. **Emotion**: create the keyframe then use it:
16+
```js
17+
import { fadeInDefault } from "@ultraviolet/ui"
18+
import { keyframes } from '@emotion/react'
19+
20+
const fadeInEmotion = keyframes`${fadeInDefault}`
21+
const StyledDiv = styled.div`
22+
animation: ${fadeInEmotion} 1s ease infinite;`
23+
```
24+
25+
2. Vanilla CSS: simply add the name of the animation you want to use as a className.
26+
```js
27+
const MyComponent = () => <div className="fadeIn">Hello World!</div>
28+
```
29+
30+
To customize the animation, you must overrule the default settings:
31+
```js
32+
const MyComponent = () => <div className="fadeIn" style={{ animationDuration: "300ms" }}>Hello World!</div>
33+
```

packages/plus/src/components/EstimateCost/Components/components.css.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { theme } from '@ultraviolet/themes'
2-
import { zoomInVanillaExtract } from '@ultraviolet/ui'
2+
import { zoomIn } from '@ultraviolet/ui'
33
import { createVar, style } from '@vanilla-extract/css'
44
import { recipe } from '@vanilla-extract/recipes'
55

@@ -40,7 +40,7 @@ export const estimateCostItemResourceName = recipe({
4040
variants: {
4141
animated: {
4242
true: {
43-
animation: `800ms ${zoomInVanillaExtract}`,
43+
animation: `800ms ${zoomIn}`,
4444
},
4545
},
4646
},
@@ -66,7 +66,7 @@ export const estimateCostResourceName = recipe({
6666
},
6767
isAnimated: {
6868
true: {
69-
animation: `${zoomInVanillaExtract} 800ms`,
69+
animation: `${zoomIn} 800ms`,
7070
},
7171
},
7272
},

packages/plus/src/components/Navigation/components/items.css.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { theme } from '@ultraviolet/themes'
22
import { style, styleVariants } from '@vanilla-extract/css'
33
import { ANIMATION_DURATION } from '../constants'
44
import { shrinkHeight } from '../animations.css'
5-
import { fadeInVanillaExtract } from '@ultraviolet/ui'
5+
import { fadeIn } from '@ultraviolet/ui'
66
import { recipe } from '@vanilla-extract/recipes'
77

88
export const navigationItemMenuContainer = style({ width: 180 })
@@ -236,10 +236,10 @@ export const navigationItemPinnedButton = style({
236236

237237
export const navigationItemAnimatedIcon = styleVariants({
238238
expand: {
239-
animation: `${fadeInVanillaExtract} ${ANIMATION_DURATION}ms ease-in-out`,
239+
animation: `${fadeIn} ${ANIMATION_DURATION}ms ease-in-out`,
240240
},
241241
collapse: {
242-
animation: `${fadeInVanillaExtract} ${ANIMATION_DURATION}ms ease-in-out reverse`,
242+
animation: `${fadeIn} ${ANIMATION_DURATION}ms ease-in-out reverse`,
243243
},
244244
})
245245

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Meta } from '@storybook/addon-docs/blocks'
2+
import Colors from '../components/Colors'
3+
4+
<Meta title="Guides/Animations" />
5+
6+
# Ultraviolet animations
7+
Ultraviolet provides a set of ready-to-use animations, each available in three formats to suit different styling approaches.
8+
9+
## Vanilla Extract
10+
Use the animation directly in `vanilla-extract` styles:
11+
```js
12+
// styles.css.ts
13+
import { fadeIn } from '@ultraviolet/ui' // vanilla-extract animation
14+
import { style } from '@vanilla-extract/css'
15+
16+
export const myStyle = style({
17+
animation: `${fadeIn} 0.2s ease-in-out`,
18+
})
19+
```
20+
21+
## CSS-in-JS
22+
For CSS-in-JS libraries like Emotion, import the `Default` version of the animation, which returns a keyframe string.
23+
24+
Example with **Emotion**: create the keyframe then use it:
25+
```js
26+
import { fadeInDefault } from "@ultraviolet/ui"
27+
import { keyframes } from '@emotion/react'
28+
29+
const fadeInEmotion = keyframes`${fadeInDefault}`
30+
31+
const StyledDiv = styled.div`
32+
animation: ${fadeInEmotion} 1s ease infinite;
33+
`
34+
```
35+
36+
## Vanilla CSS
37+
Apply the animation by using the class name with the `_uv` suffix:
38+
39+
```js
40+
const MyComponent = () => <div className="fadeIn_uv">Hello World!</div>
41+
```
42+
43+
To customize animation properties like duration or timing, override them inline:
44+
```js
45+
const MyComponent = () => <div className="fadeIn" style={{ animationDuration: "300ms" }}>Hello World!</div>
46+
```
47+
48+
49+
## List
50+
- bounce
51+
- fadeIn
52+
- fadeOut
53+
- flash
54+
- ping
55+
- pulse
56+
- quickScaleDown
57+
- scaleBack
58+
- scaleDown
59+
- scaleForward
60+
- scaleUp
61+
- sketchIn
62+
- sketchOut
63+
- slideDownLarge
64+
- slideFromBottom
65+
- slideFromLeft
66+
- slideFromRight
67+
- slideFromTop
68+
- slideToBottom
69+
- slideToLeft
70+
- slideToRight
71+
- slideToTop
72+
- slideUpLarge
73+
- unfoldIn
74+
- unfoldOut
75+
- zoomIn
76+
- zoomOut

packages/ui/src/components/ActionBar/styles.css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { theme } from '@ultraviolet/themes'
2-
import { fadeInVanillaExtract } from '../../utils'
2+
import { fadeIn } from '../../utils'
33
import { createVar, style } from '@vanilla-extract/css'
44

55
export const rankActionBar = createVar()
@@ -10,7 +10,7 @@ export const stackActionBar = style({
1010
})
1111

1212
export const actionBar = style({
13-
animation: `${fadeInVanillaExtract} 0.2s ease-in-out`,
13+
animation: `${fadeIn} 0.2s ease-in-out`,
1414
backgroundColor: theme.colors.other.elevation.background.fixed,
1515
borderRadius: theme.radii.default,
1616
boxShadow: `${theme.shadows.fixed[0]}, ${theme.shadows.fixed[1]}`,

packages/ui/src/components/Modal/styles.css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { theme } from '@ultraviolet/themes'
22
import { createVar, style } from '@vanilla-extract/css'
33
import { recipe } from '@vanilla-extract/recipes'
44
import { MODAL_PLACEMENT, MODAL_WIDTH } from './constants'
5-
import { slideFromBottomVanillaExtract } from '../../utils'
5+
import { slideFromBottom } from '../../utils'
66

77
export const topModal = createVar()
88
export const positionModal = createVar()
@@ -96,7 +96,7 @@ export const modal = recipe({
9696
},
9797
animation: {
9898
true: {
99-
animation: `${slideFromBottomVanillaExtract} 0.3s ease-in-out forwards`,
99+
animation: `${slideFromBottom} 0.3s ease-in-out forwards`,
100100
},
101101
},
102102
positivePosition: {

packages/ui/src/components/Status/styles.css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { theme } from '@ultraviolet/themes'
22
import { recipe } from '@vanilla-extract/recipes'
3-
import { pingVanillaExtract } from '../../utils'
3+
import { ping } from '../../utils'
44
import { SENTIMENTS } from './constant'
55

66
const HEIGHT = '10px'
@@ -39,7 +39,7 @@ export const animatedCircleStatus = recipe({
3939
...baseCircle,
4040
position: 'absolute',
4141
opacity: 0.75,
42-
animation: `${pingVanillaExtract} 1.1s cubic-bezier(0, 0, 0.2, 1) infinite`,
42+
animation: `${ping} 1.1s cubic-bezier(0, 0, 0.2, 1) infinite`,
4343
},
4444
variants: {
4545
sentiment: sentimentsCircleStatus,

packages/ui/src/index.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './utils/animations/animations.css'
2+
13
// eslint-disable-next-line no-restricted-syntax
24
export * from './components'
35
export type { UltravioletUITheme } from './theme'
@@ -11,38 +13,61 @@ export {
1113
export {
1214
Breakpoint,
1315
bounce,
16+
bounceDefault,
1417
down,
1518
fadeIn,
16-
fadeInVanillaExtract,
19+
fadeInDefault,
1720
fadeOut,
21+
fadeOutDefault,
1822
flash,
23+
flashDefault,
1924
getUUID,
2025
normalize,
2126
ping,
22-
pingVanillaExtract,
27+
pingDefault,
2328
pulse,
29+
pulseDefault,
2430
quickScaleDown,
31+
quickScaleDownDefault,
2532
scaleBack,
33+
scaleBackDefault,
2634
scaleDown,
35+
scaleDownDefault,
2736
scaleForward,
37+
scaleForwardDefault,
2838
scaleUp,
39+
scaleUpDefault,
2940
sketchIn,
41+
sketchInDefault,
3042
sketchOut,
43+
sketchOutDefault,
3144
slideDownLarge,
45+
slideDownLargeDefault,
3246
slideFromBottom,
33-
slideFromBottomVanillaExtract,
47+
slideFromBottomDefault,
3448
slideFromLeft,
49+
slideFromLeftDefault,
3550
slideFromRight,
51+
slideFromRightDefault,
3652
slideFromTop,
53+
slideFromTopDefault,
3754
slideToBottom,
55+
slideToBottomDefault,
3856
slideToLeft,
57+
slideToLeftDefault,
3958
slideToRight,
59+
slideToRightDefault,
4060
slideToTop,
61+
slideToTopDefault,
4162
slideUpLarge,
63+
slideUpLargeDefault,
4264
unfoldIn,
65+
unfoldInDefault,
4366
unfoldOut,
67+
unfoldOutDefault,
4468
up,
4569
zoomIn,
46-
zoomInVanillaExtract,
70+
zoomInDefault,
4771
zoomOut,
72+
zoomOutDefault,
4873
} from './utils'

packages/ui/src/utils/animationVanillaExtract.css.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)