Skip to content

Implement keyframes function and add animation prop support #122

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged

Implement keyframes function and add animation prop support #122

merged 1 commit into from
Nov 15, 2022

Conversation

brandongregoryscott
Copy link
Contributor

@brandongregoryscott brandongregoryscott commented Nov 12, 2022

This PR implements the ability to generate keyframe styles that are injected into the stylesheet and adds support for animation-related props. This backfills the last bit of functionality so we can migrate Evergreen off glamor! The API is very similar to the current glamor function. (see example in Toast.js)

Results from the master branch

3,696 ops/sec ±3.74% (54 runs sampled)
3,702 ops/sec ±4.95% (54 runs sampled)
3,662 ops/sec ±4.45% (55 runs sampled)
3,794 ops/sec ±4.02% (54 runs sampled)
3,845 ops/sec ±4.43% (54 runs sampled)
3,711 ops/sec ±4.30% (53 runs sampled)
3,841 ops/sec ±4.08% (54 runs sampled)
3,696 ops/sec ±4.06% (55 runs sampled)
3,776 ops/sec ±3.95% (56 runs sampled)
3,716 ops/sec ±3.95% (56 runs sampled)

3743.9 ops/sec avg

Results from the add-keyframes branch

3,651 ops/sec ±4.61% (52 runs sampled)
3,679 ops/sec ±4.54% (52 runs sampled)
3,633 ops/sec ±4.02% (55 runs sampled)
3,703 ops/sec ±3.91% (55 runs sampled)
3,709 ops/sec ±3.75% (55 runs sampled)
3,612 ops/sec ±4.19% (56 runs sampled)
3,666 ops/sec ±3.91% (55 runs sampled)
3,605 ops/sec ±7.42% (52 runs sampled)
3,655 ops/sec ±3.87% (55 runs sampled)
3,660 ops/sec ±4.04% (55 runs sampled)

3657.3 ops/sec

Demo of the keyframes and animation functionality via Storybook:
ezgif com-gif-maker (1)

ezgif com-gif-maker (2)

@@ -133,6 +142,7 @@ All of these CSS properties are supported. You can pass either a string or a num
- `clear`
- `color`
- `columnGap`
- `content`
Copy link
Contributor Author

@brandongregoryscott brandongregoryscott Nov 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After pulling in this change to Evergreen locally and swapping out glamor, the Overlay component wasn't showing the transparent grey background due to the missing content: ""; rule (https://github.com/segmentio/evergreen/blob/master/src/overlay/src/Overlay.js#L54). Since this isn't directly related to animations/keyframes, I can revert this change and make a separate PR for it if desired.

@brandongregoryscott brandongregoryscott marked this pull request as ready for review November 12, 2022 22:43
Copy link
Contributor

@dlasky dlasky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

}
})

const AnimatedBox = () => <Box animation={`${openAnimation} 240ms cubic-bezier(0.175, 0.885, 0.320, 1.175)`} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@@ -0,0 +1,110 @@
import { BoxCssProps, CssProps } from './enhancers'

export type KeyframesPercentageKey =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want to consider something like this?

type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
  ? Acc[number]
  : Enumerate<N, [...Acc, Acc['length']]>

type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>

type T = IntRange<20, 300>

requires TS 4.5 though (from SO)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know 😢 That was the first thing I looked into bc I didn't want to type out 0-100 manually 😂 (ended up running new Array(100).fill(null).map((_, i) => i) in a repl to enumerate all of the values) We'll have to give this repo some love and upgrade TS next!

@brandongregoryscott brandongregoryscott merged commit ed1e813 into segmentio:master Nov 15, 2022
@brandongregoryscott brandongregoryscott deleted the add-keyframes branch November 15, 2022 15:24
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants