index.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import React, { useState } from 'react';
  2. import { Icon, Radio, RadioGroup, Button, ButtonGroup, Switch } from '@douyinfe/semi-ui/';
  3. import Popconfirm from '../..';
  4. import { strings } from '@douyinfe/semi-foundation/popconfirm/constants';
  5. import { IconAlertTriangle } from '@douyinfe/semi-icons';
  6. const defaultTitle = '确定是否要保存此修改?';
  7. const defaultContent = '此修改将不可逆';
  8. const typeMap = {
  9. default: {
  10. okType: 'primary',
  11. cancelType: 'primary',
  12. icon: 'alert_triangle',
  13. },
  14. warning: {
  15. okType: 'warning',
  16. cancelType: 'warning',
  17. icon: (
  18. <Icon
  19. style={{
  20. color: 'var(--semi-color-warning)',
  21. }}
  22. type={<IconAlertTriangle />}
  23. size="extra-large"
  24. />
  25. ),
  26. },
  27. danger: {
  28. okType: 'danger',
  29. cancelType: 'danger',
  30. icon: (
  31. <Icon
  32. style={{
  33. color: 'var(--semi-color-danger)',
  34. }}
  35. type={<IconAlertTriangle />}
  36. size="extra-large"
  37. />
  38. ),
  39. },
  40. tertiary: {
  41. okType: 'tertiary',
  42. cancelType: 'tertiary',
  43. icon: (
  44. <Icon
  45. style={{
  46. color: 'var(--semi-color-tertiary)',
  47. }}
  48. type={<IconAlertTriangle />}
  49. size="extra-large"
  50. />
  51. ),
  52. },
  53. };
  54. function Demo(props = {}) {
  55. const keys = Object.keys(typeMap);
  56. const [type, setType] = useState('default');
  57. const [title, setTitle] = useState(defaultTitle);
  58. const [content, setContent] = useState(defaultContent);
  59. const [icon, setIcon] = useState(typeMap[type].icon);
  60. const [visible, _setVisible] = useState(true);
  61. const changeType = e => {
  62. const type = e && e.target && e.target.value;
  63. if (type && keys.includes(type)) {
  64. setType(type);
  65. }
  66. };
  67. const setVisible = visible => _setVisible(visible);
  68. const toggleVisible = () => setVisible(!visible);
  69. const toggleTitle = () => setTitle(title ? null : defaultTitle);
  70. const toggleContent = () => setContent(content ? null : defaultContent);
  71. const toggleIcon = () => setIcon(icon ? null : typeMap[type].icon);
  72. return (
  73. <div>
  74. <RadioGroup
  75. onChange={changeType}
  76. value={type}
  77. style={{
  78. marginTop: 14,
  79. marginBottom: 14,
  80. }}
  81. >
  82. {keys.map(key => (
  83. <Radio key={key} value={key}>
  84. <strong
  85. style={{
  86. color: `var(--semi-color-${key === 'default' ? 'primary' : key})`,
  87. }}
  88. >
  89. {key}
  90. </strong>
  91. </Radio>
  92. ))}
  93. </RadioGroup>
  94. <div>
  95. <label>展示title</label>
  96. <Switch checked={Boolean(title)} onChange={toggleTitle} />
  97. </div>
  98. <div>
  99. <label>展示content</label>
  100. <Switch checked={Boolean(content)} onChange={toggleContent} />
  101. </div>
  102. <div>
  103. <label>展示icon</label>
  104. <Switch checked={Boolean(icon)} onChange={toggleIcon} />
  105. </div>
  106. <div
  107. style={{
  108. margin: 200,
  109. }}
  110. >
  111. {strings.POSITION_SET.map(pos => (
  112. <Popconfirm
  113. {...typeMap[type]}
  114. icon={icon}
  115. onVisibleChange={setVisible}
  116. title={title}
  117. content={content}
  118. key={pos}
  119. position={pos}
  120. arrowPointAtCenter
  121. showArrow
  122. >
  123. <Button onClick={toggleVisible}>点击此处 {pos}</Button>
  124. </Popconfirm>
  125. ))}
  126. </div>
  127. </div>
  128. );
  129. }
  130. export default Demo;