data-driven.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charSet="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. <link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
  8. <link rel="icon" type="image/png" sizes="32x32" href="https://headlessui.dev/favicon-32x32.png" />
  9. <link rel="icon" type="image/png" sizes="16x16" href="https://headlessui.dev/favicon-16x16.png" />
  10. <script src="/packages/intersect/dist/cdn.js" defer></script>
  11. <script src="/packages/morph/dist/cdn.js" defer></script>
  12. <script src="/packages/persist/dist/cdn.js"></script>
  13. <script src="/packages/focus/dist/cdn.js"></script>
  14. <script src="/packages/mask/dist/cdn.js"></script>
  15. <script src="/packages/ui/dist/cdn.js" defer></script>
  16. <script src="/packages/alpinejs/dist/cdn.js" defer></script>
  17. <script src="//cdn.tailwindcss.com"></script>
  18. <title>Listbox</title>
  19. </head>
  20. <body>
  21. <div class="flex flex-col h-screen overflow-hidden font-sans antialiased text-gray-900 bg-gray-700">
  22. <div
  23. x-data="{ selected: undefined, people: [
  24. { id: 1, name: 'Wade Cooper' },
  25. { id: 2, name: 'Arlene Mccoy' },
  26. { id: 3, name: 'Devon Webb' },
  27. { id: 4, name: 'Tom Cook' },
  28. { id: 5, name: 'Tanya Fox', disabled: true },
  29. { id: 6, name: 'Hellen Schmidt' },
  30. { id: 7, name: 'Caroline Schultz' },
  31. { id: 8, name: 'Mason Heaney' },
  32. { id: 9, name: 'Claudie Smitham' },
  33. { id: 10, name: 'Emil Schaefer' },
  34. ]}"
  35. class="flex justify-center w-screen h-full p-12 bg-gray-50"
  36. >
  37. <div class="w-full max-w-xs mx-auto">
  38. <div class="flex justify-between mb-8">
  39. <button class="underline" @click="selected = people[1]">Change value</button>
  40. <button class="underline" @click="
  41. people.sort((a, b) => a.name > b.name ? 1 : -1)
  42. ">Reorder</button>
  43. <button class="underline" @click="
  44. people = people.filter(i => i.name !== 'Arlene Mccoy')
  45. ">Destroy item</button>
  46. </div>
  47. <div x-listbox name="something" x-model="selected" class="space-y-1">
  48. <label x-listbox:label class="block text-sm font-medium leading-5 text-gray-700 mb-1">
  49. Assigned to
  50. </label>
  51. <div class="relative">
  52. <span class="inline-block w-full rounded-md shadow-sm">
  53. <button x-listbox:button class="relative w-full py-2 pl-3 pr-10 text-left transition duration-150 ease-in-out bg-white border border-gray-300 rounded-md cursor-default focus:outline-none focus:shadow-outline-blue focus:border-blue-300 sm:text-sm sm:leading-5">
  54. <span class="block truncate" x-text="selected ? selected.name : 'Select Person'"></span>
  55. <span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
  56. <svg class="w-5 h-5 text-gray-400" viewBox="0 0 20 20" fill="none" stroke="currentColor">
  57. <path d="M7 7l3-3 3 3m0 6l-3 3-3-3" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
  58. </svg>
  59. </span>
  60. </button>
  61. </span>
  62. <div class="absolute w-full mt-1 bg-white rounded-md shadow-lg">
  63. <ul x-listbox:options class="py-1 overflow-auto text-base leading-6 rounded-md shadow-xs max-h-60 focus:outline-none sm:text-sm sm:leading-5">
  64. <template x-for="person in people" :key="person.id">
  65. <li
  66. x-listbox:option :value="person"
  67. class="relative py-2 pl-3 cursor-default select-none pr-9 focus:outline-none"
  68. :disabled="person.disabled"
  69. :class="[$listboxOption.isActive ? 'text-white bg-indigo-600' : 'text-gray-900', person.disabled && 'bg-gray-50 text-gray-300'].filter(Boolean)"
  70. >
  71. <span class="block truncate" :class="$listboxOption.isSelected ? 'font-semibold' : 'font-normal'" x-text="person.name"></span>
  72. <span
  73. x-show="$listboxOption.isSelected"
  74. class="absolute inset-y-0 right-0 flex items-center pr-4"
  75. :class="$listboxOption.isActive ? 'text-white' : 'text-indigo-600'"
  76. >
  77. <svg class="w-5 h-5" viewbox="0 0 20 20" fill="currentColor">
  78. <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" />
  79. </svg>
  80. </span>
  81. </li>
  82. </template>
  83. </ul>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </body>
  91. </html>