App.svelte 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 { stdfTheme, switchTheme, darkMode } from 'stdf/theme';
  7. import NintendoTheme from './data/Nintendo';
  8. import Counter from './lib/Counter.svelte';
  9. import viteLogo from './assets/vite.svg';
  10. import svelteLogo from './assets/svelte.svg';
  11. import tailwindLogo from './assets/tailwindcss.svg';
  12. //切换亮暗模式(toggle light or dark mode)
  13. let mode = sessionStorage.getItem('mode') === 'dark' ? 'dark' : 'light';
  14. if (mode === 'dark') {
  15. darkMode(true);
  16. }
  17. const toggleModeFun = () => {
  18. if (mode === 'dark') {
  19. // 切换到(light switch to light)
  20. mode = 'light';
  21. darkMode(false);
  22. sessionStorage.setItem('mode', 'light');
  23. } else {
  24. // 切换到(dark switch to dark)
  25. mode = 'dark';
  26. darkMode(true);
  27. sessionStorage.setItem('mode', 'dark');
  28. }
  29. };
  30. // 设置语言(setting language)
  31. let lang = sessionStorage.getItem('lang') === 'en_US' ? 'en_US' : 'zh_CN';
  32. $: isZh = lang === 'zh_CN';
  33. setContext('STDF_lang', sessionStorage.getItem('lang') === 'en_US' ? en_US : zh_CN);
  34. const toggleLangFun = () => {
  35. lang = isZh ? 'en_US' : 'zh_CN';
  36. sessionStorage.setItem('lang', isZh ? 'en_US' : 'zh_CN');
  37. // 刷新(refresh)
  38. location.reload();
  39. };
  40. // 进度条(percent)
  41. let percent = 20;
  42. const reduceFunc = () => {
  43. percent > 0 && (percent -= 10);
  44. };
  45. const increaseFunc = () => {
  46. percent < 100 && (percent += 10);
  47. };
  48. // 日历(calendar)
  49. let visible = false;
  50. // 主题(theme)
  51. let theme = 'STDF';
  52. const toggleThemeFun = () => {
  53. if (theme === 'STDF') {
  54. theme = 'Nintendo';
  55. switchTheme(NintendoTheme);
  56. } else {
  57. theme = 'STDF';
  58. switchTheme(stdfTheme);
  59. }
  60. };
  61. </script>
  62. <main>
  63. <div class="flex justify-center items-center text-center gap-4 pt-20">
  64. <a class="flex flex-col items-center w-10" href="https://vitejs.dev" target="_blank" rel="noreferrer">
  65. <img src={viteLogo} alt="Vite Logo" />
  66. </a>+
  67. <a class="flex flex-col items-center w-10" href="https://svelte.dev" target="_blank" rel="noreferrer">
  68. <img src={svelteLogo} alt="Svelte Logo" />
  69. </a>+
  70. <a class="flex flex-col items-center w-10" href="https://tailwindcss.com" target="_blank" rel="noreferrer">
  71. <img src={tailwindLogo} alt="Tailwind Logo" />
  72. </a>+
  73. <a class="flex flex-col items-center w-8" href="https://stdf.design" target="_blank" rel="noreferrer">
  74. <svg viewBox="0 0 90 80" fill="currentColor">
  75. <path
  76. class="text-primary dark:text-dark"
  77. 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"
  78. />
  79. <path class="text-dark dark:text-primary" d="M20 30V0L0 50H20V80L40 30H20Z" />
  80. </svg>
  81. </a>
  82. </div>
  83. <div class="text-center my-6 text-xs">
  84. {#if isZh}
  85. <p>这是一个使用 Vite + Svelte + Tailwind + STDF 构建的模板。</p>
  86. <p class="mt-2">点击上方 LOGO 了解更多。</p>
  87. {:else}
  88. <p>This is a template using Vite + Svelte + TailwindCSS + STDF.</p>
  89. <p class="mt-2">Click the logo above to learn more.</p>
  90. {/if}
  91. </div>
  92. <div class="my-6">
  93. <Cell title={isZh ? '暗模式' : 'Dark mode'} right={{ type: 'switch', switch: { check: mode === 'dark' } }} on:click={toggleModeFun} />
  94. </div>
  95. <div class="my-6">
  96. <Counter bind:percent />
  97. </div>
  98. <div class="my-6">
  99. <Button heightIn="0" group fill="lineTheme">
  100. <div class="flex divide-x">
  101. <!-- svelte-ignore a11y-click-events-have-key-events -->
  102. <!-- svelte-ignore a11y-no-static-element-interactions -->
  103. <div class="flex-1 border-primary dark:border-dark py-2 active:opacity-80" on:click={reduceFunc}>-10</div>
  104. <!-- svelte-ignore a11y-click-events-have-key-events -->
  105. <!-- svelte-ignore a11y-no-static-element-interactions -->
  106. <div class="flex-1 border-primary dark:border-dark py-2 active:opacity-80" on:click={increaseFunc}>+10</div>
  107. <!-- svelte-ignore a11y-click-events-have-key-events -->
  108. <!-- svelte-ignore a11y-no-static-element-interactions -->
  109. <div class="flex-1 border-primary dark:border-dark py-2 active:opacity-80" on:click={() => (percent = 20)}>
  110. {isZh ? '重置' : 'Reset'}
  111. </div>
  112. </div>
  113. </Button>
  114. </div>
  115. <div class="my-6">
  116. <Button fill="lineTheme" on:click={() => (visible = true)}>{isZh ? '日历' : 'Calendar'}</Button>
  117. </div>
  118. <Calendar bind:visible />
  119. <div class="my-6 px-8 flex justify-between">
  120. <Icon name="cake" theme path="fonts/Heroicons.svg" />
  121. <Icon name="riding-line" path="fonts/Remix.svg" />
  122. <Icon name="spy-line" theme path="fonts/Remix.svg" />
  123. <Icon name="javascript-fill" injClass="text-[red] dark:text-green" path="fonts/Remix.svg" />
  124. <Icon name="cup" theme path="fonts/IconPark.svg" />
  125. </div>
  126. <div class="px-4 text-xs">
  127. {isZh ? '图标:第一个来自' : 'Icons: The first one comes from'} <a class="underline" href="https://heroicons.com">Heroicons</a>
  128. ,{isZh ? '最后一个来自' : 'the last one comes from'} <a class="underline" href="https://iconpark.oceanengine.com">IconPark</a>
  129. ,{isZh ? '其余来自' : 'the rest come from'} <a class="underline" href="https://remixicon.com">Remix Icon</a> 。
  130. </div>
  131. <div class="my-6">
  132. <Button on:click={toggleLangFun}>{isZh ? '切换语言' : 'Toggle language'}</Button>
  133. <Button fill="lineTheme" on:click={toggleThemeFun}>{isZh ? '切换主题' : 'Toggle theme'}</Button>
  134. </div>
  135. </main>