AlphaDu / antd-prompt

An ant.design helper that auto create a Modal with an optional message prompting the user to input some text.

Home Page:https://codesandbox.io/s/antd-prompt-fohcs?fontsize=14

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

antd-prompt

An ant.design helper that auto create a Modal with an optional message prompting the user to input some text.

Support antd v4.

Installation

npm i antd-prompt

Usage

Edit antd-prompt

import React, { component } from 'react';
import ReactDOM from 'react-dom';
import prompt from 'antd-prompt';
import { Button, message } from 'antd';

class App extends Component {
    handler = async () => {
        try {
            const name = await prompt({
                title: "Please enter name",
                placeholder: "Your name",
                rules: [
                    // check this link for more help: https://ant.design/components/form/#Validation-Rules
                    {
                        required: true,
                        message: "You must enter name"
                    }
                ],
                modalProps: {
                    width: '80%'
                }
            });
        } catch (e) {
            message.error('Please enter name');
        }
    }
    render() {
        return <div>
            <Button onClick={this.handler}>Set Name</Button>
        </div>
    }
}

ReactDOM.render(<App />, document.getElementById('root'));

About

An ant.design helper that auto create a Modal with an optional message prompting the user to input some text.

https://codesandbox.io/s/antd-prompt-fohcs?fontsize=14

License:MIT License


Languages

Language:TypeScript 44.2%Language:HTML 25.8%Language:JavaScript 24.2%Language:CSS 5.8%