# @kano/kbc-dialog

> Injectable dialog into mini apps

Latest version **2.0.105** (published 2023-03-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install @kano/kbc-dialog
pnpm add @kano/kbc-dialog
yarn add @kano/kbc-dialog
bun add @kano/kbc-dialog
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.105 |
| Published | 2023-03-23 |
| First published | 2020-02-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 220.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kano Computing |
| Maintainers | hector.bennett, petarsimonovic, kimonsatan, ellenw3lsh, camuskano, alexfiennes, kanocomputing, rpazdera, jamie_old_plantain |

## Links

- npm: https://www.npmjs.com/package/@kano/kbc-dialog
- Repository: https://github.com/KanoComputing/kano-boilerplate-components
- Issues: https://github.com/KanoComputing/kano-boilerplate-components/issues
- npm.io page: https://npm.io/package/@kano/kbc-dialog

## Dependencies (12)

- [react-slider](https://npm.io/package/react-slider.md) ^1.1.2
- [@kano/kbc-intl](https://npm.io/package/@kano/kbc-intl.md) ^2.0.13
- [@kano/kbc-forms](https://npm.io/package/@kano/kbc-forms.md) ^2.1.26
- [@kano/kbc-icons](https://npm.io/package/@kano/kbc-icons.md) ^2.2.24
- [@kano/kbc-utils](https://npm.io/package/@kano/kbc-utils.md) ^2.2.4
- [@kano/kbc-button](https://npm.io/package/@kano/kbc-button.md) ^3.0.48
- [@kano/kbc-tokens](https://npm.io/package/@kano/kbc-tokens.md) ^2.0.6
- [react-router-dom](https://npm.io/package/react-router-dom.md) ^5.2.0
- [@kano/kbc-telemetry](https://npm.io/package/@kano/kbc-telemetry.md) ^5.0.14
- [@types/react-slider](https://npm.io/package/@types/react-slider.md) 1.0.0
- [@kano-world/kbc-clients](https://npm.io/package/@kano-world/kbc-clients.md) ^3.1.18
- [@types/resize-observer-browser](https://npm.io/package/@types/resize-observer-browser.md) ^0.1.4

## Recent versions

- 2.0.105 (latest) — 2023-03-23
- 2.0.104 — 2023-03-22
- 2.0.103 — 2023-03-22
- 2.0.102 — 2023-03-01
- 2.0.101 — 2023-03-01
- 2.0.100 — 2023-02-17
- 2.0.99 — 2023-02-14
- 2.0.98 — 2023-01-30
- 2.0.97 — 2023-01-27
- 2.0.96 — 2023-01-26
- 2.0.95 — 2023-01-12
- 2.0.94 — 2023-01-12
- 2.0.93 — 2023-01-10
- 2.0.92 — 2023-01-10
- 2.0.91 — 2023-01-03
- … 261 more at https://npm.io/package/@kano/kbc-dialog/versions

## 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`     |

---
_Source: https://npm.io/package/@kano/kbc-dialog · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
