1.0.3 • Published 2 years ago

@jswork/react-ant-status-switch v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

react-ant-status-switch

React status swicher component based on antd.

version license size download

installation

yarn add @jswork/react-ant-status-switch

usage

  1. import js

    import React, { useState } from 'react';
    import ReactAntStatusSwitch from '@/main';
    import styled from 'styled-components';
    import { Button } from 'antd';
    
    const Container = styled.div`
      width: 80%;
      margin: 100px auto 0;
      p {
        margin-top: 10px;
      }
    `;
    
    const items = [
      {
        value: 'default',
        label: '默认 🤔'
      },
      {
        value: 'success',
        label: '成功 šŸ˜Ž'
      },
      {
        value: 'warning',
        label: 'č­¦å‘Š 🄸'
      },
      {
        value: 'error',
        label: '失蓄 😤'
      },
      {
        value: 'customize',
        color: '#080',
        label: 'č‡Ŗå®šä¹‰ēŠ¶ę€ 🤩'
      }
    ];
    
    export default () => {
      const [val, setVal] = useState('success');
      return (
        <Container>
          <p>č½»č½»ēš„ē§»å‘ęˆ‘ļ¼Œęˆ‘ä¼šę”¹å˜ēŠ¶ę€ę»“.</p>
          <ReactAntStatusSwitch
            value={val}
            items={items}
            layout={'flat'}
            popoverOpts={{ placement: 'top' }}
            onChange={(e) => {
              console.log('e.', e.target.value);
              setVal(e.target.value);
            }}
          />
    
          <ReactAntStatusSwitch
            value={val}
            items={items}
            layout={'popover'}
            popoverOpts={{ placement: 'top' }}
            onChange={(e) => {
              console.log('e.', e.target.value);
              setVal(e.target.value);
            }}
          />
    
          <p>
            Current status: <strong>{val}</strong>
          </p>
    
          <p>Only tag status</p>
    
          <ReactAntStatusSwitch value={val} items={items} layout={'tag'} />
    
          <p>
            <Button type="primary" onClick={() => setVal('success')}>
              Force to Set status
            </Button>
          </p>
        </Container>
      );
    };

preview

license

Code released under the MIT license.