npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kano/kbc-dialog

v2.0.105

Published

Injectable dialog into mini apps

Downloads

460

Readme

kbc-dialog

A basic modal dialog plus Context Provider, or HOC injectable into Kano boilerplate apps.

Usage

import { DialogProvider, DialogConfig, DialogContext, KbcDialog } from '@kano/kbc-dialog';

const Component = (props) => {
    return (
        <DialogProvider>
            ...

            <DialogContext.Consumer>
                {(config: DialogConfig) => (
                    <KbcDialog config={config} title="Your message" />
                )}
            </DialogContext.Consumer>
            
            ...
            
            <DialogContext.Consumer>
                {(config: DialogConfig) => (
                    <button onClick={config.showDialog}>Open Dialog</button>
                )}
            </DialogContext.Consumer>

            ...
        </DialogProvider>
    )
}

If using the optional backdrop, nest the KbcDialog directly within the component div you want to be covered by the backdrop.

For Example (in Pixel Motion app):

You can wrap the main part of the app, since you will probably want to overlay everything (including Nav), in a HOC called withDialog, this will provide the hiding and showing functionality, and can be passed down as props if needed elsewhere. You can also pass up KbcDialog components to set the current dialog you want to show before triggering the dialog. If you have multiple dialogs, you can also set an array of dialogs here and trigger a specific one.

import { withDialog, IDialogAPI } from '@kano/kbc-dialog';

class OutsideOfNavAndBulkOfApp {
    renderDialogs = () => {
        if (this.state.currentDialog) {
            return this.state.currentDialog();
        }
        return '';
    }

    render() {
        return (
            <Main>
                ...
                <this.renderDialogs />
            </Main>
        );
    }
}

export default withDialog(OutsideOfNavAndBulkOfApp);

And with the DialogProvider being wrapper around the whole App, e.g.:

import { DialogProvider } from '@kano/kbc-dialog';

const render = (messages?: any, optRoot?: HTMLElement) => {
    ReactDOM.render(
        <DialogProvider>
            <AppProvider config={config} />
        </DialogProvider>
        optRoot || MOUNT_NODE,
    );
};

Props for KbcDialogComponent

  • config: DialogConfig - from the Context Provider
  • modifier?: string - can modify styles on the dialog container (styles should be added at app level)
  • title?: string - h4 dialog title
  • message?: string - smaller text for the dialog
  • children?: ReactNode - allows a fully customisable dialog
  • backdrop?: boolean - whether to have an overlay under the dialog, default true
  • onConfirm?: function - optional function on user selecting confirm action
  • onCancel?: function - as above, but with cancellation
  • onClose?: function - as above, but on either confirm or cancel

Custom Dialogs

There are also a selection of custom dialogs:

  • NextChallengeDialog for calling a next challenge, displays name, image and start button
  • ClearDialog for clearing the editor, letting a user decide if they want to lose what they are currently working on, includes confirm and dismiss buttons
  • WarningDialog simply to warn a user of the something, for example their browser is incompatable with exporting. Only includes dismiss button.

Tracking

| Component (location) | Function | Event / Error Name | Extra Info | | -------------------- | --------------------------------- | ----------------------------- | ---------------------------------------------------- | | KbcDialog | confirmHandler | confirm_dialog | module: kbc-dialog, action: click | | KbcDialog | cancelHandler | cancel_dialog | module: kbc-dialog, action: click | | ClearDialog | dismiss | dismiss_dialog | module: clear-dialog, action: click | | ClearDialog | fireCallback | confirm_callback | module: clear-dialog, action: click | | WarningDialog | okay | warning_acknowledged | module: warning-dialog, action: click | | RewardsDialog | next | next_challange_requested | module: rewards-dialog, action: click | | RewardsDialog | close | close_dialog | module: rewards-dialog, action: click | | NextChallengeDialog | fireCallback | confirm_callback | module: next-challenge-dialog, action: click |