| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- import React, { useState } from 'react';
- import Popconfirm from '../index';
- import Button from '../../button';
- import Input from '../../input';
- import Table from '../../table';
- import Toast from '../../toast';
- import { Space } from '../../index';
- import TypesConfrimDemo from './TypesConfirm';
- import DynamicDisableDemo from './DynamicDisable';
- import TitleConfirmDemo from './TitlePopconfirm';
- import InTableDemo from './InTable';
- import ShowArrow from './ShowArrow';
- export default {
- title: 'Popconfirm',
- parameters: {
- chromatic: { disableSnapshot: true },
- },
- }
- let style = {
- display: 'inline-block',
- padding: '20px',
- };
- export const Simple = () => (
- <div>
- <div style={style}>
- <Popconfirm
- title="确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?"
- content="此修改将不可逆"
- >
- <a>Delete</a>
- </Popconfirm>
- </div>
- </div>
- );
- Simple.story = {
- name: 'simple',
- };
- export const _Button = () => (
- <div>
- <div style={style}>
- <Popconfirm position="bottomLeft" title="确定是否要保存此修改?" content="此修改将不可逆此修改将不可逆此修改将不可逆此修">
- <Button>Save</Button>
- </Popconfirm>
- </div>
- </div>
- );
- _Button.story = {
- name: 'button',
- };
- const dataSource = [
- {
- key: '1',
- name: 'John Brown',
- age: 32,
- address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
- },
- {
- key: '2',
- name: 'Jim Green',
- age: 42,
- address: 'London No. 1 Lake Park',
- },
- {
- key: '3',
- name: 'Joe Black',
- age: 32,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '4',
- name: 'Disabled User',
- age: 99,
- address: 'Sidney No. 1 Lake Park',
- },
- ];
- const columns = [
- {
- title: 'Name',
- dataIndex: 'name',
- render: text => (
- <Popconfirm position="bottomLeft" title="确定是否要保存此修改?" content="此修改将不可逆">
- <Button>{text}</Button>
- </Popconfirm>
- ),
- },
- {
- title: 'Age',
- dataIndex: 'age',
- },
- {
- title: 'Address',
- dataIndex: 'address',
- },
- ];
- export const _Table = () => (
- <div>
- <Table dataSource={dataSource} columns={columns} />
- </div>
- );
- _Table.story = {
- name: 'table',
- };
- export const TypesConfirm = () => <TypesConfrimDemo />;
- TypesConfirm.story = {
- name: 'types-confirm',
- };
- export const DynamicDisable = () => <DynamicDisableDemo />;
- DynamicDisable.story = {
- name: 'dynamic disable',
- };
- export const TitlePopconfirm = () => <TitleConfirmDemo />;
- TitlePopconfirm.story = {
- name: 'title popconfirm',
- };
- export const InTable = () => <InTableDemo />;
- InTable.story = {
- name: 'in table',
- };
- export const ShowArrowDemo = () => <ShowArrow />;
- ShowArrowDemo.style = {
- name: 'show arrow'
- }
- export const ClickOutSideDemo = () => {
- const [v, setV] = useState(false)
- const onConfirm = () => {
- Toast.success('确认保存!');
- };
- const onCancel = () => {
- Toast.warning('取消保存!');
- }
- return (
- <Popconfirm
- title="确定是否要保存此修改?"
- content="此修改将不可逆"
- visible={v}
- onClickOutSide={onCancel}
- onConfirm={onConfirm}
- onCancel={onCancel}
- >
- <Button onClick={() => setV(true)}>保存</Button>
- </Popconfirm>
- )
- }
- ClickOutSideDemo.story = {
- name: 'ClickOutSideDemo',
- };
- export const PromiseCallback = () => {
- const onConfirm = () => {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- console.log('ccc');
- resolve(1);
- }, 2000)
- })
- };
- const onCancel = () => {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- console.log('ccc');
- reject(1);
- }, 2000)
- })
- };
- return (
- <Popconfirm
- title="确定是否要保存此修改?"
- content="此修改将不可逆"
- onConfirm={onConfirm}
- onCancel={onCancel}
- >
- <Button>保存</Button>
- </Popconfirm>
- );
- };
- PromiseCallback.story = {
- name: 'PromiseCallbackDemo',
- };
- export const KeyboardAndFocus = () => {
- return (
- <div style={{ height: '150vh', marginTop: 200 }}>
- <Space>
- <div data-cy="initial-focus-confirm">
- <Popconfirm
- title="确定是否要保存此修改?"
- content="此修改将不可逆"
- okButtonProps={{
- autoFocus: true,
- type: 'danger',
- className: 'test-ok',
- }}
- >
- <Button>确认聚焦</Button>
- </Popconfirm>
- </div>
- <div data-cy="initial-focus-cancel">
- <Popconfirm
- title="确定是否要保存此修改?"
- content="此修改将不可逆"
- cancelButtonProps={{
- autoFocus: true,
- className: 'test-cancel',
- }}
- >
- <Button>取消聚焦</Button>
- </Popconfirm>
- </div>
- <div data-cy="initial-focus-content">
- <Popconfirm
- title="确定是否要保存此修改?"
- content={({ initialFocusRef }) => {
- return <input ref={initialFocusRef} placeholder="focus here" />;
- }}
- >
- <Button>内容聚焦</Button>
- </Popconfirm>
- </div>
- </Space>
- </div>
- );
- };
- KeyboardAndFocus.storyName = "a11y focus";
- export const ESCKeyDown = () => {
- return (
- <div style={{ height: '150vh', marginTop: 200 }}>
- <Space>
- <div data-cy="content">
- <Popconfirm
- title="确定是否要保存此修改?"
- content="此修改将不可逆"
- okButtonProps={{
- autoFocus: true,
- className: 'test-ok',
- }}
- >
- <Button>content</Button>
- </Popconfirm>
- </div>
- <div data-cy="trigger">
- <Popconfirm
- title="确定是否要保存此修改?"
- content={<div onClick={() => console.log('clicked')} className='test-text'>此修改将不可逆</div>}
- okButtonProps={{ autoFocus: true }}
- >
- <Button>trigger</Button>
- </Popconfirm>
- </div>
- </Space>
- </div>
- );
- };
- ESCKeyDown.storyName = "a11y esc keydown";
|