App.svelte 5.6 KB

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