Socket
Socket
Sign inDemoInstall

@kano/kbc-dialog

Package Overview
Dependencies
Maintainers
9
Versions
276
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kano/kbc-dialog

Injectable dialog into mini apps


Version published
Weekly downloads
28
decreased by-76.67%
Maintainers
9
Weekly downloads
 
Created
Source

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)FunctionEvent / Error NameExtra Info
KbcDialogconfirmHandlerconfirm_dialogmodule: kbc-dialog, action: click
KbcDialogcancelHandlercancel_dialogmodule: kbc-dialog, action: click
ClearDialogdismissdismiss_dialogmodule: clear-dialog, action: click
ClearDialogfireCallbackconfirm_callbackmodule: clear-dialog, action: click
WarningDialogokaywarning_acknowledgedmodule: warning-dialog, action: click
RewardsDialognextnext_challange_requestedmodule: rewards-dialog, action: click
RewardsDialogcloseclose_dialogmodule: rewards-dialog, action: click
NextChallengeDialogfireCallbackconfirm_callbackmodule: next-challenge-dialog, action: click

FAQs

Package last updated on 23 Mar 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc