GithubHelp home page GithubHelp logo

wangsijie / antd-prompt Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 9.0 1.81 MB

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

License: MIT License

JavaScript 21.78% HTML 22.79% CSS 5.14% TypeScript 50.29%
antd antd-design antd-react-components

antd-prompt's Introduction

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'));

Keep modal open after submit

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 () => {
        await prompt({
            title: "Please enter name",
            value: 'Initial Value',
            modalProps: {
                width: '80%'
            },
            onOk: name => {
                // do something with name
                return false;
                // or return Promise.resolve(false);
            }
        });
    }
    render() {
        return <div>
            <Button onClick={this.handler}>Set Name</Button>
        </div>
    }
}

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

antd-prompt's People

Contributors

dependabot[bot] avatar maxired avatar wangsijie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

antd-prompt's Issues

对于按需加载组件的antd,样式不生效

版本:0.5.0
用按需加载的antd加载组件时,由于antd-prompt不会加载antd的modal的css,故样式会有问题。
实测需要在项目中加载所需的css
import 'antd/es/modal/style/index.css';
方可生效

V0.6.0 not released on npm

Hi,

I realized the version 0.6.0 is not released on npm.
it would be great if you could do so, so everyone can easily benefit from the latest features.

thanks

无法修改Modal插入节点

由于代码内写死了Modal的getContainer={false},导致无法修改Modal的插入节点,同时没有提供替代参数。
在用于qiankun等框架场景时,直接插入body会导致DOM溢出,需要指定插入节点,故此需要支持。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.