InputDemo_en.svelte 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <!-- Input Demo -->
  2. <script>
  3. import { getContext } from 'svelte';
  4. import { Input, Button, Icon, Toast } from 'stdf';
  5. let value = 'Init text';
  6. let visible = false;
  7. let IdCard = '';
  8. const isIframe = getContext('iframe') === '1'; //判断是否是iframe
  9. $: placeholderIdCard = IdCard === '' ? 'Please enter identification number' : '';
  10. const clickLabel4Fun = () => {
  11. placeholderIdCard = 'After two seconds, the recognition is complete......';
  12. setTimeout(() => {
  13. IdCard = '1234567890XXX-XX';
  14. }, 2000);
  15. };
  16. let mobileLength = 0;
  17. const changeStateFun = e => {
  18. mobileLength = e.detail.length;
  19. };
  20. $: mobileState = mobileLength === 11 ? 'success' : mobileLength === 0 ? 'theme' : 'error';
  21. </script>
  22. <div class="px-4 pt-8 font-bold text-xl">Basic usage</div>
  23. <Input title="text" />
  24. <div class="px-4 pt-8 font-bold text-xl">Without the title</div>
  25. <Input placeholder="Please enter the text" />
  26. <div class="px-4 pt-8 font-bold text-xl">customize placeholder</div>
  27. <Input title="text" placeholder="customize placeholder" />
  28. <div class="px-4 pt-8 font-bold text-xl">
  29. Different input types
  30. {#if isIframe}
  31. <span class="text-xs opacity-50 ml-2">Please check the keyboard type on your mobile device.</span>
  32. {/if}
  33. </div>
  34. <Input title="Any text (conventional keyboard)" />
  35. <Input title="password" type="password" />
  36. <Input title="Number (arbitrarily)" type="number" />
  37. <Input title="Number (integer)" type="numeric" />
  38. <Input title="Number (allowing decimal points)" type="decimal" />
  39. <Input title="Mail" type="email" />
  40. <Input title="telephone number" type="tel" />
  41. <Input title="Url" type="url" />
  42. <Input title="Search" type="search" />
  43. <Input title="Text (not using virtual keyboard)" type="none" />
  44. <div class="px-4 pt-8 font-bold text-xl">Linear style</div>
  45. <Input title="text" inputStyle="line" />
  46. <Input title="Text (the line of the line is in the middle of the line)" inputStyle="line" lineTransition="center" />
  47. <Input title="Text (transition from the left side of the line)" inputStyle="line" lineTransition="left" />
  48. <div class="px-4 pt-8 font-bold text-xl">Different transition time</div>
  49. <Input title="quick" duration="fast" />
  50. <Input title="normal" />
  51. <Input title="Slower" duration="slower" />
  52. <Input title="line normally" inputStyle="line" lineTransition="center" />
  53. <Input title="line slower" inputStyle="line" lineTransition="center" duration="slower" />
  54. <div class="px-4 pt-8 font-bold text-xl">Different title positions</div>
  55. <Input title="Title (outside)" />
  56. <Input title="Title (inside)" titlePosition="in" />
  57. <Input title="Title (none)" titlePosition="none" />
  58. <div class="px-4 pt-8 font-bold text-xl">Different input text position</div>
  59. <Input title="text" />
  60. <Input title="text" inputPosition="right" />
  61. <div class="px-4 pt-8 font-bold text-xl">Different rounded style</div>
  62. <Input title="text" />
  63. <Input title="text" radius="xl" />
  64. <Input title="text" radius="full" />
  65. <Input title="text" radius="none" />
  66. <Input title="Linear style rounded corners are invalid" radius="full" inputStyle="line" />
  67. <div class="px-4 pt-8 font-bold text-xl">Different vertical spacing</div>
  68. <Input placeholder="Spacing 0" py="0" inputStyle="line" />
  69. <Input placeholder="Spacing 0" py="0" inputStyle="line" />
  70. <Input placeholder="Spacing 0" py="0" inputStyle="line" />
  71. <Input placeholder="Spacing 4" py="4" inputStyle="line" />
  72. <Input placeholder="Spacing 4" py="4" inputStyle="line" />
  73. <Input placeholder="Spacing 4" py="4" inputStyle="line" />
  74. <div class="px-4 pt-8 font-bold text-xl">Removal</div>
  75. <Input title="text" clear />
  76. <div class="px-4 pt-8 font-bold text-xl">Disable</div>
  77. <Input title="text" disabled value="Disabled" />
  78. <div class="px-4 pt-8 font-bold text-xl">Different states</div>
  79. <Input title="success" state="success" />
  80. <Input title="warning" state="warning" />
  81. <Input title="error" state="error" />
  82. <Input title="info" state="info" />
  83. <Input title="warning & line" inputStyle="line" state="error" />
  84. <Input title="warning & line & Animation" inputStyle="line" state="error" lineTransition="center" />
  85. <Input
  86. title="Dynamic change status color"
  87. type="tel"
  88. placeholder="Please enter the 11 -digit mobile phone number"
  89. maxlength={11}
  90. state={mobileState}
  91. on:change={changeStateFun}
  92. />
  93. <div class="px-4 pt-8 font-bold text-xl">Left with icon</div>
  94. <Input title="password" type="password" label1={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }} />
  95. <Input
  96. title="username"
  97. label1={{ name: 'ri-arrow-down-s-line', size: 16, alpha: 0.5 }}
  98. label3={{ name: 'ri-shield-user-line', size: 16, alpha: 0.5 }}
  99. />
  100. <div class="px-4 pt-8 font-bold text-xl">Left with text</div>
  101. <Input title="account" label2="account" />
  102. <div class="px-4 pt-8 font-bold text-xl">The left with icon and text</div>
  103. <Input title="password" type="password" label1={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }} label2="password" />
  104. <div class="px-4 pt-8 font-bold text-xl">The left with text and icon</div>
  105. <Input title="password" type="password" label2="password" label3={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }} />
  106. <div class="px-4 pt-8 font-bold text-xl">left with icon & text & icon</div>
  107. <Input
  108. title="password"
  109. type="password"
  110. label1={{ name: 'ri-bank-line', size: 16, alpha: 0.5 }}
  111. label2="password"
  112. label3={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }}
  113. />
  114. <div class="px-4 pt-8 font-bold text-xl">left with icon</div>
  115. <Input title="ID number" label4={{ name: 'ri-qr-scan-line', size: 16, alpha: 0.5 }} />
  116. <Input
  117. title="User"
  118. label4={{ name: 'ri-arrow-down-s-line', size: 16, alpha: 0.5 }}
  119. label6={{ name: 'ri-shield-user-line', size: 16, alpha: 0.5 }}
  120. />
  121. <div class="px-4 pt-8 font-bold text-xl">right with text</div>
  122. <Input title="Amount" type="number" label5="$" />
  123. <div class="px-4 pt-8 font-bold text-xl">right with iocn and text</div>
  124. <Input title="password" type="password" label4={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }} label5="password" />
  125. <div class="px-4 pt-8 font-bold text-xl">right with text and icon</div>
  126. <Input title="password" type="password" label5="password" label6={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }} />
  127. <div class="px-4 pt-8 font-bold text-xl">right with icon & text & icon</div>
  128. <Input
  129. title="password"
  130. type="password"
  131. label4={{ name: 'ri-bank-line', size: 16, alpha: 0.5 }}
  132. label5="password"
  133. label6={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }}
  134. />
  135. <div class="px-4 pt-8 font-bold text-xl">left with text, right with icon</div>
  136. <Input label2="身份证号" label6={{ name: 'ri-qr-scan-line', size: 16, alpha: 0.5 }} placeholder="请输入身份证号" />
  137. <div class="px-4 pt-8 font-bold text-xl">Six left and right all band</div>
  138. <Input
  139. title="password"
  140. type="password"
  141. label1={{ name: 'ri-bank-line', size: 16, alpha: 0.5 }}
  142. label2="password"
  143. label3={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }}
  144. label4={{ name: 'ri-bank-line', size: 16, alpha: 0.5 }}
  145. label5="password"
  146. label6={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }}
  147. />
  148. <div class="px-4 pt-8 font-bold text-xl">Prompt information and data item combination</div>
  149. <Input title="text" tip="Prompt information" />
  150. <Input title="text" data1="data1" />
  151. <Input title="text" data1="data1" data2="data2" />
  152. <Input title="text" data3="data3" />
  153. <Input title="text" data1="data1" tip="information" />
  154. <Input title="text" data3="data3" tip="information" />
  155. <div class="px-4 pt-8 font-bold text-xl">Show all configuration items</div>
  156. <Input
  157. title="title"
  158. placeholder="Please enter the text"
  159. label1={{ name: 'ri-bank-line', size: 16, alpha: 0.5 }}
  160. label2="label2"
  161. label3={{ name: 'ri-lock-line', size: 16, alpha: 0.5 }}
  162. label4={{ name: 'ri-bank-line', size: 16, alpha: 0.5 }}
  163. label5="label5"
  164. label6={{ name: 'ri-qr-scan-line', size: 16, alpha: 0.5 }}
  165. data1="data1"
  166. data2="data2"
  167. data3="data3"
  168. tip="tip"
  169. clear
  170. />
  171. <div class="px-4 pt-8 font-bold text-xl">label1 and label4 use slot</div>
  172. <Input title="Verification code" label1="slot" label4="slot">
  173. <div slot="label1">
  174. <svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">
  175. <path
  176. d="M511.198384 637.07798c-17.170101 0-31.08202 13.911919-31.08202 31.08202v124.302222c0 17.157172 13.924848 31.08202 31.08202 31.08202s31.069091-13.924848 31.069091-31.08202v-124.302222c0-17.170101-13.911919-31.08202-31.069091-31.08202z m0 0"
  177. fill="#515151"
  178. />
  179. <path
  180. d="M759.815758 513.331717V264.145455C759.815758 126.823434 648.520404 15.515152 511.198384 15.515152c-137.309091 0-248.630303 111.308283-248.630303 248.630303v249.186262C223.702626 565.20404 200.40404 629.423838 200.40404 699.229091c0 171.649293 139.145051 310.794343 310.794344 310.794343s310.794343-139.145051 310.794343-310.794343c0-69.805253-23.311515-134.025051-62.176969-185.897374zM324.719192 264.145455c0-102.994747 83.497374-186.479192 186.479192-186.479192 102.981818 0 186.466263 83.484444 186.466262 186.479192v186.88c-51.975758-39.111111-116.402424-62.577778-186.466262-62.577778s-134.490505 23.453737-186.479192 62.577778V264.145455z m186.479192 683.726868c-137.309091 0-248.630303-111.321212-248.630303-248.643232 0-137.309091 111.308283-248.617374 248.630303-248.617374 132.628687 0 248.617374 115.988687 248.617374 248.617374 0 137.32202-111.295354 248.643232-248.617374 248.643232z m0 0"
  181. fill="#515151"
  182. />
  183. </svg>
  184. </div>
  185. <div slot="label4">
  186. <Button size="auto" heightOut="0" heightIn="1" fill="lineTheme">
  187. <div class="px-2">Get code</div>
  188. </Button>
  189. </div>
  190. </Input>
  191. <div class="px-4 pt-8 font-bold text-xl">Dynamic display</div>
  192. <Input
  193. title="Dynamic display label5"
  194. type="tel"
  195. placeholder="Please enter the 11 -digit mobile phone number"
  196. maxlength={11}
  197. state={mobileState}
  198. on:change={changeStateFun}
  199. label5="slot"
  200. >
  201. <div slot="label5">
  202. {#if mobileLength === 11}
  203. <Icon name="ri-check-fill" injClass="text-[green]" size={14} />
  204. {:else if mobileLength === 0}
  205. <!-- none -->
  206. {:else}
  207. <Icon name="ri-close-fill" injClass="text-[red]" size={14} />
  208. {/if}
  209. </div>
  210. </Input>
  211. <div class="px-4 pt-8 font-bold text-xl">bind value</div>
  212. <Input title="text" bind:value />
  213. <Button on:click={() => (visible = true)}>Display the current value</Button>
  214. <Toast bind:visible message={`Currently entering text:${value}`} />
  215. <div class="px-4 pt-8 font-bold text-xl">click label4 trigger event</div>
  216. <Input
  217. title="ID number"
  218. placeholder={placeholderIdCard}
  219. bind:value={IdCard}
  220. label4={{ name: 'ri-qr-scan-line', size: 16, alpha: 0.5 }}
  221. on:clicklabel4={clickLabel4Fun}
  222. clear
  223. />
  224. <div class="px-4 pt-8 font-bold text-xl">textarea</div>
  225. <Input placeholder="Please enter the content" type="textarea" />
  226. <div class="px-4 pt-8 font-bold text-xl">textarea automatic height</div>
  227. <Input placeholder="Please enter the content" type="textarea" autosize />