🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@idui/react-snackbar

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@idui/react-snackbar

React Snackbar Component

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Snackbar React Component

NPM Size JavaScript Style Guide Coverage Status LICENSE

  • Docs
  • Playground

Install

npm install --save @idui/react-snackbar
yarn add @idui/react-snackbar

See props in Docs

Snackbar

import React from 'react'
import { Snackbar } from '@idui/react-snackbar'

function Example() {
    const [isSnackbarShown, setSnackbarShown] = useState(false);

    return (
        <div>
            <button onClick={() => setSnackbarShown(true)}>Show</button>
            {isSnackbarShown && (
                <Snackbar onClose={() => setSnackbarShown(false)}>
                    <Content>{children}</Content>
                </Snackbar>
            )}
        </div>
    );
}

const Content = styled.div`
  min-width: 30rem;
  max-width: 60rem;
  border-radius: 0.5rem;
  background-color: #14113c;
  box-shadow: 0 0.4rem 0.5rem rgba(0, 0, 0, 0.09),
    0 0.4rem 1.2rem rgba(0, 0, 0, 0.05), 0 0.2rem 0.6rem rgba(0, 0, 0, 0.1);
  color: #ffffff;
  padding: 1.4rem;
`;

SnackbarGroup

import React from 'react'
import { Snackbar } from '@idui/react-snackbar'

function Example() {
    const [items, setItems] = useState([]);

    const addItem = useCallback(() => {
        setItems([...items, { id: Math.round(Math.random() * 1000) }]);
    }, [items]);

    const removeItem = useCallback(
        (itemId) => {
            if (itemId) {
                setItems(items.filter((item) => itemId !== item.id));
            } else {
                setItems(items.slice(1));
            }
        },
        [items]
    );

    return (
        <div>
            <button onClick={addItem}>Add Item</button>
            <button onClick={() => removeItem()}>Remove Item</button>
            <SnackbarGroup
                {...props}
                onClose={removeItem}
                items={items}
                renderItem={({ data, close }) => (
                    <Content>
                        <div>â„– {data.id}</div>
                        <button onClick={close}>Close</button>
                    </Content>
                )}
            />
        </div>
    );
}

const Content = styled.div`
  min-width: 30rem;
  max-width: 60rem;
  border-radius: 0.5rem;
  background-color: #14113c;
  box-shadow: 0 0.4rem 0.5rem rgba(0, 0, 0, 0.09),
    0 0.4rem 1.2rem rgba(0, 0, 0, 0.05), 0 0.2rem 0.6rem rgba(0, 0, 0, 0.1);
  color: #ffffff;
  padding: 1.4rem;
  margin-bottom: 0.5rem;
  button {
    margin-top: 1rem;
  }
`;

See more details in storybook

License

MIT © kaprisa57@gmail.com

FAQs

Package last updated on 18 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts