Skip to content

Commit

Permalink
simultaneous updates bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
adnan-td committed Jul 2, 2023
1 parent c03a1d7 commit ef4d44e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"build-storybook": "storybook build",
"chromatic": "chromatic --exit-zero-on-changes"
},
"dependencies": {
"framer-motion": "^10.12.18"
},
"peerDependencies": {
"framer-motion": "^10.12.17",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand All @@ -47,7 +49,6 @@
"@types/react-dom": "^18.0.11",
"babel-loader": "^9.1.2",
"chromatic": "^6.19.9",
"framer-motion": "^10.12.17",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down Expand Up @@ -76,7 +77,6 @@
"bugs": {
"url": "https://github.com/Adnan-S-Husain/react-mouse-follower/issues"
},
"readme": "ERROR: No README data found!",
"homepage": "https://github.com/Adnan-S-Husain/react-mouse-follower#readme",
"_id": "react-mouse-follower@1.0.6"
"readme": "README.md",
"homepage": "https://github.com/Adnan-S-Husain/react-mouse-follower#readme"
}
2 changes: 1 addition & 1 deletion src/component/follower_div.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function FollowerDiv({ pos, options }: { pos: MousePosition; options: Mou
overflow: 'hidden',
}}
>
{options.text ? (
{options.text && !options.backgroundElement ? (
<p
style={{
width: '85%',
Expand Down
3 changes: 1 addition & 2 deletions src/context/mouse.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export const MousePropertiesContext = createContext<ContextInterface>(null);
export const FollowerProvider = ({ children }: Props) => {
const layerStack = useStack(defaultMouseProperties);
const addLayer = (layerOptions: MouseSettings) => {
const properties = { ...layerStack.peek(), ...layerOptions };
layerStack.push(properties);
layerStack.push(layerOptions);
};

const removeLayer = () => {
Expand Down
6 changes: 5 additions & 1 deletion src/stories/FollowerBasic.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const meta: Meta = {
argTypes: {
backgroundColor: { control: 'color', defaultValue: 'black' },
scale: { control: 'number', min: 0.1, max: 2, step: 0.1, defaultValue: 1 },
inverted: { control: 'boolean', defaultValue: false },
radius: { control: 'number', min: 12, max: 200, step: 1, defaultValue: 12 },
speed: { control: 'number', min: 0, max: 10, step: 0.1, defaultValue: 1 },
text: { control: 'text', defaultValue: '' },
textColor: { control: 'color', defaultValue: 'white' },
textFontSize: { control: 'text', defaultValue: '12px' },
},
parameters: {
layout: 'fullscreen',
Expand Down
2 changes: 1 addition & 1 deletion src/stories/UpdateFollower.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import './css/update_follower.css';

const meta: Meta = {
title: 'Components/UpdateFollower',
component: UpdateFollower,
component: undefined,
parameters: {
layout: 'fullscreen',
},
Expand Down
22 changes: 16 additions & 6 deletions src/util/stack_hook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import type { MouseSettings } from '../types/index.js';

export const useStack = (
Expand All @@ -16,10 +16,13 @@ export const useStack = (
const [stack, setStack] = useState<MouseSettings[]>([defaultMouseProperties]);

const push = (options: MouseSettings): void => {
const item: MouseSettings = {
...options,
};
setStack((prevStack) => [...prevStack, item]);
setStack((prevStack) => {
const item: MouseSettings = {
...prevStack[prevStack.length - 1],
...options,
};
return [...prevStack, item];
});
};

const pop = (): MouseSettings | undefined => {
Expand Down Expand Up @@ -48,9 +51,16 @@ export const useStack = (
};

const logStack = (): void => {
console.log(stack);
console.log('logging stack');
stack.forEach((item, i) => {
console.log(i, item);
});
};

useEffect(() => {
logStack();
}, [stack]);

return {
stack,
push,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4357,10 +4357,10 @@ forwarded@0.2.0:
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
integrity sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==

framer-motion@^10.12.17:
version "10.12.17"
resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-10.12.17.tgz#0e891aaddbe6049267c413449945af95585cbc87"
integrity sha512-IR+aAYntsyu6ofyxqQV4QYotmOqzcuKxhqNpfc3DXJjNWOPpOeSyH0A+In3IEBu49Yx/+PNht+YMeZSdCNaYbw==
framer-motion@^10.12.18:
version "10.12.18"
resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-10.12.18.tgz#92015860b6468a82e76c4739fcae81e1f6723b3f"
integrity sha512-cfhiUpPbj+0eEWKjuD+5cz5cMqH71xOtMxGiS/cSGfHn2OlHIEAqFnFyzEMENw5PxWR9bMVhatzzpD6lexmHZQ==
dependencies:
tslib "^2.4.0"
optionalDependencies:
Expand Down

0 comments on commit ef4d44e

Please sign in to comment.