slotDemo.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React, { useState, useLayoutEffect } from 'react';
  2. import { Form, Select } from '../../../index';
  3. import { IconSemiLogo } from '@douyinfe/semi-icons';
  4. const { Option } = Select;
  5. class AssistComponent extends React.Component {
  6. render() {
  7. return (
  8. <>
  9. <Form
  10. onChange={v => console.log(v)}
  11. onSubmit={v => console.log(v)}
  12. style={{
  13. width: 600,
  14. }}
  15. labelPosition="left"
  16. labelWidth={100}
  17. >
  18. <Form.Input
  19. field="特效名称"
  20. style={{
  21. width: 250,
  22. }}
  23. trigger="blur"
  24. rules={[
  25. {
  26. required: true,
  27. },
  28. ]}
  29. />
  30. <Form.Select
  31. style={{
  32. width: 250,
  33. }}
  34. field="type"
  35. label="特效类型"
  36. >
  37. <Option value="脸部贴纸">脸部贴纸</Option>
  38. <Option value="前景贴纸">前景贴纸</Option>
  39. </Form.Select>
  40. <Form.ErrorMessage />
  41. <Form.Slot
  42. label={{
  43. text: 'SlotA',
  44. required: true,
  45. }}
  46. >
  47. <div
  48. style={{
  49. display: 'flex',
  50. alignItems: 'center',
  51. height: '100%',
  52. }}
  53. >
  54. 我是Semi Form SlotA, 我是自定义的ReactNode
  55. </div>
  56. </Form.Slot>
  57. <Form.Slot label="string Label">
  58. <div
  59. style={{
  60. display: 'flex',
  61. alignItems: 'center',
  62. height: '100%',
  63. }}
  64. >
  65. 我是一个传string label的slot
  66. </div>
  67. </Form.Slot>
  68. <Form.Slot label={<IconSemiLogo />}>
  69. <div
  70. style={{
  71. display: 'flex',
  72. alignItems: 'center',
  73. height: '100%',
  74. }}
  75. >
  76. 我是一个传ReactNode label的slot
  77. </div>
  78. </Form.Slot>
  79. <Form.Slot label={<IconSemiLogo />} error={'我是slot的错误信息'}>
  80. <div>我是一个带error的slot</div>
  81. </Form.Slot>
  82. <Form.Slot
  83. label={{
  84. text: 'SlotB',
  85. width: 170,
  86. align: 'right',
  87. }}
  88. >
  89. <div
  90. style={{
  91. display: 'flex',
  92. alignItems: 'center',
  93. height: '100%',
  94. }}
  95. >
  96. 我是Semi Form SlotB, 我的Label Align、Width与众不同
  97. </div>
  98. </Form.Slot>
  99. </Form>
  100. <Form.Slot
  101. label={{
  102. text: 'SlotB',
  103. width: 170,
  104. align: 'right',
  105. extra: 'se',
  106. required: true,
  107. }}
  108. >
  109. <div
  110. style={{
  111. display: 'flex',
  112. alignItems: 'center',
  113. height: '100%',
  114. }}
  115. >
  116. 我是Slot,我并没有被Form包裹,我是单独使用的
  117. </div>
  118. </Form.Slot>
  119. </>
  120. );
  121. }
  122. }
  123. export { AssistComponent };