index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <html>
  2. <!-- <script src="./packages/intersect/dist/cdn.js" defer></script>
  3. <script src="./packages/morph/dist/cdn.js" defer></script>
  4. <script src="./packages/persist/dist/cdn.js"></script>
  5. <script src="./packages/focus/dist/cdn.js"></script>
  6. <script src="./packages/mask/dist/cdn.js"></script>
  7. <script src="./packages/ui/dist/cdn.js" defer></script> -->
  8. <script src="./packages/history/dist/cdn.js"></script>
  9. <script src="./packages/alpinejs/dist/cdn.js" defer></script>
  10. <!-- <script src="//cdn.tailwindcss.com"></script> -->
  11. <!-- <script src="//cdn.tailwindcss.com"></script> -->
  12. <div x-data="{
  13. my_array: [{x:'x'},{x:'y'}],
  14. click() {
  15. this.my_array = [{x:'a'},{x:'b'}];
  16. }
  17. }">
  18. <!-- Loop with plain div -->
  19. <template x-for="item in my_array">
  20. <div x-text="item.x"></div>
  21. </template>
  22. <!-- Loop with div nested inside component -->
  23. <template x-for="item in my_array">
  24. <div x-data="some_component" >
  25. <div x-text="item.x"></div>
  26. </div>
  27. </template>
  28. <button @click="click">Click me</button>
  29. </div>
  30. <script>
  31. document.addEventListener('alpine:init', () => {
  32. Alpine.data('some_component', () => ({}));
  33. });
  34. </script>
  35. <button wire:click.prefetch"...">
  36. Do something
  37. </button>
  38. <div x-data="{ count: $url(1) }">
  39. <button @click="count++">+</button>
  40. <button @click="count--">-</button>
  41. <h1 x-text="count"></h1>
  42. </div>
  43. <br>
  44. <br>
  45. <br>
  46. <br>
  47. <br>
  48. <br>
  49. <br>
  50. <br>
  51. <br>
  52. <br>
  53. <br>
  54. <br>
  55. <br>
  56. <br>
  57. <br>
  58. <br>
  59. <br>
  60. <br>
  61. <br>
  62. <br>
  63. <br>
  64. <div x-data="{ users: [{ name: 'lebowski' }] }">
  65. <template x-for="(user, idx) in users">
  66. <span x-text="users[idx].name" x-yo></span>
  67. </template>
  68. <button @click="users = []">Reset</button>
  69. </div>
  70. <div x-data="{ foo: undefined }">
  71. Yo: <input type="text" x-model="foo">
  72. </div>
  73. <!-- Play around here... -->
  74. <div class="relative">
  75. <div>Query: <span x-text="query"></span></div>
  76. <span class="inline-block w-full rounded-md shadow-sm">
  77. <div class="relative w-full cursor-default rounded-md border border-gray-300 bg-white py-2 pl-2 pr-10 text-left transition duration-150 ease-in-out focus-within:border-blue-700 focus-within:outline-none focus-within:ring-1 focus-within:ring-blue-700 sm:text-sm sm:leading-5">
  78. <span class="block flex flex-wrap gap-2">
  79. <span x-show="activePersons.length === 0" class="p-0.5">Empty</span>
  80. <template x-for="person in activePersons" :key="person.id">
  81. <span class="flex items-center gap-1 rounded bg-blue-50 px-2 py-0.5">
  82. <span x-text="person.name"></span>
  83. <svg class="h-4 w-4 cursor-pointer" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" @click.stop.prevent="removePerson(person)">
  84. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
  85. </svg>
  86. </span>
  87. </template>
  88. <input x-combobox:input @change="query = $event.target.value" class="border-none p-0 focus:ring-0" placeholder="Search..." />
  89. </span>
  90. <button x-combobox:button class="absolute inset-y-0 right-0 flex items-center pr-2">
  91. <svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="none" stroke="currentColor">
  92. <path d="M7 7l3-3 3 3m0 6l-3 3-3-3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
  93. </svg>
  94. </button>
  95. </div>
  96. </span>
  97. <div class="absolute mt-1 w-full rounded-md bg-white shadow-lg">
  98. <ul x-combobox:options hold class="shadow-xs max-h-60 overflow-auto rounded-md py-1 text-base leading-6 focus:outline-none sm:text-sm sm:leading-5">
  99. <template
  100. x-for="person in people.filter((person) =>
  101. person.name.toLowerCase().includes(query.toLowerCase())
  102. )"
  103. :key="person.id"
  104. >
  105. <li x-combobox:option :value="person" class="relative cursor-default select-none py-2 pl-3 pr-9 focus:outline-none" :class="$comboboxOption.isActive ? 'bg-indigo-600 text-white' : 'text-gray-900'">
  106. <span x-text="person.name" class="block truncate" :class="{ 'font-semibold': $comboboxOption.isSelected, 'font-normal': !$comboboxOption.isSelected }">
  107. </span>
  108. <span x-show="$comboboxOption.isSelected" class="absolute inset-y-0 right-0 flex items-center pr-4" :class="{ 'text-white': $comboboxOption.isActive, 'text-indigo-600': !$comboboxOption.isActive }">
  109. <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
  110. <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
  111. </svg>
  112. </span>
  113. </li>
  114. </template>
  115. <!-- <template x-if="queryPerson">
  116. <li x-combobox:option :value="queryPerson" class="relative cursor-default select-none py-2 pl-3 pr-9 focus:outline-none" :class="$comboboxOption.isActive ? 'bg-indigo-600 text-white' : 'text-gray-900'">
  117. <span x-text="'Create ' + queryPerson.name" class="block truncate" :class="{ 'font-semibold': $comboboxOption.isSelected, 'font-normal': !$comboboxOption.isSelected }">
  118. </span>
  119. <span x-show="$comboboxOption.isSelected" class="absolute inset-y-0 right-0 flex items-center pr-4" :class="{ 'text-white': $comboboxOption.isActive, 'text-indigo-600': !$comboboxOption.isActive }">
  120. <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
  121. <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
  122. </svg>
  123. </span>
  124. </li>
  125. </template> -->
  126. </ul>
  127. </div>
  128. </div>
  129. </div>
  130. <button class="mt-2 inline-flex items-center rounded border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
  131. Submit
  132. </button>
  133. </form>
  134. </div>
  135. </div>
  136. </div>
  137. <div
  138. x-data="{
  139. query: '',
  140. selected: null,
  141. frameworks: [
  142. {
  143. id: 1,
  144. name: 'Laravel',
  145. disabled: false,
  146. },
  147. {
  148. id: 2,
  149. name: 'Ruby on Rails',
  150. disabled: false,
  151. },
  152. {
  153. id: 3,
  154. name: 'Django',
  155. disabled: false,
  156. },
  157. {
  158. id: 4,
  159. name: 'Express',
  160. disabled: false,
  161. },
  162. {
  163. id: 5,
  164. name: 'Phoenix',
  165. disabled: false,
  166. },
  167. {
  168. id: 6,
  169. name: 'Adonis',
  170. disabled: false,
  171. },
  172. {
  173. id: 7,
  174. name: 'NextJS',
  175. disabled: false,
  176. },
  177. ],
  178. get filteredFrameworks() {
  179. return this.query === ''
  180. ? this.frameworks
  181. : this.frameworks.filter((framework) => {
  182. return framework.name.toLowerCase().includes(this.query.toLowerCase())
  183. })
  184. }
  185. }"
  186. class="flex h-full w-screen justify-center bg-gray-50 p-12"
  187. >
  188. <div x-combobox x-model="selected">
  189. <label x-combobox:label class="block text-sm text-gray-600">
  190. Select framework
  191. </label>
  192. <div class="mt-1 relative">
  193. <div class="flex items-center justify-between gap-2 w-64 bg-white pl-5 pr-3 py-2.5 rounded-md shadow">
  194. <input
  195. x-combobox:input
  196. :display-value="framework => framework.name"
  197. @change="query = $event.target.value"
  198. class="border-none p-0 focus:outline-none focus:ring-0"
  199. placeholder="Search..."
  200. />
  201. <button x-combobox:button class="absolute inset-y-0 right-0 flex items-center pr-2">
  202. <!-- Heroicons up/down -->
  203. <svg class="shrink-0 w-5 h-5 text-gray-500" viewBox="0 0 20 20" fill="none" stroke="currentColor"><path d="M7 7l3-3 3 3m0 6l-3 3-3-3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg>
  204. </button>
  205. </div>
  206. <div x-combobox:options x-cloak class="absolute right-0 w-64 max-h-60 mt-2 z-10 origin-top-right overflow-hidden bg-white border border-gray-200 rounded-md shadow-md outline-none" x-transition>
  207. <ul class="divide-y divide-gray-100">
  208. <template
  209. x-for="framework in filteredFrameworks"
  210. :key="framework.id"
  211. hidden
  212. >
  213. <li
  214. x-combobox:option
  215. :value="framework"
  216. :disabled="framework.disabled"
  217. :class="{
  218. 'bg-cyan-500/10 text-gray-900': $comboboxOption.isActive,
  219. 'text-gray-600': ! $comboboxOption.isActive,
  220. 'opacity-50 cursor-not-allowed': $comboboxOption.isDisabled,
  221. }"
  222. class="flex items-center cursor-default justify-between gap-2 w-full px-4 py-2 text-sm"
  223. >
  224. <span x-text="framework.name"></span>
  225. <span x-show="$comboboxOption.isSelected" class="text-cyan-600 font-bold">&check;</span>
  226. </li>
  227. </template>
  228. </ul>
  229. <p x-show="filteredFrameworks.length == 0" class="px-4 py-2 text-sm text-gray-600">No frameworks match your query.</p>
  230. </div>
  231. </div>
  232. <div>local selected: <span x-text="selected?.name"></span></div>
  233. <div>internal selected: <span x-text="$combobox.value?.name"></span></div>
  234. <article x-text="$combobox.activeIndex"></article>
  235. </div>
  236. </div>
  237. </html>