SwitchDemo_en.svelte 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!-- Switch Demo -->
  2. <script>
  3. import { Switch, Icon, Cell, Dialog } from 'stdf';
  4. let checkAsync = false;
  5. const switchClickFun = () => {
  6. setTimeout(() => {
  7. checkAsync = !checkAsync;
  8. }, 2000);
  9. };
  10. let cellCheck = false;
  11. const cellAsyncFun = () => {
  12. setTimeout(() => {
  13. cellCheck = !cellCheck;
  14. }, 2000);
  15. };
  16. let loading = false;
  17. let loadingCheck = false;
  18. const loadingFun = () => {
  19. loading = true;
  20. setTimeout(() => {
  21. loadingCheck = !loadingCheck;
  22. loading = false;
  23. }, 3000);
  24. };
  25. let cellLoading = false;
  26. let cellLoadingCheck = false;
  27. const cellLoadingFun = () => {
  28. cellLoading = true;
  29. setTimeout(() => {
  30. cellLoadingCheck = !cellLoadingCheck;
  31. cellLoading = false;
  32. }, 3000);
  33. };
  34. let visible = false;
  35. let confirmSwitcheck = false;
  36. const confirmFunc = () => {
  37. visible = false;
  38. confirmSwitcheck = !confirmSwitcheck;
  39. };
  40. const showDialogFunc = () => {
  41. visible = true;
  42. };
  43. </script>
  44. <div class="pb-8">
  45. <div class="flex flex-col space-y-8 py-8 px-4">
  46. <div>
  47. <div class="mb-4 font-bold">Different fillet</div>
  48. <div class="flex justify-between">
  49. <Switch />
  50. <Switch radius="none" />
  51. <Switch radius="full" />
  52. </div>
  53. </div>
  54. <div>
  55. <div class="mb-4 font-bold">Different colors</div>
  56. <div class="flex justify-between">
  57. <Switch check injClass="bg-success dark:bg-success" />
  58. <Switch check injClass="bg-error dark:bg-error" />
  59. <Switch check injClass="bg-warning dark:bg-warning" />
  60. <Switch check injClass="bg-[#DC88F5] dark:bg-[#FFCA28]" />
  61. </div>
  62. </div>
  63. <div>
  64. <div class="mb-4 font-bold">With text/status/icon</div>
  65. <div class="flex justify-between">
  66. <Switch inside={['OF', 'ON']} />
  67. <Switch inside={['😭', '😄']} />
  68. <Switch inside="state" />
  69. <!-- <Switch inside="state" radius="none" /> -->
  70. <Switch inside="slot">
  71. <div slot="false">
  72. <Icon name="ri-moon-line" size={16} top={-1} />
  73. </div>
  74. <div slot="true">
  75. <Icon name="ri-sun-line" size={16} top={-1} />
  76. </div>
  77. </Switch>
  78. </div>
  79. </div>
  80. <div>
  81. <div class="mb-4 font-bold">disable</div>
  82. <div class="flex justify-between">
  83. <Switch disabled />
  84. <Switch disabled check />
  85. </div>
  86. </div>
  87. <div>
  88. <div class="mb-4 font-bold">Asynchronous control</div>
  89. <div class="flex justify-between">
  90. <div class="flex flex-col space-y-2 items-center">
  91. <Switch async check={checkAsync} on:click={switchClickFun} />
  92. <div class="text-sm">Trigger after 2 seconds of clicking</div>
  93. </div>
  94. <div class="flex flex-col space-y-2 items-center">
  95. <Switch async check={loadingCheck} loading={{ theme: true }} on:click={loadingFun} inside={loading ? 'loading' : ''} />
  96. <div class="text-sm">Trigger after 3 seconds of clicking</div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <!-- <div>-->
  102. <div class="mb-4 font-bold px-4">Use in Cell</div>
  103. <Cell title="switch" detail="Click on the whole row to trigger the switch" right={{ type: 'switch' }} />
  104. <Cell title="Switch tape text" right={{ type: 'switch', switch: { inside: ['😭', '😄'] } }} switcheck />
  105. <Cell title="Switch with full rounded corners" right={{ type: 'switch', switch: { radius: 'full' } }} />
  106. <Cell
  107. title="Asynchronous control"
  108. detail="Click 2 seconds to trigger the switch"
  109. right={{ type: 'switch', switch: { async: true } }}
  110. switcheck={cellCheck}
  111. on:click={cellAsyncFun}
  112. />
  113. <Cell
  114. title="Asynchronous loading"
  115. detail="Click 3 seconds to trigger the switch"
  116. right={{ type: 'switch', switch: { async: true, inside: cellLoading ? 'loading' : '' } }}
  117. switcheck={cellLoadingCheck}
  118. on:click={cellLoadingFun}
  119. />
  120. <Cell title="Disable switch" right={{ type: 'switch', switch: { disabled: true } }} switcheck />
  121. <Cell
  122. title="Secondary confirmation"
  123. right={{ type: 'switch', switch: { async: true } }}
  124. bind:switcheck={confirmSwitcheck}
  125. on:click={showDialogFunc}
  126. />
  127. <Dialog bind:visible content={`determine ${confirmSwitcheck ? 'Shut down' : 'open'} this switch?`} on:primary={confirmFunc} />
  128. </div>