Coder Social home page Coder Social logo

pakenfit / toast-it Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 5.39 MB

Let's toast to the health of your app 🔥

Home Page: https://www.npmjs.com/package/@pakenfit/toast-it

License: MIT License

JavaScript 12.74% TypeScript 87.26%
expo react-native react-native-reanimated toast toast-notifications

toast-it's Introduction

@pakenfit/toast-it

Let's toast to the health of your application

With animation type spring and backdrop for loading

Installation

npm install @pakenfit/toast-it --save

Or

yarn add @pakenfit/toast-it

Dependencies

This library needs these dependencies to be installed in your project before you can use it:

npm install react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-svg --save

Or

yarn add react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-svg

Features

  • Fully customizable
  • Works on Android and iOS (not tested on web should work as well)
  • Compatible with Expo Go
  • Written in Typescript

Usage

import { ToastProvider, useToast } from '@pakenfit/toast-it';

const ToastComponent = () => {
  const { show, hide } = useToast();

  return (
    <View>
      <Button
        label='Show Toast'
        onPress={() =>
          show({
            type: 'success',
            message: 'This is a success Toast🤙🏽',
          })
        }
      />
    </View>
  )
}

export default function App() {

  return (
    <SafeAreaProvider>
        <ToastProvider
          defaultConfig={{
            textNumberOfLines: 2,
            bgColor: 'white',
            textColor: 'black',
          }}
        />
        <ToastComponent/>
    </SafeAreaProvider>
  )
}

Configuration

The toast component accepts the following configuration options:

  • type (optional): The type of the toast message. Possible values are 'success', 'error', 'warning', 'info', or 'loading'. Default is 'info'.
  • message: The text message to be displayed in the toast.
  • duration (optional): The duration of the toast message in milliseconds. Use 'infinite' for an indefinite duration. Default is 3000 milliseconds.
  • textColor (optional): The text color of the toast message. Default is black.
  • iconColor (optional): The color of the toast icon. Default is undefined (uses default color for each type).
  • iconSize (optional): The size of the toast icon. Default is undefined (uses default size for each type).
  • textNumberOfLines (optional): The number of lines to display for the toast message. Default is 1.
  • withBackdrop (optional, only for type loading): If true a backdrop is set when loading. Default is false.
  • backdropColor (optional, only for type loading): Set the backdrop color.
  • backdropOpacity (optional, only for type loading): Set the backdrop opacity.
  • animationType (optional): The toast enter animation type. Possible values are 'timing' and 'spring'. Default is 'timing'.
  • containerStyle (optional): The toast container style.

API

The Toast component provides the following methods through the toastRef:

  • show(config: ToastConfig): Displays a toast message with the specified configuration.
  • hide(): Hides the currently displayed toast message.
  • isVisible(): Returns a boolean indicating whether a toast message is currently visible.

Types

ToastRef

The ToastRef type represents the reference to the Toast component, allowing access to its methods. It has the following methods:

  • show: Shows the toast with the specified configuration.
  • hide: Hides the toast.
  • isVisible: Returns a boolean indicating whether the toast is currently visible.

ToastConfig

The ToastConfig type represents the configuration options for the toast component. It has the following properties:

type ToastConfig = {
  type?: toastType;
  message: string;
  duration?: number | 'infinite';
  textColor?: string;
  iconColor?: string;
  iconSize?: number;
  textNumberOfLines?: number;
  withBackdrop?: boolean;
  backdropColor?: string;
  backdropOpacity?: number;
  animationType?: 'timing' | 'spring',
  containerStyle?: ViewStyle
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Development

You can launch the example app to test your feature or bug:

yarn example ios

or

yarn example android

Run tests

yarn test

License

MIT


Made with create-react-native-library

Inspired by react-hot-toast

toast-it's People

Contributors

pakenfit avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.