index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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/history/dist/cdn.js"></script>
  5. <script src="./packages/persist/dist/cdn.js"></script>
  6. <script src="./packages/focus/dist/cdn.js"></script>
  7. <script src="./packages/mask/dist/cdn.js"></script>
  8. <script src="./packages/ui/dist/cdn.js" defer></script>
  9. <script src="./packages/alpinejs/dist/cdn.js" defer></script>
  10. <script src="//cdn.tailwindcss.com"></script>
  11. <div
  12. x-data="{
  13. query: '',
  14. people: [
  15. { id: 1, name: 'Wade Cooper' },
  16. { id: 2, name: 'Arlene Mccoy' },
  17. { id: 3, name: 'Devon Webb' },
  18. { id: 4, name: 'Tom Cook' },
  19. { id: 5, name: 'Tanya Fox' },
  20. { id: 6, name: 'Hellen Schmidt' },
  21. { id: 7, name: 'Caroline Schultz' },
  22. { id: 8, name: 'Mason Heaney' },
  23. { id: 9, name: 'Claudie Smitham' },
  24. { id: 10, name: 'Emil Schaefer' },
  25. ],
  26. activePersons: [],
  27. get queryPerson() {
  28. if (! this.query) return null
  29. return {
  30. id: 11, name: this.query,
  31. }
  32. },
  33. onSubmit(e) {
  34. e.preventDefault()
  35. console.log([...new FormData(e.currentTarget).entries()])
  36. },
  37. removePerson(person) {
  38. this.activePersons = this.activePersons.filter((p) => p !== person)
  39. }
  40. }"
  41. class="flex h-full w-screen justify-center space-x-4 bg-gray-50 p-12"
  42. >
  43. <div class="w-full max-w-4xl">
  44. <div class="space-y-1">
  45. <form @submit="onSubmit">
  46. <div x-combobox x-model="activePersons" name="people" multiple>
  47. <label x-combobox:label class="block text-sm font-medium leading-5 text-gray-700">
  48. Assigned to
  49. </label>
  50. <div class="relative">
  51. <div>Query: <span x-text="query"></span></div>
  52. <span class="inline-block w-full rounded-md shadow-sm">
  53. <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">
  54. <span class="block flex flex-wrap gap-2">
  55. <span x-show="activePersons.length === 0" class="p-0.5">Empty</span>
  56. <template x-for="person in activePersons" :key="person.id">
  57. <span class="flex items-center gap-1 rounded bg-blue-50 px-2 py-0.5">
  58. <span x-text="person.name"></span>
  59. <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)">
  60. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
  61. </svg>
  62. </span>
  63. </template>
  64. <input x-combobox:input @change="query = $event.target.value" class="border-none p-0 focus:ring-0" placeholder="Search..." />
  65. </span>
  66. <button x-combobox:button class="absolute inset-y-0 right-0 flex items-center pr-2">
  67. <svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="none" stroke="currentColor">
  68. <path d="M7 7l3-3 3 3m0 6l-3 3-3-3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
  69. </svg>
  70. </button>
  71. </div>
  72. </span>
  73. <div class="absolute mt-1 w-full rounded-md bg-white shadow-lg">
  74. <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">
  75. <template
  76. x-for="person in people.filter((person) =>
  77. person.name.toLowerCase().includes(query.toLowerCase())
  78. )"
  79. :key="person.id"
  80. >
  81. <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'">
  82. <span x-text="person.name" class="block truncate" :class="{ 'font-semibold': $comboboxOption.isSelected, 'font-normal': !$comboboxOption.isSelected }">
  83. </span>
  84. <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 }">
  85. <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
  86. <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" />
  87. </svg>
  88. </span>
  89. </li>
  90. </template>
  91. <!-- <template x-if="queryPerson">
  92. <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'">
  93. <span x-text="'Create ' + queryPerson.name" class="block truncate" :class="{ 'font-semibold': $comboboxOption.isSelected, 'font-normal': !$comboboxOption.isSelected }">
  94. </span>
  95. <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 }">
  96. <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
  97. <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" />
  98. </svg>
  99. </span>
  100. </li>
  101. </template> -->
  102. </ul>
  103. </div>
  104. </div>
  105. </div>
  106. <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">
  107. Submit
  108. </button>
  109. </form>
  110. </div>
  111. </div>
  112. </div>
  113. <div
  114. x-data="{
  115. query: '',
  116. selected: null,
  117. frameworks: [
  118. {
  119. id: 1,
  120. name: 'Laravel',
  121. disabled: false,
  122. },
  123. {
  124. id: 2,
  125. name: 'Ruby on Rails',
  126. disabled: false,
  127. },
  128. {
  129. id: 3,
  130. name: 'Django',
  131. disabled: false,
  132. },
  133. {
  134. id: 4,
  135. name: 'Express',
  136. disabled: false,
  137. },
  138. {
  139. id: 5,
  140. name: 'Phoenix',
  141. disabled: false,
  142. },
  143. {
  144. id: 6,
  145. name: 'Adonis',
  146. disabled: false,
  147. },
  148. {
  149. id: 7,
  150. name: 'NextJS',
  151. disabled: false,
  152. },
  153. ],
  154. get filteredFrameworks() {
  155. return this.query === ''
  156. ? this.frameworks
  157. : this.frameworks.filter((framework) => {
  158. return framework.name.toLowerCase().includes(this.query.toLowerCase())
  159. })
  160. }
  161. }"
  162. class="flex h-full w-screen justify-center bg-gray-50 p-12"
  163. >
  164. <div x-combobox x-model="selected">
  165. <label x-combobox:label class="block text-sm text-gray-600">
  166. Select framework
  167. </label>
  168. <div class="mt-1 relative">
  169. <div class="flex items-center justify-between gap-2 w-64 bg-white pl-5 pr-3 py-2.5 rounded-md shadow">
  170. <input
  171. x-combobox:input
  172. :display-value="framework => framework.name"
  173. @change="query = $event.target.value"
  174. class="border-none p-0 focus:outline-none focus:ring-0"
  175. placeholder="Search..."
  176. />
  177. <button x-combobox:button class="absolute inset-y-0 right-0 flex items-center pr-2">
  178. <!-- Heroicons up/down -->
  179. <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>
  180. </button>
  181. </div>
  182. <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>
  183. <ul class="divide-y divide-gray-100">
  184. <template
  185. x-for="framework in filteredFrameworks"
  186. :key="framework.id"
  187. hidden
  188. >
  189. <li
  190. x-combobox:option
  191. :value="framework"
  192. :disabled="framework.disabled"
  193. :class="{
  194. 'bg-cyan-500/10 text-gray-900': $comboboxOption.isActive,
  195. 'text-gray-600': ! $comboboxOption.isActive,
  196. 'opacity-50 cursor-not-allowed': $comboboxOption.isDisabled,
  197. }"
  198. class="flex items-center cursor-default justify-between gap-2 w-full px-4 py-2 text-sm"
  199. >
  200. <span x-text="framework.name"></span>
  201. <span x-show="$comboboxOption.isSelected" class="text-cyan-600 font-bold">&check;</span>
  202. </li>
  203. </template>
  204. </ul>
  205. <p x-show="filteredFrameworks.length == 0" class="px-4 py-2 text-sm text-gray-600">No frameworks match your query.</p>
  206. </div>
  207. </div>
  208. <div>local selected: <span x-text="selected?.name"></span></div>
  209. <div>internal selected: <span x-text="$combobox.value?.name"></span></div>
  210. <article x-text="$combobox.activeIndex"></article>
  211. </div>
  212. </div>
  213. </html>