modals.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Modals - 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 Modals 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="p-modal-background">
  33. <div class="p-modal" id="normal-modal" data-p-close-on-outside="true">
  34. <h2>Hello!</h2>
  35. <p>This modal has 3 buttons, please don't add more than 3 :)</p>
  36. <div class="p-modal-button-container">
  37. <a href="#"><strong>Confirm</strong></a>
  38. <a href="#">Settings</a>
  39. <button data-p-cancel>Cancel</button>
  40. </div>
  41. </div>
  42. <div class="p-modal" id="two-button-modal" data-p-close-on-outside="true">
  43. <h2>Alert!</h2>
  44. <p>This modals has 2 buttons!</p>
  45. <div class="p-modal-button-container">
  46. <a href="#" data-p-cancel>OK</a>
  47. <a href="#" data-p-cancel>Cancel</a>
  48. </div>
  49. </div>
  50. <div class="p-modal" id="one-button-modal">
  51. <h2>Alert!</h2>
  52. <p>
  53. Hope you are having an amazing day :)<br />
  54. Also this modal does not close when you click outside, you have to
  55. click the OK button
  56. </p>
  57. <div class="p-modal-button-container">
  58. <a href="#" data-p-cancel>OK</a>
  59. </div>
  60. </div>
  61. <div class="p-modal" id="example-modal">
  62. <h2>Hey!</h2>
  63. <p>
  64. This is an example modal! It does not feature the attribute
  65. data-p-close-on-outside, so it's not gonna close if you click outside
  66. of it
  67. </p>
  68. <div class="p-modal-button-container">
  69. <a href="#" data-p-cancel>OK</a>
  70. </div>
  71. </div>
  72. </div>
  73. <div class="route">
  74. <a
  75. href="https://codedgar.github.io/Puppertino/"
  76. class="p-btn p-btn-scope p-btn-scope-unactive"
  77. >Puppertino</a
  78. >
  79. <p>/</p>
  80. <a href="index.html" class="p-btn p-btn-scope p-btn-scope-unactive"
  81. >Examples</a
  82. >
  83. <p>/</p>
  84. <a href="modals.html" class="p-btn p-btn-scope">Modals</a>
  85. </div>
  86. <h1>Modals</h1>
  87. <div class="master">
  88. <p>
  89. Modals are iconic in iOS design, making them a natural addition to Puppertino. Unlike macOS-style dialog boxes (planned for future versions), these modals are currently categorized under mobile components.
  90. <br><br>To implement modals, you’ll need:
  91. <a
  92. href="https://github.com/codedgar/Puppertino/blob/master/dist/css/modals.css"
  93. target="_blank"
  94. >Modals CSS</a
  95. >
  96. and
  97. <a
  98. href="https://github.com/codedgar/Puppertino/blob/master/src/js/modals.js"
  99. target="_blank"
  100. >Modals JS</a
  101. >
  102. alternatively you can use the
  103. <a
  104. href="https://github.com/codedgar/Puppertino/blob/master/dist/css/newfull.css"
  105. target="_blank"
  106. >Full CSS</a
  107. >
  108. (Not recommended if you are just going to use this component). Please be
  109. aware that you still need to download the JS of Modals, since at the
  110. time, there's no full.js
  111. </p>
  112. <div class="talk-about-it">
  113. <h3>Note on Previous Versions</h3>
  114. <p>In earlier versions of Puppertino, modal actions were exclusively links. In the latest version, you now have the option to use either <strong>Buttons</strong> or <strong>Links</strong>, offering greater flexibility for appropriate actions while maintaining proper semantics and accessibility.</p>
  115. </div>
  116. <div class="talk-about-it">
  117. <h2>Modals: Limitations</h2>
  118. <p>
  119. Puppertino modals are designed for simplicity and optimized user experience. However, there are current limitations to be aware of:
  120. </p>
  121. <ul>
  122. <li>Adding form elements within modals is <strong>not supported</strong> (planned for the next release).</li>
  123. <li>Opening multiple modals simultaneously is not supported to maintain usability.</li>
  124. </ul>
  125. <button data-p-open-modal="#normal-modal" class="p-btn">
  126. Three button modal
  127. </button>
  128. <button data-p-open-modal="#two-button-modal" class="p-btn">
  129. Two button modal
  130. </button>
  131. <button data-p-open-modal="#one-button-modal" class="p-btn">
  132. One button modal
  133. </button>
  134. </div>
  135. </div>
  136. <div class="talk-about-it">
  137. <h2>First steps.</h2>
  138. <p>
  139. To use modals, we need to have a master div where every modal will be
  140. located, as such:
  141. </p>
  142. <div class="code">
  143. <pre>
  144. <code class="html">
  145. &#60;div class="p-modal-background">
  146. &#60;!-- Your modals will be here -->
  147. &#60;/div>
  148. </code>
  149. </pre>
  150. </div>
  151. </div>
  152. <div class="talk-about-it">
  153. <h2>General usage.</h2>
  154. <p>
  155. To use modals, we need 2 principal components:
  156. <strong>A trigger for the modal</strong> and
  157. <strong>the modal itself</strong>. For the button to work, you need to
  158. add the attribute <code class="code">data-p-open-modal</code> followed
  159. by the ID of the actual modal. The actual modal can have from 1 to 3
  160. buttons, and if you add the attribute
  161. <code class="code">data-p-close-on-outside="true"</code> the modal will
  162. close if you click outside of it. Also, modals appear a little bit at
  163. the bottom in lower resolutions, just to make them easier to tap in
  164. mobile devices.<br />
  165. Also, if the <code class="code">data-p-cancel</code> attribute is
  166. present on a button of the modal, the modal will close when the user
  167. clicks the button.
  168. </p>
  169. <button data-p-open-modal="#example-modal" class="p-btn">
  170. Toggle Modal
  171. </button>
  172. <p>Usage:</p>
  173. <div class="code">
  174. <pre>
  175. <code class="html">
  176. &#60;!-- The button that toggles the modal -->
  177. &#60;a href="#" class="p-btn" data-p-open-modal="#example-modal">Default&#60;/a>
  178. &#60;!-- Modal container, all the modals you use should be inside of it. -->
  179. &#60;div class="p-modal-background">
  180. &#60;!-- Your modals will be here -->
  181. &#60;div class="p-modal" id="example-modal">
  182. &#60;h2>Hey!&#60;/h2>
  183. &#60;p>This is an example modal!&#60;/p>
  184. &#60;div class="p-modal-button-container">
  185. &#60;button data-p-cancel>OK&#60;/button>
  186. &#60;/div>
  187. &#60;/div>
  188. &#60;/div>
  189. </code>
  190. </pre>
  191. </div>
  192. </div>
  193. <div class="talk-about-it">
  194. <h2>Several Buttons in a modal.</h2>
  195. <p>
  196. Modals support having several buttons on them without breaking, but due
  197. to composition, you should not add more than 3 buttons, but if you need them, you are free to put them. To add more buttons, the
  198. only thing you need is to add another
  199. <code class="code">&#60;a></code> element inside the Modal button
  200. container (<code class="code"
  201. >&#60;div class="p-modal-button-container"></code
  202. >).
  203. </p>
  204. <button data-p-open-modal="#two-button-modal" class="p-btn">
  205. Toggle Modal
  206. </button>
  207. <p>Usage:</p>
  208. <div class="code">
  209. <pre>
  210. <code class="html">
  211. &#60;div class="p-modal-button-container">
  212. &#60;a href="#" data-p-cancel>OK&#60;/a>
  213. &#60;a href="#">Settings&#60;/a>
  214. &#60;/div>
  215. </code>
  216. </pre>
  217. </div>
  218. </div>
  219. <div class="talk-about-it">
  220. <section id="api-methods">
  221. <h2>JS API Methods</h2>
  222. <p>In newer versions, the old JavaScript has been replaced with the PuppertinoModalMan class—a lightweight utility for managing modals within the Puppertino framework.
  223. <br><br>
  224. While the way you use modals remains unchanged thanks to automatic initialization, this class introduces programmatic methods for Opening or Closing modals, and handling user interactions. <br><br> Here's what currently possible using Puppertino's Modal Manager</p>
  225. <article id="open-modal" class="d-flex align-bottom mt-4">
  226. <div class="flex-1 w-100">
  227. <h3>openModal(selector)</h3>
  228. <p>Opens the modal specified by the CSS selector.</p>
  229. <p><strong>Parameters:</strong></p>
  230. <ul>
  231. <li><code class="code">selector</code> (string): CSS selector for the modal to open.</li>
  232. </ul>
  233. </div>
  234. <div class="flex-1 w-100">
  235. <p><strong>Usage:</strong></p>
  236. <div class="code" >
  237. <pre>
  238. <code>
  239. PuppertinoModalManager.openModal("#exampleModal");
  240. </code>
  241. </pre>
  242. </div>
  243. </div>
  244. </article>
  245. <article id="close-active-modal" class="d-flex align-bottom mt-4">
  246. <div class="flex-1 w-100">
  247. <h3>closeActiveModal()</h3>
  248. <p>Closes the currently active (open) modal.</p>
  249. </div>
  250. <div class="flex-1 w-100">
  251. <p><strong>Usage:</strong></p>
  252. <div class="code">
  253. <pre>
  254. <code>
  255. PuppertinoModalManager.closeActiveModal();
  256. </code>
  257. </pre>
  258. </div>
  259. </div>
  260. </article>
  261. <article id="close-modal" class="d-flex align-bottom mt-4">
  262. <div class="flex-1 w-100">
  263. <h3>closeModal(selector)</h3>
  264. <p>Closes a specific modal specified by the CSS selector.</p>
  265. <p><strong>Parameters:</strong></p>
  266. <ul>
  267. <li><code class="code">selector</code> (string): CSS selector for the modal to close.</li>
  268. </ul>
  269. </div>
  270. <div class="flex-1 w-100">
  271. <p><strong>Usage:</strong></p>
  272. <div class="code">
  273. <pre>
  274. <code>
  275. PuppertinoModalManager.closeModal("#exampleModal");
  276. </code>
  277. </pre>
  278. </div>
  279. </div>
  280. </article>
  281. <article id="is-modal-open" class="d-flex align-bottom mt-4">
  282. <div class="flex-1 w-100">
  283. <h3>isModalOpen(selector)</h3>
  284. <p>Checks if a specific modal is currently open.</p>
  285. <p><strong>Parameters:</strong></p>
  286. <ul>
  287. <li><code class="code">selector</code> (string): CSS selector for the modal to check.</li>
  288. </ul>
  289. <p><strong>Returns:</strong></p>
  290. <ul>
  291. <li><code class="code">true</code> if the modal is open, <code>false</code> otherwise.</li>
  292. </ul>
  293. </div>
  294. <div class="flex-1 w-100">
  295. <p><strong>Usage:</strong></p>
  296. <div class="code">
  297. <pre>
  298. <code>
  299. if (PuppertinoModalManager.isModalOpen("#exampleModal")) {
  300. console.log("The modal is open.");
  301. }
  302. </code>
  303. </pre>
  304. </div>
  305. </div>
  306. </article>
  307. </section>
  308. </div>
  309. <div class="talk-about-it">
  310. <h2>Support for blur on Firefox.</h2>
  311. <p>
  312. Modals use a backdrop-filter, which is currently supported by Firefox
  313. but you need to manually activate it, but in Puppertino there's a
  314. fallback, and for users who don't have active the backdrop-filter in
  315. Firefox, the modal will appear completely white.
  316. </p>
  317. </div>
  318. </body>
  319. <script src="https://cdn.jsdelivr.net/gh/codedgar/Puppertino@latest/src/js/dakmode_manager.js"></script>
  320. <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/codedgar/Puppertino@latest/src/js/modals.js"></script>
  321. <script
  322. type="text/javascript"
  323. src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"
  324. ></script>
  325. <script>
  326. hljs.initHighlightingOnLoad();
  327. </script>
  328. </html>