dialog-theme-list.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { DialogSelect, type DialogSelectRef } from "../ui/dialog-select"
  2. import { useTheme } from "../context/theme"
  3. import { useDialog } from "../ui/dialog"
  4. import { onCleanup, onMount } from "solid-js"
  5. export function DialogThemeList() {
  6. const theme = useTheme()
  7. const options = Object.keys(theme.all())
  8. .sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }))
  9. .map((value) => ({
  10. title: value,
  11. value: value,
  12. }))
  13. const dialog = useDialog()
  14. let confirmed = false
  15. let ref: DialogSelectRef<string>
  16. const initial = theme.selected
  17. onCleanup(() => {
  18. if (!confirmed) theme.set(initial)
  19. })
  20. return (
  21. <DialogSelect
  22. title="Themes"
  23. options={options}
  24. current={initial}
  25. onMove={(opt) => {
  26. theme.set(opt.value)
  27. }}
  28. onSelect={(opt) => {
  29. theme.set(opt.value)
  30. confirmed = true
  31. dialog.clear()
  32. }}
  33. ref={(r) => {
  34. ref = r
  35. }}
  36. onFilter={(query) => {
  37. if (query.length === 0) {
  38. theme.set(initial)
  39. return
  40. }
  41. const first = ref.filtered[0]
  42. if (first) theme.set(first.value)
  43. }}
  44. />
  45. )
  46. }