0.1.8 • Published 4 years ago

myt-react-notify v0.1.8

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

github npm yarn bundlephobia

myt-react-notify

This react notification library is a gold. It is easy to use and undestand because it is uniquely engineered and it don`t need a complicated set-up for container and trigger like the majority does. This library set-up feels normal component and handy to understand which makes it unique, it can be render in any functions as component which allow developer to use customize component as templates. and plus it is just 6kb gzip minified, it is so light it can make the tree shaking and feather flying with no regrets.

installation

npm

npm i myt-react-notify

yarn

yarn add myt-react-notify

visit playground 👉 Edit notification machine

How to use

import to your project

import { Notification, Render, RenderHasId } from 'myt-react-notify';

Customize Template Usage

You can make template of your own. Edit myt-react-notify-usage

import { Alert, Button } from 'react-bootstrap';
<Button
	onClick={() => {
		Render(
			<Notification placement='bottom-left'>
				{(notificationShow) => (
					<Alert
						variant='danger'
						dismissible
						onClose={() => notificationShow(false)}>
						<Alert.Heading>Oh snap!!</Alert.Heading>
						<p>I can use bootstrap</p>
					</Alert>
				)}
			</Notification>
		);
	}}>
	Show Alert
</Button>

Animation Usage

You can use a custom animation class using @keyframe for this component. animate.css for cool animations. Edit myt-react-notify-usage

<button
	className='btn'
	onClick={() => {
		Render(
			<Notification
				template={{
					title: 'Animated!',
					message: 'that is so cool',
					variant: 'primary',
					dismissible: false
				}}
				animation={{
					enter: 'animated bounceInLeft',
					exit: 'animated fadeOutDown'
				}}
				timing={1000}
				delay={4000}
			/>
		);
	}}>
	Show Animated Notification
</button>

Remaining Notification Usage

You can remove the timeout of the notification by setting delay as 0. Edit myt-react-notify-usage

<button
	className='btn'
	onClick={() => {
		Render(
			<Notification
				template={{
					title: 'Hey!',
					message: 'I`m not closing unless 👉',
					variant: 'warning',
					dismissible: true
				}}
				animation={{
					enter: 'animated bounceInLeft',
					exit: 'animated fadeOutDown'
				}}
				timing={1000}
				delay={0}
			/>
		);
	}}>
	Show No Timeout Notification
</button>

Customize Default Template Usage

You can customize the default template as well. Edit myt-react-notify-usage

<button
	className='btn'
	onClick={() => {
		Render(
			<Notification
				template={{
					message: (
						<a
							href='https://codesandbox.io/s/notification-machine-rql5k?fontsize=14&hidenavigation=1&theme=dark'
							target='_blanks'
							style={{ textDecoration: 'none' }}>
							<div>
								<img
									src='https://avatars0.githubusercontent.com/u/28913097?v=4'
									alt='beard'
									width='20%'
								/>
								<span style={{ padding: '10px 15px' }}>hey check me out</span>
							</div>
						</a>
					),
					variant: 'primary',
					dismissible: true
				}}
				animation={{
					enter: 'animated bounceInLeft',
					exit: 'animated fadeOutDown'
				}}
				timing={1000}
				delay={4000}
			/>
		);
	}}>
	Customize Default Template
</button>

Updating Notification Usage

You can update or change notification anytime and anywhere using id which must be unique. but cannot be updated the Notification property timing, placement and delay. Edit myt-react-notify-usage

<button
	className='btn'
	onClick={() => {
		Render(
			<Notification
				id='notify'
				template={{
					title: 'Hey!',
					message: 'what is up?',
					variant: 'primary'
				}}
				onEntered={() =>
					Render(
						<Notification
							id='notify'
							template={{
								title: 'Pal!',
								message: 'wooow I can change',
								variant: 'success'
							}}
						/>
					)
				}
				onExit={() =>
					Render(
						<Notification
							id='notify'
							template={{
								title: 'Yo!',
								message: "I'am going now bye",
								variant: 'danger'
							}}
						/>
					)
				}
			/>
		);
	}}>
	Updating Notification
</button>

Cancel Notification Usage

You can close or cancel immidiately notification by updating the identified notification cancel as true. Edit myt-react-notify-usage

<button className="btn" onClick={() => {
  Render(
    <Notification
      id="persistent"
      template={{
        title: "Hey!",
        message: "I`m not closing unless you cancel",
        variant: "warning",
        dismissible: false,
      }}
      animation={{
        enter: "animated bounceInLeft",
        exit: "animated fadeOutDown"
      }}
      timing={1000}
      delay={0}
    />
  );
}}>
Persistent Notification
</button>
<button className="btn" onClick={() => {
  Render(
    <Notification
      id="persistent"
      cancel={true}
    />
  );
}}>
Cancel
</button>

RenderHasId Usage

You can check the identified notification if it is already rendered. Edit myt-react-notify-usage

<button
	className='btn'
	onClick={() => {
		Render(
			RenderHasId('check-me') ? (
				<Notification
					id='check-me'
					template={{
						title: 'Heeee..',
						message: 'I`m already rendered',
						variant: 'danger',
						dismissible: true
					}}
				/>
			) : (
				<Notification
					id='check-me'
					template={{
						title: 'Yo!',
						message: 'I just got rendered',
						variant: 'success',
						dismissible: false
					}}
					delay={0}
				/>
			)
		);
	}}>
	Click Again If Rendered
</button>

PROPERTIES

All properties that is supported by Notification Component. The datatypes with "*" means it is required.

PROPERTYDATATYPESDEFAULTDESCRIPTION
idstring It is to identify the notification you want to update and cancel
template{  title: string,   message: string,   variant: "success"    |"primary"    |"warning"    |"danger",   dismissible: boolean } It is the properties of default template. if using default templating you must import the stylesheet import "myt-react-notify/template.css". default { title: null, message: "", variant: "default", dismissible: true }
animationobject you can set a customize animations. default { enter: "fade-notify-in", exit: "fade-notify-out" }
timingnumber1000It is the duration of each animation
delaynumber5000It is the duration of notification will last. if the delay is set 0 it will remain forever unless dismiss
placementtop-left|top-right|bottom-left|bottom-rightbottom-rightthe placement where the notification will remain
childrenfunction It enables you to make a customize template
cancelbooleanfalseIt is to cancel or close the certain identified or with id notification
onEnterfunction it is invoke when the animation is started to enter
onEnteringfunction it is invoke when the animation is entering
onEnteredfunction it is invoke when the animation is fully entered
onExitfunction it is invoke when the animation is started to exit
onExitingfunction it is invoke when the animation is exiting
onExitedfunction it is invoke when the animation is fully exited
onMountedfunction it is invoke when the component is mounted

Specials

you can remove notification in mobile using swipe from left to right.

License

MIT Licensed. Copyright (c) Mytabworks 2020.