Giter Site home page Giter Site logo

forkkit / sunflower Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ant-design/sunflower

0.0 2.0 0.0 2.9 MB

☀️A react-hooks + antd library from Alipay Industry Technology department.

Home Page: https://ant-design.github.io/sunflower

License: MIT License

JavaScript 45.03% TypeScript 54.97%

sunflower's Introduction

sunflower

React Hooks with components of antd.

build status Test coverage node version

🎩  Features

  • 🏄 Easy to use. You don't need to know too much about state and change methods to use components with interaction logic.
  • 💅 Easy to customize. You can easily customize the combination of components you need.
  • 👯 Layered design. You can use react-hooks without ui or react-hooks with antd.

🤔  Why?

    Usually, we use multiple antd components, and we organize their relationship through state and props methods like value, onChange.

    Is there a way to reduce the process code and describe the relationship between multiple ui components? How can we use a way to use existing processes?

    Yes,we can use react-hooks, so the relationship between multiple antd components will be in react-hooks.

⚠️ Warning

This project is still under development.

📟  Usage

$ npm install sunflower-antd --save

Examples

useFormTable

image

import { Form, Table } from 'antd';
import { useFormTable } from 'sunflower-antd';
import request from './request';


function Component({ form }) {
  // return: formProps, tableProps, current, pageSize, formValues ...
  const { formProps, tableProps } = useFormTable({
    // form instance from props
    form,    

    // default page size, default: 10
    defaultPageSize: 5,

    // search method, params: current, pageSize, fitlers, sorter and form values(eg: username)
    async search({ current, pageSize, username, email }) {
      const result = await request({ current, pageSize, username, email });

      // just return { dataSource, total }
      return {
        dataSource: result.list,
        total: result.total,
      };
    }
  });
  return <div>
    <Form layout="inline" {...formProps}>
      <Form.Item label="Username">
        {
          form.getFieldDecorator('username')(
            <Input placeholder="Username" />
          )
        } 
      </Form.Item>

      <Form.Item label="Email">
        {
          form.getFieldDecorator('email')(
            <Input placeholder="Email" />
          )
        } 
      </Form.Item>

      <Form.Item>
        <Button onClick={() => form.resetFields()}>
          Reset
        </Button>
      </Form.Item>

      <Form.Item>
        <Button type="primary" htmlType="submit">
          Search
        </Button>
      </Form.Item>
    </Form>

    <Table
      columns={[
        {
          title: 'Username',
          dataIndex: 'username',
          key: 'username',
        },
        {
          title: 'Email',
          dataIndex: 'email',
          key: 'email',
        }
      ]}
      rowKey="id"
      {...tableProps}
    />
  </div>;
}

export default Form.create()(Component);

⚒  Development

$ yarn
$ yarn bootstrap
$ yarn dev       // dev
$ yarn build     // build
$ yarn test      // test

sunflower's People

Contributors

dependabot[bot] avatar jiacheng9 avatar mr-zyy avatar nitta-honoka avatar twisger avatar

Watchers

 avatar  avatar

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.