Installations
npm install preact-transitioning
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
20.18.1
NPM Version
10.8.2
Score
75.7
Supply Chain
94
Quality
89.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Languages
TypeScript (89.38%)
JavaScript (10.62%)
Developer
Download Statistics
Total Downloads
269,134
Last Day
277
Last Week
1,483
Last Month
7,884
Last Year
59,575
GitHub Statistics
46 Stars
37 Commits
9 Forks
3 Watching
2 Branches
6 Contributors
Bundle Size
5.38 kB
Minified
2.04 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.5.2
Package Id
preact-transitioning@1.5.2
Unpacked Size
32.36 kB
Size
9.40 kB
File Count
13
NPM Version
10.8.2
Node Version
20.18.1
Publised On
28 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
269,134
Last day
-16.3%
277
Compared to previous day
Last week
-40%
1,483
Compared to previous week
Last month
7.4%
7,884
Compared to previous month
Last year
-17%
59,575
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
22
preact-transitioning
Exposes Preact components for easily implementing basic CSS animations and transitions.
Lightweight and fast implementation. Inspired by react-transition-group
and has almost the same API. Please take a look how it works.
Installation
npm i preact-transitioning
Demo
Usage
Transition Component
The Transition
component controls the mounting and unmounting of a component with transitions.
1import { Transition } from 'preact-transitioning' 2 3... 4 5<Transition 6 in={!hidden} 7 appear 8 exit={false} 9> 10 {(transitionState) => ( 11 <pre> 12 {JSON.stringify(transitionState)} 13 </pre> 14 )} 15</Transition>
CSSTransition Component
The CSSTransition
component applies CSS classes to animate components based on their state.
1import { CSSTransition } from 'preact-transitioning' 2 3... 4 5<CSSTransition 6 in={!hidden} 7 classNames="fade" 8> 9 <div> 10 Animated element 11 </div> 12</CSSTransition>
StyleTransition Component
The StyleTransition
component applies inline styles to animate components based on their state.
1import { StyleTransition } from 'preact-transitioning' 2 3... 4 5<StyleTransition 6 in={!hidden} 7 duration={300} 8 styles={{ 9 enter: { opacity: 0 }, 10 enterActive: { opacity: 1 }, 11 }} 12> 13 <div style={{ transition: 'opacity 300ms' }}> 14 Animated element 15 </div> 16</StyleTransition>
TransitionGroup Component
The TransitionGroup
component manages a set of transitions as a group.
1import { TransitionGroup } from 'preact-transitioning' 2 3... 4 5<TransitionGroup duration={300}> 6 {items.map((item) => ( 7 <CSSTransition 8 key={item.key} 9 classNames="fade" 10 > 11 <div> 12 {renderItem(item)} 13 </div> 14 </CSSTransition> 15 ))} 16</TransitionGroup>
Detecting transition end:
1<CSSTransition 2 in={!hidden} 3 classNames="fade" 4 addEndListener={(node, done) => { 5 node.addEventListener('transitionend', done, { once: true, capture: false }) 6 }} 7> 8 <div> 9 Animated element 10 </div> 11</CSSTransition>
Using event callbacks to animate height:
1<CSSTransition 2 in={!hidden} 3 classNames="fade" 4 onEnter={(node) => { 5 node.style.height = `${node.scrollHeight}px` 6 }} 7 onEntered={(node) => { 8 node.style.height = '' 9 }} 10 onExit={(node) => { 11 node.style.height = `${node.scrollHeight}px` 12 // force reflow 13 node.clientHeight 14 }} 15> 16 <div> 17 Animated element 18 </div> 19</CSSTransition>
API
Transition Props
1type TransitionProps = { 2 children: (transitionState: TransitionState, activePhase: Phase) => ComponentChildren 3 in?: boolean = false 4 appear?: boolean = false 5 enter?: boolean = true 6 exit?: boolean = true 7 duration?: number = 500 8 alwaysMounted?: boolean = false 9 onEnter?: (node?: Element | Text) => void 10 onEntering?: (node?: Element | Text) => void 11 onEntered?: (node?: Element | Text) => void 12 onExit?: (node?: Element | Text) => void 13 onExiting?: (node?: Element | Text) => void 14 onExited?: (node?: Element | Text) => void 15 addEndListener?: (node: Element | Text, done: () => void) => void 16}
The TransitionState
passed to the children function has the following structure:
1type TransitionState = { 2 appear: boolean 3 appearActive: boolean 4 appearDone: boolean 5 enter: boolean 6 enterActive: boolean 7 enterDone: boolean 8 exit: boolean 9 exitActive: boolean 10 exitDone: boolean 11}
CSSTransition Props
1type CSSTransitionProps = TransitionProps & { 2 children: VNode<any> 3 classNames: string | { 4 appear?: string 5 appearActive?: string 6 appearDone?: string 7 enter?: string 8 enterActive?: string 9 enterDone?: string 10 exit?: string 11 exitActive?: string 12 exitDone?: string 13 } 14}
If classNames
is a string, then the computed className will be suffixed according to the current transition state. For example, if you pass the string "fade"
as classNames
, then fade-appear-active
className will be applied during the appearActive
phase.
If classNames
is an object, then the final className will be taken from that object according to the current transition state. For example, when the element enters, the enterActive
property will be used as className.
StyleTransition Props
1type StyleTransitionProps = TransitionProps & { 2 children: VNode<any> 3 styles: { 4 appear?: object 5 appearActive?: object 6 appearDone?: object 7 enter?: object 8 enterActive?: object 9 enterDone?: object 10 exit?: object 11 exitActive?: object 12 exitDone?: object 13 } 14}
The styles
prop is used to compute inline styles of the element according to the current transition state. For example, when the element enters, enterActive
styles will be applied.
TransitionGroup Props
1type TransitionGroupProps = { 2 children: ComponentChildren 3 appear?: boolean 4 enter?: boolean 5 exit?: boolean 6 duration?: number 7}
License
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build-deploy-docs.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-deploy-docs.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/fakundo/preact-transitioning/build-deploy-docs.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-deploy-docs.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/fakundo/preact-transitioning/build-deploy-docs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/fakundo/preact-transitioning/publish.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/fakundo/preact-transitioning/publish.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Reason
25 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More