popconfirm.stories.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import React, { useState } from 'react';
  2. import Popconfirm from '../index';
  3. import Button from '../../button';
  4. import Input from '../../input';
  5. import Table from '../../table';
  6. import Toast from '../../toast';
  7. import TypesConfrimDemo from './TypesConfirm';
  8. import DynamicDisableDemo from './DynamicDisable';
  9. import TitleConfirmDemo from './TitlePopconfirm';
  10. import InTableDemo from './InTable';
  11. import ShowArrow from './ShowArrow';
  12. export default {
  13. title: 'Popconfirm',
  14. parameters: {
  15. chromatic: { disableSnapshot: true },
  16. },
  17. }
  18. let style = {
  19. display: 'inline-block',
  20. padding: '20px',
  21. };
  22. export const Simple = () => (
  23. <div>
  24. <div style={style}>
  25. <Popconfirm
  26. title="确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?"
  27. content="此修改将不可逆"
  28. >
  29. <a>Delete</a>
  30. </Popconfirm>
  31. </div>
  32. </div>
  33. );
  34. Simple.story = {
  35. name: 'simple',
  36. };
  37. export const _Button = () => (
  38. <div>
  39. <div style={style}>
  40. <Popconfirm position="bottomLeft" title="确定是否要保存此修改?" content="此修改将不可逆">
  41. <Button>Save</Button>
  42. </Popconfirm>
  43. </div>
  44. </div>
  45. );
  46. _Button.story = {
  47. name: 'button',
  48. };
  49. const dataSource = [
  50. {
  51. key: '1',
  52. name: 'John Brown',
  53. age: 32,
  54. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  55. },
  56. {
  57. key: '2',
  58. name: 'Jim Green',
  59. age: 42,
  60. address: 'London No. 1 Lake Park',
  61. },
  62. {
  63. key: '3',
  64. name: 'Joe Black',
  65. age: 32,
  66. address: 'Sidney No. 1 Lake Park',
  67. },
  68. {
  69. key: '4',
  70. name: 'Disabled User',
  71. age: 99,
  72. address: 'Sidney No. 1 Lake Park',
  73. },
  74. ];
  75. const columns = [
  76. {
  77. title: 'Name',
  78. dataIndex: 'name',
  79. render: text => (
  80. <Popconfirm position="bottomLeft" title="确定是否要保存此修改?" content="此修改将不可逆">
  81. <Button>{text}</Button>
  82. </Popconfirm>
  83. ),
  84. },
  85. {
  86. title: 'Age',
  87. dataIndex: 'age',
  88. },
  89. {
  90. title: 'Address',
  91. dataIndex: 'address',
  92. },
  93. ];
  94. export const _Table = () => (
  95. <div>
  96. <Table dataSource={dataSource} columns={columns} />
  97. </div>
  98. );
  99. _Table.story = {
  100. name: 'table',
  101. };
  102. export const TypesConfirm = () => <TypesConfrimDemo />;
  103. TypesConfirm.story = {
  104. name: 'types-confirm',
  105. };
  106. export const DynamicDisable = () => <DynamicDisableDemo />;
  107. DynamicDisable.story = {
  108. name: 'dynamic disable',
  109. };
  110. export const TitlePopconfirm = () => <TitleConfirmDemo />;
  111. TitlePopconfirm.story = {
  112. name: 'title popconfirm',
  113. };
  114. export const InTable = () => <InTableDemo />;
  115. InTable.story = {
  116. name: 'in table',
  117. };
  118. export const ShowArrowDemo = () => <ShowArrow />;
  119. ShowArrowDemo.style = {
  120. name: 'show arrow'
  121. }
  122. export const ClickOutSideDemo = () => {
  123. const [v, setV] = useState(false)
  124. const onConfirm = () => {
  125. Toast.success('确认保存!');
  126. };
  127. const onCancel = () => {
  128. Toast.warning('取消保存!');
  129. }
  130. return (
  131. <Popconfirm
  132. title="确定是否要保存此修改?"
  133. content="此修改将不可逆"
  134. visible={v}
  135. onClickOutSide={onCancel}
  136. onConfirm={onConfirm}
  137. onCancel={onCancel}
  138. >
  139. <Button onClick={() => setV(true)}>保存</Button>
  140. </Popconfirm>
  141. )
  142. }
  143. ClickOutSideDemo.story = {
  144. name: 'ClickOutSideDemo',
  145. };