-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(useHeightAnimation): add hook to make height (auto) animations e…
…asy (for internal use as of now)
- Loading branch information
1 parent
c18b021
commit 45495f7
Showing
5 changed files
with
415 additions
and
18 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
29 changes: 29 additions & 0 deletions
29
packages/dnb-design-system-portal/src/docs/uilib/helpers/hooks.md
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,29 @@ | ||
--- | ||
showTabs: true | ||
--- | ||
|
||
import { | ||
HeightAnimationExample, | ||
} from 'Docs/uilib/helpers/Examples' | ||
import SkipLinkExample from 'Docs/uilib/usage/accessibility/examples/skip-link-example.js' | ||
|
||
## Description | ||
|
||
These React Hooks are internally used in the components, and are with that a good choice when it comes to save bandwidth in the final production bundle. | ||
|
||
## `useHeightAnimation` | ||
|
||
In many places we want to animate the content in and out. The challenge is to never define a fixed height, because of an unknown content size and users' different font sizes. | ||
|
||
The `useHeightAnimation` hook takes an HTML Element, and animates it from 0 to the current content. When the animation is done, it sets the element's height to `auto`. | ||
|
||
The element animation is done with a CSS transition, e.g.: | ||
|
||
```css | ||
.animation-element { | ||
overflow: hidden; | ||
transition: height 1s var(--easing-default); | ||
} | ||
``` | ||
|
||
<HeightAnimationExample /> |
Oops, something went wrong.