@kano/kbc-dialog
Injectable dialog into mini apps
Last updated 3 days ago by onishiweb .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @kano/kbc-dialog 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.7.1                                ...           latest (3 days ago)

110 Versions

  • 1.7.1                                ...           3 days ago
  • 1.7.0                                ...           4 days ago
  • 1.6.4                                ...           8 days ago
  • 1.6.3                                ...           9 days ago
  • 1.6.1                                ...           9 days ago
  • 1.6.0                                ...           22 days ago
  • 1.5.2                                ...           a month ago
  • 1.5.1                                ...           a month ago
  • 1.5.0                                ...           a month ago
  • 1.4.0                                ...           a month ago
  • 1.3.3                                ...           a month ago
  • 1.3.2                                ...           a month ago
  • 1.3.1                                ...           a month ago
  • 1.3.0                                ...           a month ago
  • 1.2.3                                ...           a month ago
  • 1.2.2                                ...           2 months ago
  • 1.2.1                                ...           2 months ago
  • 1.2.0                                ...           2 months ago
  • 1.1.14                                ...           2 months ago
  • 1.1.13                                ...           2 months ago
  • 1.1.12                                ...           2 months ago
  • 1.1.11                                ...           2 months ago
  • 1.1.10                                ...           2 months ago
  • 1.1.9                                ...           2 months ago
  • 1.1.8                                ...           2 months ago
  • 1.1.7                                ...           2 months ago
  • 1.1.6                                ...           2 months ago
  • 1.1.5                                ...           2 months ago
  • 1.1.4                                ...           2 months ago
  • 1.1.3                                ...           2 months ago
  • 1.1.2                                ...           2 months ago
  • 1.1.1                                ...           2 months ago
  • 1.1.0                                ...           2 months ago
  • 1.0.4                                ...           3 months ago
  • 1.0.3                                ...           3 months ago
  • 1.0.2                                ...           3 months ago
  • 1.0.1                                ...           3 months ago
  • 1.0.0                                ...           3 months ago
  • 4.26.11-alpha.0                                ...           3 months ago
  • 4.26.9-alpha.0                                ...           3 months ago
  • 4.26.8-alpha.0                                ...           3 months ago
  • 4.26.7-alpha.0                                ...           3 months ago
  • 4.26.6-alpha.0                                ...           3 months ago
  • 4.26.4-alpha.0                                ...           3 months ago
  • 4.26.1-alpha.0                                ...           3 months ago
  • 4.26.0-alpha.0                                ...           3 months ago
  • 4.25.4-alpha.0                                ...           3 months ago
  • 4.25.2-alpha.0                                ...           4 months ago
  • 4.25.0-alpha.1                                ...           4 months ago
  • 4.25.0-alpha.0                                ...           4 months ago
  • 4.24.2-alpha.0                                ...           4 months ago
  • 4.24.0-alpha.0                                ...           4 months ago
  • 4.23.1-alpha.0                                ...           4 months ago
  • 4.23.0-alpha.0                                ...           4 months ago
  • 4.22.25-alpha.0                                ...           4 months ago
  • 4.22.24-alpha.0                                ...           4 months ago
  • 4.22.23-alpha.0                                ...           4 months ago
  • 4.22.22-alpha.0                                ...           4 months ago
  • 4.22.21-alpha.0                                ...           4 months ago
  • 4.22.20-alpha.0                                ...           4 months ago
  • 4.22.19-alpha.0                                ...           4 months ago
  • 4.22.18-alpha.0                                ...           4 months ago
  • 4.22.17-alpha.0                                ...           4 months ago
  • 4.22.15-alpha.0                                ...           4 months ago
  • 4.22.14-alpha.0                                ...           4 months ago
  • 4.22.13-alpha.0                                ...           4 months ago
  • 4.22.12-alpha.0                                ...           4 months ago
  • 4.22.11-alpha.0                                ...           4 months ago
  • 4.22.9-alpha.0                                ...           4 months ago
  • 4.22.7-alpha.0                                ...           4 months ago
  • 4.22.6-alpha.0                                ...           4 months ago
  • 4.22.5-alpha.0                                ...           4 months ago
  • 4.22.4-alpha.0                                ...           4 months ago
  • 4.22.1-alpha.0                                ...           4 months ago
  • 4.21.6-alpha.0                                ...           4 months ago
  • 4.22.0-alpha.0                                ...           4 months ago
  • 4.21.4-alpha.0                                ...           4 months ago
  • 4.21.2-alpha.0                                ...           5 months ago
  • 4.21.0-alpha.0                                ...           5 months ago
  • 4.20.4-alpha.0                                ...           5 months ago
  • 4.20.3-alpha.0                                ...           5 months ago
  • 4.20.2-alpha.0                                ...           5 months ago
  • 4.20.1-alpha.0                                ...           5 months ago
  • 4.20.0-alpha.0                                ...           5 months ago
  • 4.19.3-alpha.0                                ...           5 months ago
  • 4.19.2-alpha.0                                ...           5 months ago
  • 4.19.0-alpha.0                                ...           5 months ago
  • 4.18.0-alpha.0                                ...           5 months ago
  • 4.17.1-alpha.0                                ...           5 months ago
  • 4.16.5-alpha.0                                ...           5 months ago
  • 4.16.4-alpha.0                                ...           5 months ago
  • 4.16.3-alpha.0                                ...           5 months ago
  • 4.15.0                                ...           5 months ago
  • 4.14.13-alpha.0                                ...           5 months ago
  • 4.14.12-alpha.0                                ...           5 months ago
  • 4.14.11-alpha.0                                ...           6 months ago
  • 4.14.10-alpha.0                                ...           6 months ago
  • 4.14.8-alpha.0                                ...           6 months ago
  • 4.13.1-alpha.0                                ...           6 months ago
  • 4.13.0-alpha.0                                ...           6 months ago
  • 4.12.0-alpha.0                                ...           6 months ago
  • 4.11.5-alpha.0                                ...           6 months ago
  • 4.11.1-alpha.0                                ...           6 months ago
  • 4.10.5-alpha.0                                ...           6 months ago
  • 4.10.2-alpha.0                                ...           6 months ago
  • 4.10.1-alpha.0                                ...           6 months ago
  • 4.9.3-alpha.0                                ...           7 months ago
  • 4.8.0-alpha.0                                ...           7 months ago
  • 4.6.0-alpha.0                                ...           7 months ago
  • 4.5.0-alpha.0                                ...           7 months ago
Downloads
Today 0
This Week 18
This Month 44
Last Day 0
Last Week 26
Last Month 389
Dependencies (6)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |