Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/code/Animations/pixelTransitionCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const pixelTransition = {
}
gridSize={12}
pixelColor='#ffffff'
once={false}
animationStepDuration={0.4}
className="custom-pixel-card"
/>`,
Expand Down
6 changes: 4 additions & 2 deletions src/content/Animations/PixelTransition/PixelTransition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function PixelTransition({
gridSize = 7,
pixelColor = 'currentColor',
animationStepDuration = 0.3,
once = false,
aspectRatio = '100%',
className = '',
style = {}
Expand Down Expand Up @@ -93,10 +94,11 @@ function PixelTransition({
if (!isActive) animatePixels(true);
};
const handleLeave = () => {
if (isActive) animatePixels(false);
if (isActive && !once) animatePixels(false);
};
const handleClick = () => {
animatePixels(!isActive);
if (!isActive) animatePixels(true);
else if (isActive && !once) animatePixels(false);
};

return (
Expand Down
10 changes: 10 additions & 0 deletions src/demo/Animations/PixelTransitionDemo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useForceRerender from '../../hooks/useForceRerender';

import PixelTransition from '../../content/Animations/PixelTransition/PixelTransition';
import { pixelTransition } from '../../constants/code/Animations/pixelTransitionCode';
import PreviewSwitch from '@/components/common/Preview/PreviewSwitch';

const propData = [
{
Expand Down Expand Up @@ -51,6 +52,12 @@ const propData = [
default: `"100%"`,
description: "Sets the 'padding-top' (or aspect-ratio) for the container."
},
{
name: 'once',
type: 'boolean',
default: 'false',
description: 'If true, the transition will not revert on mouse leave or subsequent clicks.'
},
{
name: 'className',
type: 'string',
Expand All @@ -70,6 +77,7 @@ const PixelTransitionDemo = () => {
const [pixelColor, setPixelColor] = useState('#ffffff');
const [animationStepDuration, setAnimationStepDuration] = useState(0.4);
const [key, forceRerender] = useForceRerender();
const [once, setOnce] = useState(false);

return (
<TabsLayout>
Expand Down Expand Up @@ -100,6 +108,7 @@ const PixelTransitionDemo = () => {
gridSize={gridSize}
pixelColor={pixelColor}
animationStepDuration={animationStepDuration}
once={once}
className="custom-pixel-card"
/>
<Text mt={2} color="#a6a6a6">
Expand Down Expand Up @@ -148,6 +157,7 @@ const PixelTransitionDemo = () => {
p={0}
/>
</Flex>
<PreviewSwitch title="Once" isChecked={once} onChange={checked => setOnce(checked)} />
</Customize>

<PropTable data={propData} />
Expand Down
8 changes: 6 additions & 2 deletions src/tailwind/Animations/PixelTransition/PixelTransition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function PixelTransition({
animationStepDuration = 0.3,
aspectRatio = '100%',
className = '',
once = false,
style = {},
aspectRatio = '100%'
style = {}
}) {
const containerRef = useRef(null);
Expand Down Expand Up @@ -94,10 +97,11 @@ function PixelTransition({
if (!isActive) animatePixels(true);
};
const handleLeave = () => {
if (isActive) animatePixels(false);
if (isActive && !once) animatePixels(false);
};
const handleClick = () => {
animatePixels(!isActive);
if (!isActive) animatePixels(true);
else if (isActive && !once) animatePixels(false);
};

return (
Expand Down
8 changes: 5 additions & 3 deletions src/ts-default/Animations/PixelTransition/PixelTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface PixelTransitionProps {
gridSize?: number;
pixelColor?: string;
animationStepDuration?: number;
once?: boolean;
className?: string;
style?: CSSProperties;
aspectRatio?: string;
Expand All @@ -19,6 +20,7 @@ const PixelTransition: React.FC<PixelTransitionProps> = ({
gridSize = 7,
pixelColor = 'currentColor',
animationStepDuration = 0.3,
once = false,
aspectRatio = '100%',
className = '',
style = {}
Expand Down Expand Up @@ -104,12 +106,12 @@ const PixelTransition: React.FC<PixelTransitionProps> = ({
if (!isActive) animatePixels(true);
};
const handleLeave = (): void => {
if (isActive) animatePixels(false);
if (isActive && !once) animatePixels(false);
};
const handleClick = (): void => {
animatePixels(!isActive);
if (!isActive) animatePixels(true);
else if (isActive && !once) animatePixels(false);
};

return (
<div
ref={containerRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface PixelTransitionProps {
gridSize?: number;
pixelColor?: string;
animationStepDuration?: number;
once?: boolean;
className?: string;
style?: CSSProperties;
aspectRatio?: string;
Expand All @@ -18,6 +19,7 @@ const PixelTransition: React.FC<PixelTransitionProps> = ({
gridSize = 7,
pixelColor = 'currentColor',
animationStepDuration = 0.3,
once = false,
aspectRatio = '100%',
className = '',
style = {}
Expand Down Expand Up @@ -105,12 +107,12 @@ const PixelTransition: React.FC<PixelTransitionProps> = ({
if (!isActive) animatePixels(true);
};
const handleLeave = (): void => {
if (isActive) animatePixels(false);
if (isActive && !once) animatePixels(false);
};
const handleClick = (): void => {
animatePixels(!isActive);
if (!isActive) animatePixels(true);
else if (isActive && !once) animatePixels(false);
};

return (
<div
ref={containerRef}
Expand Down