App.svelte 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <script>
  2. import { setContext } from 'svelte';
  3. import en_US from 'stdf/lang/en_US';
  4. import zh_CN from 'stdf/lang/zh_CN';
  5. import { Button, Cell, Calendar, Icon } from 'stdf';
  6. import Counter from './lib/Counter.svelte';
  7. import viteLogo from './assets/vite.svg';
  8. import svelteLogo from './assets/svelte.svg';
  9. import unoLogo from './assets/uno.svg';
  10. //切换亮暗模式(toggle light or dark mode)
  11. let theme = sessionStorage.getItem('theme') === 'dark' ? 'dark' : 'light';
  12. if (theme === 'dark') {
  13. document.documentElement.classList.add('dark');
  14. }
  15. const toggleModeFun = () => {
  16. if (theme === 'dark') {
  17. // 切换到(light switch to light)
  18. theme = 'light';
  19. document.documentElement.classList.remove('dark');
  20. sessionStorage.setItem('theme', 'light');
  21. } else {
  22. // 切换到(dark switch to dark)
  23. theme = 'dark';
  24. document.documentElement.classList.add('dark');
  25. sessionStorage.setItem('theme', 'dark');
  26. }
  27. };
  28. // 设置语言(setting language)
  29. let lang = sessionStorage.getItem('lang') === 'en_US' ? 'en_US' : 'zh_CN';
  30. $: isZh = lang === 'zh_CN';
  31. setContext('STDF_lang', sessionStorage.getItem('lang') === 'en_US' ? en_US : zh_CN);
  32. const toggleLangFun = () => {
  33. lang = isZh ? 'en_US' : 'zh_CN';
  34. sessionStorage.setItem('lang', isZh ? 'en_US' : 'zh_CN');
  35. // 刷新(refresh)
  36. location.reload();
  37. };
  38. // 进度条(percent)
  39. let percent = 20;
  40. const reduceFunc = () => {
  41. percent > 0 && (percent -= 10);
  42. };
  43. const increaseFunc = () => {
  44. percent < 100 && (percent += 10);
  45. };
  46. // 日历(calendar)
  47. let visible = false;
  48. </script>
  49. <main>
  50. <div class="flex justify-center items-center text-center gap-4 pt-20">
  51. <a class="flex flex-col items-center w-10" href="https://vitejs.dev" target="_blank" rel="noreferrer">
  52. <img src={viteLogo} alt="Vite Logo" />
  53. </a>+
  54. <a class="flex flex-col items-center w-10" href="https://svelte.dev" target="_blank" rel="noreferrer">
  55. <img src={svelteLogo} alt="Svelte Logo" />
  56. </a>+
  57. <a class="flex flex-col items-center w-8" href="https://unocss.dev" target="_blank" rel="noreferrer">
  58. <img src={unoLogo} alt="UnoCSS Logo" />
  59. </a>+
  60. <a class="flex flex-col items-center w-8" href="https://stdf.design" target="_blank" rel="noreferrer">
  61. <svg viewBox="0 0 90 80" fill="currentColor">
  62. <path
  63. class="text-primary dark:text-dark"
  64. d="M0 0H20H40H50C64.8056 0 77.7325 8.04398 84.6487 20H50H40V22.6757V30H50C55.5229 30 60 34.4771 60 40C60 45.5229 55.5229 50 50 50H40V57.3243V78.7398V80H20V66.4583V20H15.3513H0V0ZM50 80C72.0914 80 90 62.0914 90 40C90 36.547 89.5625 33.1962 88.7398 30H67.3244C69.0261 32.9417 70 36.3571 70 40C70 51.0457 61.0457 60 50 60V80Z"
  65. />
  66. <path class="text-dark dark:text-primary" d="M20 30V0L0 50H20V80L40 30H20Z" />
  67. </svg>
  68. </a>
  69. </div>
  70. <div class="text-center my-8 text-xs">
  71. {#if isZh}
  72. <p>这是一个使用 Vite + Svelte + UnoCSS + STDF 构建的模板。</p>
  73. <p class="mt-2">点击上方 LOGO 了解更多。</p>
  74. {:else}
  75. <p>This is a template using Vite + Svelte + UnoCSS + STDF.</p>
  76. <p class="mt-2">Click the logo above to learn more.</p>
  77. {/if}
  78. </div>
  79. <div class="my-8">
  80. <Cell title={isZh ? '暗模式' : 'Dark mode'} right={{ type: 'switch', switch: { check: theme === 'dark' } }} on:click={toggleModeFun} />
  81. </div>
  82. <div class="my-8">
  83. <Counter bind:percent />
  84. </div>
  85. <div class="my-8">
  86. <Button heightIn="0" group fill="lineTheme">
  87. <div class="flex divide-x">
  88. <!-- svelte-ignore a11y-click-events-have-key-events -->
  89. <!-- svelte-ignore a11y-no-static-element-interactions -->
  90. <div class="flex-1 py-2 active:opacity-80" on:click={reduceFunc}>-10</div>
  91. <!-- svelte-ignore a11y-click-events-have-key-events -->
  92. <!-- svelte-ignore a11y-no-static-element-interactions -->
  93. <div class="flex-1 py-2 active:opacity-80" on:click={increaseFunc}>+10</div>
  94. <!-- svelte-ignore a11y-click-events-have-key-events -->
  95. <!-- svelte-ignore a11y-no-static-element-interactions -->
  96. <div class="flex-1 py-2 active:opacity-80" on:click={() => (percent = 20)}>{isZh ? '重置' : 'Reset'}</div>
  97. </div>
  98. </Button>
  99. </div>
  100. <div class="my-8">
  101. <Button fill="lineTheme" on:click={() => (visible = true)}>{isZh ? '日历' : 'Calendar'}</Button>
  102. </div>
  103. <Calendar bind:visible />
  104. <div class="my-8 px-8 flex justify-between">
  105. <Icon name="cake" theme path="fonts/Heroicons.svg" />
  106. <Icon name="riding-line" path="fonts/Remix.svg" />
  107. <Icon name="spy-line" theme path="fonts/Remix.svg" />
  108. <Icon name="javascript-fill" injClass="text-[red] dark:text-green" path="fonts/Remix.svg" />
  109. <Icon name="cup" theme path="fonts/IconPark.svg" />
  110. </div>
  111. <div class="px-4 text-xs">
  112. {isZh ? '图标:第一个来自' : 'Icons: The first one comes from'} <a class="underline" href="https://heroicons.com">Heroicons</a>
  113. ,{isZh ? '最后一个来自' : 'the last one comes from'} <a class="underline" href="https://iconpark.oceanengine.com">IconPark</a>
  114. ,{isZh ? '其余来自' : 'the rest come from'} <a class="underline" href="https://remixicon.com">Remix Icon</a> 。
  115. </div>
  116. <div class="my-8">
  117. <Button on:click={toggleLangFun}>{isZh ? '切换语言' : 'Toggle language'}</Button>
  118. </div>
  119. </main>