-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(components): use the web animations api in the post-collapsible… (
#2042) … component --------- Co-authored-by: Philipp Gfeller <[email protected]>
- Loading branch information
1 parent
f74c966
commit 3b42032
Showing
16 changed files
with
129 additions
and
187 deletions.
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
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,22 @@ | ||
const collapseDuration = 350; | ||
const collapseEasing = 'ease'; | ||
const collapsedKeyframe: Keyframe = { height: '0', overflow: 'hidden' }; | ||
|
||
export const collapse = (el: HTMLElement): Animation => { | ||
const { height } = window.getComputedStyle(el); | ||
const expandedKeyframe: Keyframe = { height }; | ||
|
||
return el.animate( | ||
[expandedKeyframe, collapsedKeyframe], | ||
{ duration: collapseDuration, easing: collapseEasing, fill: 'forwards' }, | ||
); | ||
}; | ||
|
||
export const expand = (el: HTMLElement): Animation => { | ||
const expandedKeyframe: Keyframe = { height: `${el.scrollHeight}px` }; | ||
|
||
return el.animate( | ||
[collapsedKeyframe, expandedKeyframe], | ||
{ duration: collapseDuration, easing: collapseEasing, fill: 'forwards' }, | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
const fadeDuration = 200; | ||
const fadedOutKeyFrame = {opacity: '0'}; | ||
const fadedInKeyFrame = {opacity: '1'}; | ||
const fadedOutKeyframe: Keyframe = {opacity: '0'}; | ||
const fadedInKeyframe: Keyframe = {opacity: '1'}; | ||
|
||
export const fadeIn = (el: Element): Animation => el.animate( | ||
[ fadedOutKeyFrame, fadedInKeyFrame ], | ||
[ fadedOutKeyframe, fadedInKeyframe ], | ||
{ duration: fadeDuration } | ||
); | ||
|
||
export const fadeOut = (el: Element): Animation => el.animate( | ||
[ fadedInKeyFrame, fadedOutKeyFrame ], | ||
[ fadedInKeyframe, fadedOutKeyframe ], | ||
{ duration: fadeDuration } | ||
); |
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
3 changes: 3 additions & 0 deletions
3
packages/components/src/components/post-collapsible/heading-levels.ts
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,3 @@ | ||
export const HEADING_LEVELS = [1, 2, 3, 4, 5, 6] as const; | ||
|
||
export type HeadingLevel = typeof HEADING_LEVELS[number]; |
1 change: 0 additions & 1 deletion
1
packages/components/src/components/post-collapsible/post-collapsible.scss
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
Oops, something went wrong.