
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
animation-library-test-abdullah-altun
Advanced tools
React animation library using SCSS and CSS Custom Properties
A lightweight, performant, and customizable animation library for React applications, powered by SCSS and CSS Custom Properties. Easily add entrance animations to your components.
<Animate>
component or the flexible useAnimation
hook.@use
, @forward
) for defining animations. CSS Custom Properties allow runtime adjustments via React props.slide
, rotate
, and bounce
respect direction based on prop values (distance
, degrees
, axis
).transform
, opacity
).prefers-reduced-motion
.Install the library:
npm install animation-library-test-abdullah-altun
# or
yarn add animation-library-test-abdullah-altun
Import Styles (Recommended: Compiled CSS):
In your project's global CSS file (e.g., src/app/globals.css
for Next.js):
/* src/app/globals.css */
@import "animation-library-test-abdullah-altun/dist/styles.css";
Ensure this global CSS file is imported in your root layout/app component.
Use in your Client Component:
Wrap the element you want to animate with the <Animate>
component.
"use client"; // Necessary if this component isn't already client-side
import { Animate } from "animation-library-test-abdullah-altun";
// Ensure styles are imported globally as shown in Step 2
function MyAnimatedPage() {
return (
<div>
<Animate type="fade" duration={0.8}>
<h2>Fade In Title</h2>
</Animate>
<Animate type="slide" distance={-100} axis="x" delay={0.2}>
<p>Slides in from the left.</p>
</Animate>
</div>
);
}
Method 1: Importing Compiled CSS (Recommended & Most Compatible)
This is the best approach for all projects, especially if you're using plain CSS for global styles (e.g., globals.css
in Next.js) or have an older Sass setup.
In your project's global CSS file (e.g., src/app/globals.css
for Next.js App Router):
/* src/app/globals.css */
@import "animation-library-test-abdullah-altun/dist/styles.css";
/* Your other global styles */
Ensure this global CSS file is imported in your root layout or app component (e.g., src/app/layout.tsx
or src/pages/_app.tsx
in Next.js).
// src/app/layout.tsx (Next.js App Router)
import "./globals.css"; // Or your global CSS file name
export default function RootLayout({ children }) {
/* ... */
}
With this method, animation behavior is controlled by props on the React components, which set CSS Custom Properties. SCSS variable customization is not applicable here.
Method 2: For Modern SCSS Users (Using @use
)
If your project uses a modern Sass compiler that supports the @use
rule (Dart Sass 1.23+), you can integrate the library's SCSS source for more direct SCSS variable configuration. This method will not produce @import
deprecation warnings.
Ensure you have a compatible sass
version installed in your project:
npm install sass
# or
yarn add sass
In your main global SCSS file (e.g., src/app/globals.scss
):
/* src/app/globals.scss */
// Configure SCSS variables using the `with` keyword:
@use "animation-library-test-abdullah-altun/styles" with (
$animation-duration: 0.7s,
// SCSS fallback for animation duration
$default-slide-distance: 80px,
// SCSS fallback for slide distance
// ... other configurable variables from the library's _variables.scss
);
// If no SCSS variable configuration is needed, simply:
// @use "animation-library-test-abdullah-altun/styles";
/* Your other global styles */
Ensure this global SCSS file is imported in your root layout or app component.
Note: Attempting to use the older @import "animation-library-test-abdullah-altun/styles/main.scss";
on the library's SCSS source may not work as expected with modern Sass compilers, as the library now uses @forward
and @use
internally. The pre-compiled CSS or the @use
rule are the supported methods for integrating styles.
<Animate>
ComponentThe <Animate>
component is the easiest way to apply animations. Remember to use it within a Client Component (e.g., marked with "use client";
in Next.js App Router).
The <Animate>
component wraps its children in an element (default div
, configurable with as
prop) and applies an animated
CSS class to this wrapper, along with specific animation classes (e.g., animate-fade
, animate-slide-x-positive
).
"use client";
import { Animate } from "animation-library-test-abdullah-altun";
function MyComponent() {
return (
<div>
<Animate type="fade" duration={0.8}>
<h2>Fade In Title</h2>
</Animate>
<Animate type="slide" distance={-100} axis="x" delay={0.2}>
<p>Slides in from the left (distance is negative).</p>
</Animate>
<Animate type="slide" distance={75} axis="y" delay={0.4}>
<p>Slides down from above (distance is positive, axis y).</p>
</Animate>
<Animate type="bounce" distance={25} easing="ease-in-out">
<button>Bounce Me Up (distance positive)</button>
</Animate>
<Animate type="scale" scale={0.5} duration={0.4}>
<span>Scale In (starts at 50% size)</span>
</Animate>
<Animate type="rotate" degrees={-90} delay={0.5}>
<div>Rotate -90 degrees (Counter-Clockwise)</div>
</Animate>
<Animate type="rotate" degrees={{ start: 45, end: 225 }} duration={1}>
<div>Rotate from 45 to 225 degrees</div>
</Animate>
</div>
);
}
Important: The <Animate>
component's children
prop must be a single React element that can accept a ref
(like standard HTML elements div
, p
, button
, or components using React.forwardRef
). The animation styles are applied to a wrapper element generated by <Animate>
.
useAnimation
HookFor more direct control, or if you want to apply animations to an element without an extra wrapper from <Animate>
, use the useAnimation
hook.
"use client";
import {
useAnimation,
AnimationConfig,
} from "animation-library-test-abdullah-altun";
// Ensure styles are imported globally
function MyAdvancedComponent() {
const slideConfig: AnimationConfig = {
type: "slide",
distance: 150,
axis: "x",
duration: 0.7,
easing: "cubic-bezier(0.175, 0.885, 0.32, 1.275)",
};
const {
ref: slideRef,
key: slideKey,
replay: replaySlide,
} = useAnimation<HTMLDivElement>(slideConfig);
return (
<div>
<div
ref={slideRef}
key={slideKey}
style={{
padding: "20px",
background: "lightcoral",
marginBottom: "10px",
}}
>
Animated with Hook (Slide)!
</div>
<button onClick={replaySlide}>Replay Slide</button>
</div>
);
}
Animations are primarily controlled by the type
prop and other specific props that define magnitude and direction. CSS Custom Properties are set by the JavaScript to control the keyframe animations defined in SCSS.
fade
:
opacity: { start?: number, end?: number }
(defaults to { start: 0, end: 1 }
).slide
:
distance: number
: Magnitude of movement in pixels.axis: "x" | "y"
: Axis of movement (defaults to "x"
).axis: "x"
: Positive distance
= slides in from right, Negative distance
= slides in from left.axis: "y"
: Positive distance
= slides in from bottom, Negative distance
= slides in from top.scale
:
scale: number
(e.g., 0.5
starts at 50% size, defaults to 0.8
).rotate
:
degrees: number | { start?: number, end: number }
.
number
(e.g., 90
): Rotates from 0deg
to 90deg
. Positive = clockwise, Negative = counter-clockwise.object
(e.g., { start: -45, end: 45 }
): Rotates from start
to end
degrees.bounce
:
distance: number
. Positive distance
= main bounce upwards, Negative distance
= main bounce downwards.<Animate>
)Prop | Type | Default | Description |
---|---|---|---|
type | 'fade' | 'slide' | 'scale' | 'rotate' | 'bounce' | Required | The type of animation to apply. |
children | ReactNode | Required | A single React element child to be animated. Must be able to accept a ref . |
as | keyof JSX.IntrinsicElements | React.ComponentType<any> | 'div' | The HTML tag or React component to render as the wrapper element. |
duration | number | 0.5 | Animation duration in seconds. |
delay | number | 0 | Delay before the animation starts in seconds. |
easing | string | 'ease-out' | CSS animation timing function (e.g., 'linear' , 'ease-in' , 'cubic-bezier(...)' ). |
distance | number | 50 | Magnitude (px) for slide and bounce. Sign influences direction. |
degrees | number | { start?: number, end: number } | 360 | Degrees for rotate. Number is end rotation (from 0 or degreesStart ). Object for start /end . Sign/difference influences direction. |
scale | number | 0.8 | Starting scale factor for scale animations (e.g., 0.5 means start at 50%). |
opacity | { start?: number, end?: number } | (internal) | Start/end opacity (0-1). Default: { start: 0, end: 1 } . |
axis | 'x' | 'y' | 'x' | Axis for slide animations. |
className | string | '' | Additional CSS classes for the wrapper. The component adds an animated class. |
onAnimationComplete | () => void | undefined | Callback when animation finishes. For event object, use onAnimationEnd . |
...props | HTMLAttributes<HTMLDivElement> | - | Other HTML attributes (e.g., style , id , onClick , onAnimationEnd ) for the wrapper. |
useAnimation
)function useAnimation<T extends HTMLElement>(
config: AnimationConfig,
onAnimationComplete?: (event: Event) => void
): {
ref: React.RefObject<T | null>;
key: number;
replay: () => void;
};
// AnimationConfig type:
// {
// type: AnimationType;
// duration?: number;
// delay?: number;
// easing?: string;
// distance?: number;
// degrees?: number | { start?: number; end: number };
// scale?: number;
// opacity?: { start?: number; end?: number };
// axis?: SlideAxis;
// }
If you are using Method 2 for importing styles (via @use "animation-library-test-abdullah-altun/styles"
), you can configure the default SCSS fallback variables. These fallbacks are used by the keyframes if the CSS Custom Properties (set by the React component/hook) are somehow not applied.
// src/app/globals.scss
// Configure SCSS variables using the `with` keyword:
@use "animation-library-test-abdullah-altun/styles" with (
$animation-duration: 0.8s,
// Default fallback duration
$animation-delay: 0.1s,
// Default fallback delay
$animation-easing: ease-in-out,
// Default fallback easing
$default-slide-distance: 100px,
// Fallback for --distance in slide
// ... see styles/_variables.scss in the library for all configurable variables
);
Note: Runtime animation parameters (duration, delay, distance, etc.) set via props on the <Animate>
component or useAnimation
hook will always take precedence by setting CSS Custom Properties. The SCSS variables primarily act as compile-time defaults for the keyframes themselves.
The library includes styles that respect the prefers-reduced-motion
media query, significantly reducing or disabling animations for users who have enabled this preference in their system settings. This is handled by the @include acc.respect-motion-preferences;
mixin (from styles/_accessibility.scss
) within the library's styles.
This library relies on standard CSS Animations and Custom Properties, supported by all modern browsers:
This guide helps new developers understand, maintain, and extend the library.
animation-library/
├── dist/ # Build output (JS, MJS, DTS, compiled CSS)
├── src/
│ ├── components/
│ │ ├── Animate.tsx
│ │ └── index.ts
│ ├── hooks/
│ │ ├── useAnimation.ts
│ │ └── index.ts
│ ├── types/
│ │ └── index.ts
│ └── index.ts # Main library export
├── styles/ # SCSS source files (using @use, @forward)
│ ├── _accessibility.scss
│ ├── _animations.scss
│ ├── _keyframes.scss
│ ├── _variables.scss
│ └── main.scss # Main SCSS entry point for SCSS users
├── package.json
├── tsconfig.json
├── tsup.config.ts
└── README.md
tsup
(configured in tsup.config.ts
) for TypeScript/JavaScript and sass
CLI for SCSS.npm run build
(or yarn build
).
src/
to JavaScript (CJS and ESM) and generates type definitions (.d.ts
) into dist/
.styles/main.scss
to dist/styles.css
.prepublishOnly
script ensures a clean build before publishing.useAnimation
Hook: Sets CSS Custom Properties (e.g., --animation-duration
) and applies CSS classes (e.g., animate-fade
) to the target element.<Animate>
Component: A wrapper around useAnimation
for declarative use.styles/
):
@use
, @forward
)._variables.scss
: Defines configurable SCSS variables with !default
._keyframes.scss
: Defines @keyframes
using CSS Custom Properties with SCSS variable fallbacks (e.g., var(--distance, #{$default-slide-distance})
)._animations.scss
: Defines animation utility classes that apply keyframes and base properties.main.scss
: The entry point for SCSS consumers, using @forward
and @use
.dist/styles.css
): The output of styles/main.scss
, usable by any project.src/types/index.ts
): Add to AnimationType
.src/hooks/useAnimation.ts
): Handle new type for class generation and any specific CSS Custom Properties.styles/_keyframes.scss
): Define new @keyframes
.styles/_animations.scss
): Add new .animate-...
class.styles/_variables.scss
): Add any new SCSS fallback variables if needed.npm run build
).npm update
or yarn upgrade
.dist/styles.css
(or SCSS via @use
) is correctly imported globally.<Animate>
and useAnimation
must be used in React Client Components.[Link to Live Demo - Placeholder]
Contributions are welcome! Please feel free to submit issues or Pull Requests.
git checkout -b feature/your-feature
).git commit -m 'Add some feature'
).git push origin feature/your-feature
).This project is licensed under the MIT License - see the LICENSE
file for details.
Abdullah Altun
FAQs
React animation library using SCSS and CSS Custom Properties
We found that animation-library-test-abdullah-altun demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.