popconfirm.stories.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 { Space } from '../../index';
  8. import TypesConfrimDemo from './TypesConfirm';
  9. import DynamicDisableDemo from './DynamicDisable';
  10. import TitleConfirmDemo from './TitlePopconfirm';
  11. import InTableDemo from './InTable';
  12. import ShowArrow from './ShowArrow';
  13. export default {
  14. title: 'Popconfirm',
  15. parameters: {
  16. chromatic: { disableSnapshot: true },
  17. },
  18. }
  19. let style = {
  20. display: 'inline-block',
  21. padding: '20px',
  22. };
  23. export const Simple = () => (
  24. <div>
  25. <div style={style}>
  26. <Popconfirm
  27. title="确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?确定是否要保存此修改?"
  28. content="此修改将不可逆"
  29. >
  30. <a>Delete</a>
  31. </Popconfirm>
  32. </div>
  33. </div>
  34. );
  35. Simple.story = {
  36. name: 'simple',
  37. };
  38. export const _Button = () => (
  39. <div>
  40. <div style={style}>
  41. <Popconfirm position="bottomLeft" title="确定是否要保存此修改?" content="此修改将不可逆此修改将不可逆此修改将不可逆此修">
  42. <Button>Save</Button>
  43. </Popconfirm>
  44. </div>
  45. </div>
  46. );
  47. _Button.story = {
  48. name: 'button',
  49. };
  50. const dataSource = [
  51. {
  52. key: '1',
  53. name: 'John Brown',
  54. age: 32,
  55. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  56. },
  57. {
  58. key: '2',
  59. name: 'Jim Green',
  60. age: 42,
  61. address: 'London No. 1 Lake Park',
  62. },
  63. {
  64. key: '3',
  65. name: 'Joe Black',
  66. age: 32,
  67. address: 'Sidney No. 1 Lake Park',
  68. },
  69. {
  70. key: '4',
  71. name: 'Disabled User',
  72. age: 99,
  73. address: 'Sidney No. 1 Lake Park',
  74. },
  75. ];
  76. const columns = [
  77. {
  78. title: 'Name',
  79. dataIndex: 'name',
  80. render: text => (
  81. <Popconfirm position="bottomLeft" title="确定是否要保存此修改?" content="此修改将不可逆">
  82. <Button>{text}</Button>
  83. </Popconfirm>
  84. ),
  85. },
  86. {
  87. title: 'Age',
  88. dataIndex: 'age',
  89. },
  90. {
  91. title: 'Address',
  92. dataIndex: 'address',
  93. },
  94. ];
  95. export const _Table = () => (
  96. <div>
  97. <Table dataSource={dataSource} columns={columns} />
  98. </div>
  99. );
  100. _Table.story = {
  101. name: 'table',
  102. };
  103. export const TypesConfirm = () => <TypesConfrimDemo />;
  104. TypesConfirm.story = {
  105. name: 'types-confirm',
  106. };
  107. export const DynamicDisable = () => <DynamicDisableDemo />;
  108. DynamicDisable.story = {
  109. name: 'dynamic disable',
  110. };
  111. export const TitlePopconfirm = () => <TitleConfirmDemo />;
  112. TitlePopconfirm.story = {
  113. name: 'title popconfirm',
  114. };
  115. export const InTable = () => <InTableDemo />;
  116. InTable.story = {
  117. name: 'in table',
  118. };
  119. export const ShowArrowDemo = () => <ShowArrow />;
  120. ShowArrowDemo.style = {
  121. name: 'show arrow'
  122. }
  123. export const ClickOutSideDemo = () => {
  124. const [v, setV] = useState(false)
  125. const onConfirm = () => {
  126. Toast.success('确认保存!');
  127. };
  128. const onCancel = () => {
  129. Toast.warning('取消保存!');
  130. }
  131. return (
  132. <Popconfirm
  133. title="确定是否要保存此修改?"
  134. content="此修改将不可逆"
  135. visible={v}
  136. onClickOutSide={onCancel}
  137. onConfirm={onConfirm}
  138. onCancel={onCancel}
  139. >
  140. <Button onClick={() => setV(true)}>保存</Button>
  141. </Popconfirm>
  142. )
  143. }
  144. ClickOutSideDemo.story = {
  145. name: 'ClickOutSideDemo',
  146. };
  147. export const PromiseCallback = () => {
  148. const onConfirm = () => {
  149. return new Promise((resolve, reject) => {
  150. setTimeout(() => {
  151. console.log('ccc');
  152. resolve(1);
  153. }, 2000)
  154. })
  155. };
  156. const onCancel = () => {
  157. return new Promise((resolve, reject) => {
  158. setTimeout(() => {
  159. console.log('ccc');
  160. reject(1);
  161. }, 2000)
  162. })
  163. };
  164. return (
  165. <Popconfirm
  166. title="确定是否要保存此修改?"
  167. content="此修改将不可逆"
  168. onConfirm={onConfirm}
  169. onCancel={onCancel}
  170. >
  171. <Button>保存</Button>
  172. </Popconfirm>
  173. );
  174. };
  175. PromiseCallback.story = {
  176. name: 'PromiseCallbackDemo',
  177. };
  178. export const KeyboardAndFocus = () => {
  179. return (
  180. <div style={{ height: '150vh', marginTop: 200 }}>
  181. <Space>
  182. <div data-cy="initial-focus-confirm">
  183. <Popconfirm
  184. title="确定是否要保存此修改?"
  185. content="此修改将不可逆"
  186. okButtonProps={{
  187. autoFocus: true,
  188. type: 'danger',
  189. className: 'test-ok',
  190. }}
  191. >
  192. <Button>确认聚焦</Button>
  193. </Popconfirm>
  194. </div>
  195. <div data-cy="initial-focus-cancel">
  196. <Popconfirm
  197. title="确定是否要保存此修改?"
  198. content="此修改将不可逆"
  199. cancelButtonProps={{
  200. autoFocus: true,
  201. className: 'test-cancel',
  202. }}
  203. >
  204. <Button>取消聚焦</Button>
  205. </Popconfirm>
  206. </div>
  207. <div data-cy="initial-focus-content">
  208. <Popconfirm
  209. title="确定是否要保存此修改?"
  210. content={({ initialFocusRef }) => {
  211. return <input ref={initialFocusRef} placeholder="focus here" />;
  212. }}
  213. >
  214. <Button>内容聚焦</Button>
  215. </Popconfirm>
  216. </div>
  217. </Space>
  218. </div>
  219. );
  220. };
  221. KeyboardAndFocus.storyName = "a11y focus";
  222. export const ESCKeyDown = () => {
  223. return (
  224. <div style={{ height: '150vh', marginTop: 200 }}>
  225. <Space>
  226. <div data-cy="content">
  227. <Popconfirm
  228. title="确定是否要保存此修改?"
  229. content="此修改将不可逆"
  230. okButtonProps={{
  231. autoFocus: true,
  232. className: 'test-ok',
  233. }}
  234. >
  235. <Button>content</Button>
  236. </Popconfirm>
  237. </div>
  238. <div data-cy="trigger">
  239. <Popconfirm
  240. title="确定是否要保存此修改?"
  241. content={<div onClick={() => console.log('clicked')} className='test-text'>此修改将不可逆</div>}
  242. okButtonProps={{ autoFocus: true }}
  243. >
  244. <Button>trigger</Button>
  245. </Popconfirm>
  246. </div>
  247. </Space>
  248. </div>
  249. );
  250. };
  251. ESCKeyDown.storyName = "a11y esc keydown";