-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hiccup-css): add animation(), add test & update readme
- Loading branch information
1 parent
3b3e503
commit aac8b6f
Showing
4 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { at_keyframes } from "./keyframes"; | ||
|
||
export interface AnimationOpts { | ||
delay: string; | ||
direction: "unset" | "inherit" | "initial" | "normal" | "reverse" | "alternate" | "alternate-reverse"; | ||
duration: string; | ||
"fill-mode": "none" | "forwards" | "backwards" | "both"; | ||
"iteration-count": number; | ||
"play-state": "unset" | "inherit" | "initial" | "paused" | "running"; | ||
"timing-function": string; | ||
} | ||
|
||
/** | ||
* Defines new `@keyframes` with given `id` and creates related class of | ||
* same name to configure given animation `opts`. Only the `duration` | ||
* option is given a default value (250ms), all others are optional. | ||
* | ||
* ``` | ||
* css( | ||
* animation( | ||
* "fadein", | ||
* { delay: "0.5s" }, | ||
* { opacity: 0 }, | ||
* { opacity: 1 } | ||
* ) | ||
* ); | ||
* ``` | ||
* | ||
* ```css | ||
* @keyframes fadein { | ||
* 0% { | ||
* opacity: 0; | ||
* } | ||
* 100% { | ||
* opacity: 1; | ||
* } | ||
* } | ||
* | ||
* .fadein { | ||
* animation-duration: 250ms; | ||
* animation-name: fadein; | ||
* animation-delay: 0.5s; | ||
* } | ||
* ``` | ||
* | ||
* @param id | ||
* @param opts | ||
* @param keyframes | ||
*/ | ||
export const animation = | ||
(id: string, opts: Partial<AnimationOpts>, ...keyframes: any) => { | ||
opts = <any>{ | ||
duration: "250ms", | ||
name: id, | ||
...opts | ||
}; | ||
return [ | ||
at_keyframes.apply(null, [id, ...keyframes]), | ||
[ | ||
`.${id}`, | ||
Object.keys(opts).reduce((acc, k) => (acc[`animation-${k}`] = opts[k], acc), {}) | ||
] | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters