TimePickerDemo_en.svelte 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!-- TimePickerDemo Demo -->
  2. <script>
  3. import { Cell, TimePicker } from '../../../../components';
  4. let visible1 = false;
  5. let visible2 = false;
  6. let visible3 = false;
  7. let visible4 = false;
  8. let visible5 = false;
  9. let visible6 = false;
  10. let visible7 = false;
  11. let visible8 = false;
  12. let visible9 = false;
  13. let visible10 = false;
  14. let visible11 = false;
  15. let visible12 = false;
  16. let visible13 = false;
  17. let visible14 = false;
  18. let visible15 = false;
  19. let visible16 = false;
  20. let visible17 = false;
  21. let visible18 = false;
  22. let visible19 = false;
  23. let visible20 = false;
  24. let visible21 = false;
  25. let visible22 = false;
  26. let defaultTimeStr = '';
  27. const getDefaultFunc = e => {
  28. defaultTimeStr = e.detail.times;
  29. };
  30. let customFormatStr = '';
  31. const customFormatFunc = e => {
  32. customFormatStr = e.detail.times;
  33. };
  34. let monthFirstStr = '';
  35. const monthFirstFunc = e => {
  36. monthFirstStr = e.detail.times;
  37. };
  38. let timeObj = {};
  39. $: timeObjStr = JSON.stringify(timeObj);
  40. const getTimeObjFunc = e => {
  41. timeObj = e.detail.times;
  42. };
  43. </script>
  44. <div class="py-4">
  45. <div class="px-4">
  46. {#if defaultTimeStr !== ''}
  47. Currently selected:
  48. <span class="mr-2 text-primary dark:text-dark">{defaultTimeStr}</span>
  49. {:else}
  50. <div>Please select the time</div>
  51. {/if}
  52. </div>
  53. <Cell
  54. title="Basic usage"
  55. subTitle="By default, the current time is selected. 10 years is optional"
  56. on:click={() => (visible1 = true)}
  57. />
  58. <TimePicker bind:visible={visible1} on:confirm={getDefaultFunc} />
  59. <Cell title="Just the year, the month and the day" on:click={() => (visible2 = true)} />
  60. <TimePicker bind:visible={visible2} type="YMD" />
  61. <Cell
  62. title="Misrepresentation unsupported type"
  63. subTitle="Use the default year, month, day, hour and second"
  64. on:click={() => (visible7 = true)}
  65. />
  66. <TimePicker bind:visible={visible7} type="MD" />
  67. <Cell title="Just use the minutes and seconds" on:click={() => (visible3 = true)} />
  68. <TimePicker bind:visible={visible3} type="hms" />
  69. <Cell title="Just the year, the month, the day" on:click={() => (visible4 = true)} />
  70. <TimePicker bind:visible={visible4} type="YMDh" />
  71. <Cell title="Do not display prompt" on:click={() => (visible5 = true)} />
  72. <TimePicker bind:visible={visible5} showTips={false} />
  73. <Cell title="Different columns have different visible rows" on:click={() => (visible6 = true)} />
  74. <TimePicker
  75. bind:visible={visible6}
  76. yearProps={{ showRow: 3 }}
  77. hourProps={{ showRow: 7 }}
  78. minuteProps={{ showRow: 7 }}
  79. secondProps={{ showRow: 7 }}
  80. />
  81. <Cell title="Different columns have different widths" on:click={() => (visible8 = true)} />
  82. <TimePicker bind:visible={visible8} yearProps={{ flex: 3 }} dayProps={{ flex: 2 }} />
  83. <Cell title="Align annual data to the right and daily data to the left" on:click={() => (visible22 = true)} />
  84. <TimePicker bind:visible={visible22} type="YMD" yearProps={{ align: 'right' }} dayProps={{ align: 'left' }} />
  85. <Cell title="Limited year interval" on:click={() => (visible9 = true)} />
  86. <TimePicker bind:visible={visible9} yearRange={[2022, 2025]} />
  87. <Cell title="Limited month range" on:click={() => (visible10 = true)} />
  88. <TimePicker bind:visible={visible10} monthRange={[2, 5]} />
  89. <Cell title="Limited time interval" on:click={() => (visible11 = true)} />
  90. <TimePicker bind:visible={visible11} hourRange={[2, 5]} minuteRange={[25, 45]} secondRange={[5, 10]} />
  91. <Cell title="The minute step length is 5" on:click={() => (visible12 = true)} />
  92. <TimePicker bind:visible={visible12} minuteStep={5} />
  93. <Cell title="The second step is 10" on:click={() => (visible13 = true)} />
  94. <TimePicker bind:visible={visible13} secondStep={10} />
  95. <div class="px-4">
  96. {#if customFormatStr !== ''}
  97. Currently selected:
  98. <span class="mr-2 text-primary dark:text-dark">{customFormatStr}</span>
  99. {:else}
  100. <div>Please select the time</div>
  101. {/if}
  102. </div>
  103. <Cell
  104. title="User-defined return time format"
  105. subTitle="The output format is Y year M month D day h hour m minute s second"
  106. on:click={() => (visible15 = true)}
  107. />
  108. <TimePicker bind:visible={visible15} outFormat="Y year, M month, D day, h hour, m minutes, s seconds" on:confirm={customFormatFunc} />
  109. <div class="px-4">
  110. {#if monthFirstStr !== ''}
  111. Currently selected:
  112. <span class="mr-2 text-primary dark:text-dark">{monthFirstStr}</span>
  113. {:else}
  114. <div>Please select the time</div>
  115. {/if}
  116. </div>
  117. <Cell title="Return time month before" on:click={() => (visible16 = true)} />
  118. <TimePicker bind:visible={visible16} type="YMD" outFormat="M/D/Y" on:confirm={monthFirstFunc} />
  119. <div class="px-4 text-xs">
  120. Currently selected:<br />
  121. <span class="mr-2 text-primary dark:text-dark break-words">{timeObjStr}</span>
  122. </div>
  123. <Cell title="Return time object" on:click={() => (visible17 = true)} />
  124. <TimePicker bind:visible={visible17} outFormat="object" on:confirm={getTimeObjFunc} />
  125. <Cell title="I want some rounded corners on the top" on:click={() => (visible14 = true)} />
  126. <TimePicker bind:visible={visible14} popup={{ radius: 'xl' }} />
  127. <Cell title="Custom title" on:click={() => (visible18 = true)} />
  128. <TimePicker bind:visible={visible18} title="Please select the time" />
  129. <Cell title="Specifies the initial selection year" on:click={() => (visible19 = true)} />
  130. <TimePicker bind:visible={visible19} initYear="2020" />
  131. <Cell title="Specifies the initial selected month" on:click={() => (visible20 = true)} />
  132. <TimePicker bind:visible={visible20} initMonth="05" />
  133. <Cell title="Specifies the initial selection time" on:click={() => (visible21 = true)} />
  134. <TimePicker bind:visible={visible21} initHour="05" initMinute="05" initSecond="05" />
  135. </div>