Comments (15)
Will close this issue since #36 was created and this issue has a lot of irrelevant comments.
from alert.
@gxrsti can you assign me this issue?
from alert.
Sure, here you go!
from alert.
@gxrsti do we have to change all the comments in the code?
from alert.
Currently, there are no comments. We need comments at least for all the exported components/functions!
The more, the better.
from alert.
@gxrsti we should we add the toaster component?
from alert.
@gxrsti we should we add the toaster component?
Toaster component and toast function at least.
from alert.
@gxrsti while running ppm run development website I am getting this error
Turborepo requires npm workspaces to be defined in the root package.json
from alert.
@shakthi2003-ice Try these steps in the project root:
- Run
pnpm install
- Run
pnpm run dev:website
from alert.
@gxrsti i did the same but still getting error
from alert.
Make sure to have the newest version of the master branch.
If you follow these steps, everything should work.
Also make sure to have pnpm installed (npm install -g pnpm
)
If it still doesn't work, here is my last possible solution:
Get a fresh version of the repository and add "packageManager": "[email protected]"
at the end (after peerDependencies) of the package.json
.
Then try the install and dev:website
from alert.
@shakthi2003-ice did you get it working?
from alert.
Hi there! I've added a comment for this code file. Please let me know if you're satisfied with it or if you'd like any changes. By the way, this is @Moksh45
import { IToast, ToastState, ToasterProps } from '../core/types';
import { Store } from '../core/store';
import { Toast } from './toast';
// A component that renders a toast notification container
const Toaster = ({
position = 'bottom-right',
duration = 3000,
reverse = false,
theme = 'light',
style,
className,
}: ToasterProps) => {
// State for storing the toast notifications
const [toasts, setToasts] = useState<IToast[]>([]);
// State for positioning the toast container
const [positionState, setPositionState] = useState<React.CSSProperties>({});
// State for calculating the height of the toast container
const [height, setHeight] = useState(0);
// Subscribe to the toast store and add new toast notifications
useEffect(() => {
const unsubscribe = Store.subscribe((toast) => {
setToasts((toasts) => [...toasts, toast]);
handleToast(toast);
});
return () => {
unsubscribe();
};
}, []);
// Set the position state based on the given position prop
useEffect(() => {
const [y, x] = position.split('-');
setPositionState({
[y]: 0,
[x]: 0,
});
}, [position]);
// Update the height of the toast container based on the number of toasts
useEffect(() => {
setHeight(toasts.length * 41);
}, [toasts]);
// Handle the lifecycle of a toast notification
function handleToast(toast: IToast) {
setTimeout(() => updateToastState(toast, 'idle'), 300);
setTimeout(() => updateToastState(toast, 'leave'), duration - 100);
setTimeout(() => removeToast(toast), duration);
}
// Update the state of a toast notification
function updateToastState(toast: IToast, state: ToastState) {
setToasts((toasts) => {
var copy = toasts.slice();
var index = copy.findIndex((x) => x.id === toast.id);
copy[index] = { ...copy[index], state: state };
return copy;
});
}
// Remove a toast notification from the state
const removeToast = useCallback(
(toast: IToast) => setToasts((toasts) => toasts.filter((x) => x.id !== toast.id)),
[],
);
// Reverse the order of toasts if reverse prop is true
const reversedToasts = reverse ? toasts.slice().reverse() : toasts;
return (
<section
style={{
position: 'fixed',
zIndex: 9999,
display: 'flex',
flexDirection: 'column',
gap: 5,
margin: 16,
transform: 'translateY(0)',
height: height,
transition: 'all 230ms cubic-bezier(.21, 1.02, .73, 1)',
...positionState,
}}
>
{position.startsWith('bottom') && !reverse && <div className="flex h-full w-full grow" />}
{reversedToasts.map((toast, index) => (
<Toast key={index} toast={{ ...toast, zIndex: index, theme }} />
))}
</section>
);
};
export { Toaster };
from alert.
Hey @Moksh45-Bot!
For file changes, could you please open a pr? Also from what i see, i would like to use this commenting style as far as it is possible to also descripe the parameters of a function or component.
from alert.
@gxrsti ok
from alert.
Related Issues (20)
- Add `toast.error()` function HOT 2
- Bump version to 6.0.0 HOT 5
- `Position` Select Box For Demo Website HOT 1
- Allow Changing Direction Of Toasts HOT 2
- Create Figma For Demo Website HOT 4
- Add More Test Cases HOT 2
- Add `toast.promise()` function HOT 5
- Add Theming To Toaster Component HOT 2
- Add Light/Dark Mode To Demo Website HOT 1
- Design Icon/Logo For This Package HOT 4
- Add Footer To Website HOT 3
- Add Install Instructions To Website HOT 4
- Improve Feature Showcase Of Website HOT 3
- Add Copy Button To Codeblocks On Website HOT 5
- Error/Success Toast Brakes Animations
- Enhance Contributing.md HOT 1
- Comments For Better Code Documentation HOT 8
- docs: Add a contribution section in main Readme.md HOT 2
- Props do not work HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alert.