dark_mode.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Dark Mode - Puppertino Framework</title>
  6. <link
  7. href="https://rsms.me/inter/inter.css"
  8. rel="stylesheet"
  9. />
  10. <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/codedgar/Puppertino@latest/dist/css/newfull.css" />
  11. <meta
  12. name="viewport"
  13. content="width=device-width, initial-scale=1, shrink-to-fit=no"
  14. />
  15. <meta http-equiv="x-ua-compatible" content="ie=edge" />
  16. <link rel="stylesheet" type="text/css" href="doc.css" />
  17. <meta
  18. name="description"
  19. content="This is the documentation for Dark Mode on the Puppertino Framework, a framework that mimics Apple's design, woof!"
  20. />
  21. <link rel="icon" type="image/png" href="../landing-images/doggo.png" />
  22. <!-- Global site tag (gtag.js) - Google Analytics -->
  23. <script async src="https://www.googletagmanager.com/gtag/js?id=UA-176821843-1"></script>
  24. <script>
  25. window.dataLayer = window.dataLayer || [];
  26. function gtag(){dataLayer.push(arguments);}
  27. gtag('js', new Date());
  28. gtag('config', 'UA-176821843-1');
  29. </script>
  30. </head>
  31. <body class="p-layout">
  32. <div class="route">
  33. <a
  34. href="https://codedgar.github.io/Puppertino/"
  35. class="p-btn p-btn-scope p-btn-scope-unactive"
  36. >Puppertino</a
  37. >
  38. <p>/</p>
  39. <a href="index.html" class="p-btn p-btn-scope p-btn-scope-unactive"
  40. >Examples</a
  41. >
  42. <p>/</p>
  43. <a href="dark_mode.html" class="p-btn p-btn-scope">Dark Mode</a>
  44. </div>
  45. <h1>Dark Mode</h1>
  46. <div class="master">
  47. <p>
  48. Dark Mode it's not new to Apple's design system, and it has been something we've been wanting to add since the first version of Puppertino. And this is now a strong part of Puppertino, to use Dark Mode, you will need to get the
  49. <a
  50. href="https://github.com/codedgar/Puppertino/blob/master/dist/css/dark_mode.css"
  51. target="_blank"
  52. >CSS of Dark Mode</a
  53. >
  54. or
  55. <a
  56. href="https://github.com/codedgar/Puppertino/blob/master/dist/css/newfull.css"
  57. target="_blank"
  58. >download the full CSS</a
  59. >
  60. </p>
  61. <div class="talk-about-it">
  62. <h2>About Dark Mode.</h2>
  63. <p>
  64. Dark mode it's pretty straight forward to use. And it comes in two flavors, automatic and manual toggling. The automatic toggling uses the <code class="code">media-prefers-scheme</code> to get the user's desired theme and apply automatically. Of course, this doesn't work in some (mosts) of Linux Operating systems, and that's what the manual version is aimed for. It's also really useful if you want your users to select their own theme.
  65. <br>
  66. <br>
  67. This is how it looks on practice (All current components support dark mode):
  68. </p>
  69. <div class="content_smol ">
  70. <div class="mw-450 p-dark-mode dark_theme">
  71. <div class="p-mobile-tabs-content">
  72. <div class="p-mobile-tabs--content active" id="demo4">
  73. <h1 style="color: #fff;">Dark theme</h1>
  74. <a href="#" class="p-btn p-prim-col">Primary</a>
  75. <a href="#" class="p-btn">Second</a>
  76. <input
  77. type="email"
  78. class="p-form-text"
  79. placeholder="Normal validated input (email)"
  80. />
  81. </div>
  82. <div class="p-mobile-tabs">
  83. <div>
  84. <a href="#" class="active" data-p-mobile-toggle="#demo1">
  85. <svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>
  86. Home
  87. </a>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. <div class="mw-450">
  93. <div class="p-mobile-tabs-content">
  94. <div class="p-mobile-tabs--content active" id="demo1">
  95. <h1>Default theme</h1>
  96. <a href="#" class="p-btn p-prim-col">Primary</a>
  97. <a href="#" class="p-btn">Second</a>
  98. <input
  99. type="email"
  100. class="p-form-text"
  101. placeholder="Normal validated input (email)"
  102. />
  103. </div>
  104. <div class="p-mobile-tabs">
  105. <div>
  106. <a href="#" class="active" data-p-mobile-toggle="#demo1">
  107. <svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>
  108. Home
  109. </a>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <p>You can experience the Dark Mode in all of the Puppertino's website by clicking <a href="#" class="p-btn p-prim-col" id="the_button">This button</a></p>
  116. <p>Usage:</p>
  117. <div class="code">
  118. <pre>
  119. <code class="html">
  120. &#60;body class="p-auto-dark-mode">&#60;/body> &#60;!-- Automatic -->
  121. &#60;body class="p-dark-theme">&#60;/body> &#60;!-- Manual -->
  122. </code>
  123. </pre>
  124. </div>
  125. </div>
  126. <div class="talk-about-it" id="modifier">
  127. <h2>How to use manual.</h2>
  128. <p>
  129. <h3>Getting Started</h3>
  130. <p><strong>1. Initializing PuppertinoThemeMan</strong></p>
  131. <p>To get started, initialize <code class="code">PuppertinoThemeMan</code> by calling the <code class="code">init()</code> function. This setup allows you to customize theme behavior, including auto-detection based on system preferences.</p>
  132. <div class="code">
  133. <pre>
  134. <code class="js">
  135. puppertinoThemeMan.init({
  136. autoDetect: true, // Automatically detect system theme
  137. darkThemeClass: 'p-dark-mode' // Your custom dark theme class (optional)
  138. });
  139. </code>
  140. </pre>
  141. </div>
  142. <h3>Options:</h3>
  143. <ul>
  144. <li>
  145. <strong>autoDetect:</strong> Enable automatic detection of the system's preferred color scheme. If set to true, <code class="code">PuppertinoThemeMan</code> will adjust based on the system's light or dark mode.
  146. </li>
  147. <li>
  148. <strong>darkThemeClass:</strong> Define the class name for the dark mode (defaults to <strong>p-dark-mode</strong>). Customize this if you’re using a different class for your dark theme styles.
  149. </li>
  150. </ul>
  151. <h3>
  152. 2. Toggling Themes
  153. </h3>
  154. <p>Easily switch between light and dark themes using the <code class="code">toggle()</code> function. This function will apply the correct theme class and store the user’s selection for future visits.</p>
  155. <div class="code">
  156. <pre>
  157. <code>
  158. puppertinoThemeMan.toggle();
  159. </code>
  160. </pre>
  161. </div>
  162. <p>When this function is called, PuppertinoThemeMan will:</p>
  163. <ul>
  164. <li>Add or remove the dark theme class from the document’s body.</li>
  165. <li>Save the user’s selection in <code class="code">localStorage</code> to remember the preference across sessions.</li>
  166. </ul>
  167. <h3>3. System Theme Auto-Detection</h3>
  168. <p>If enabled in the <code class="code">init()</code> options, PuppertinoThemeMan can automatically switch to light or dark mode based on the user’s system preferences. This ensures a seamless experience aligned with the user’s device settings.</p>
  169. <ul>
  170. <li>The detection is powered by the prefers-color-scheme media query.</li>
  171. <li>PuppertinoThemeMan will listen for changes to this setting and adjust the theme accordingly.</li>
  172. </ul>
  173. <h3>4. Consistency Across Tabs</h3>
  174. <p>PuppertinoThemeMan synchronizes theme changes across multiple tabs. If a user changes their theme in one tab, the new theme will automatically apply to all open tabs in the same browser.
  175. <br><br>
  176. No extra configuration is needed—this behavior is built into PuppertinoThemeMan, ensuring a unified user experience.
  177. </p>
  178. <h3>5. Checking the Current Theme</h3>
  179. <p>You can check whether the dark theme is active by using the isDarkThemeActive() function. This function returns true if the dark theme is currently applied.</p>
  180. <div class="code">
  181. <pre>
  182. <code>
  183. const isDarkMode = puppertinoThemeMan.isDarkThemeActive();
  184. </code>
  185. </pre>
  186. </div>
  187. <p>This allows you to tailor additional features based on the active theme.</p>
  188. </div>
  189. <div class="talk-about-it" id="modifier">
  190. <h2>Under the hood.</h2>
  191. <p>
  192. How does this all work? Simple, Puppertino is based on CSS variables, and when you toggle this class you are basically overriding all the colors in CSS variables for the dark themed ones, making it really easy to change all the colors, and also create your own themes if you need to do so. Keep in mind that some variables have been reused to cut down sizes.
  193. </p>
  194. </div>
  195. </div>
  196. </body>
  197. <script
  198. type="text/javascript"
  199. src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"
  200. ></script>
  201. <script defer>
  202. hljs.initHighlightingOnLoad();
  203. </script>
  204. <script src="https://cdn.jsdelivr.net/gh/codedgar/Puppertino@latest/src/js/dakmode_manager.js"></script>
  205. <script defer>
  206. document.querySelector('#the_button').addEventListener('click',function(e){
  207. e.preventDefault();
  208. puppertinoThemeMan.toggle();
  209. });
  210. </script>
  211. </html>