gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitae3b80dcae3b80dc|||PR records: HM55b briefTrackerae3b80dc/components/pagination.hl

4.5 KB

  1. // pagination.hl — THE PAGINATION: "Previous 1 .. 44 45 46 .. 89 Next". Buttons for the first and last page, the current page
  2. // and its neighbours, "…" for the pages left out. Previous is missing on the first page, Next on the last. Plain Hybriel, no
  3. // script. The page reads `page` (1-based) and `pages` (how many there are) as its own members — set `pages` on the tag:
  4. // `Pagination { pages = 89 }`. USE ONE PER PAGE: a composed component's members are the page's state (COMPONENTS.md §12).
  5. // Every entry is a button (an `if` or a conditional attribute would re-create the DOM, hybriel#41); the "…" ones
  6. // only differ by class, and a click on them does nothing. Each button carries its target page in `data-page` (0 for "…"): a bound
  7. // attribute on a row follows the reassigned list (hybriel#100).
  8. // DATA OUT (ticket #16): the host hands a function, `Pagination { pages = 89 page = page onPage = goPage }`; a click (pointer or
  9. // keyboard) calls `onPage(target)` with the page it goes to — Previous / Next / a number resolved against the page shown BEFORE the
  10. // buttons change (hybriel#87: a child talks upward through a function its host gives it; the function writes the host's members).
  11. Number page = 1
  12. Number pages = 10
  13. String previousLabel = 'Previous'
  14. String nextLabel = 'Next'
  15. onPage = null
  16. Hybrid items = build(page, pages)
  17. entry(label, target, cls) {
  18. return { label = label target = target cls = cls }
  19. }
  20. // the page numbers to show: first, last, current ± 1; at either end four in a row; 0 = a gap
  21. numbers(p, n) {
  22. want = []
  23. let i = 1
  24. while (i <= n) {
  25. let near = i == 1 || i == n || (i >= p - 1 && i <= p + 1)
  26. if (p <= 3 && i <= 4) { near = true }
  27. if (p >= n - 2 && i >= n - 3) { near = true }
  28. if (near) { want.push(i) }
  29. i = i + 1
  30. }
  31. out = []
  32. let last = 0
  33. let k = 0
  34. while (k < want.length) {
  35. v = want[k]
  36. if (v == last + 2) { out.push(v - 1) }
  37. else if (v > last + 2) { out.push(0) }
  38. out.push(v)
  39. last = v
  40. k = k + 1
  41. }
  42. return out
  43. }
  44. build(p, n) {
  45. out = []
  46. if (p > 1) { out.push(entry(previousLabel, p - 1, 'step')) }
  47. nums = numbers(p, n)
  48. let k = 0
  49. while (k < nums.length) {
  50. v = nums[k]
  51. if (v == 0) { out.push(entry('…', 0, 'gap')) }
  52. else { out.push(entry('' + v, v, v == p ? 'page current' : 'page')) }
  53. k = k + 1
  54. }
  55. if (p < n) { out.push(entry(nextLabel, p + 1, 'step')) }
  56. return out
  57. }
  58. show(p) {
  59. if (p < 1 || p > pages) { return }
  60. page = p
  61. items = build(p, pages)
  62. }
  63. // Look: black, white and the greys #555 #999 #ddd #f2f2f2 (the library's base, named in shared/base.hl; README "Look"). Every colour is a semantic token
  64. // with its base value as fallback, `var(--color-…, #000)`, so a bare copy looks right and an app that declares the tokens (layouts.worldapi.org's
  65. // theme) restyles it. No frames: a border or ring only where it means something. A component's browser module
  66. // cannot import tokens itself.
  67. Style {
  68. pagination {
  69. display = 'block'
  70. ol {
  71. display = 'flex'
  72. flexWrap = 'wrap'
  73. gap = '.3rem'
  74. margin = '0'
  75. padding = '0'
  76. listStyle = 'none'
  77. }
  78. button {
  79. font = 'inherit'
  80. fontWeight = '600'
  81. minWidth = '2.75rem'
  82. minHeight = '2.75rem'
  83. padding = '.35rem .6rem'
  84. color = 'var(--color-text, #000)'
  85. background = 'transparent'
  86. border = '0'
  87. borderRadius = '.4rem'
  88. cursor = 'pointer'
  89. hover {
  90. background = 'var(--color-surface, #f2f2f2)'
  91. }
  92. focusVisible {
  93. outline = '2px solid var(--color-accent, #555)'
  94. outlineOffset = '1px'
  95. }
  96. }
  97. 'li.current' {
  98. button {
  99. color = 'var(--color-accent-text, #fff)'
  100. background = 'var(--color-accent, #000)'
  101. border = '0'
  102. }
  103. }
  104. 'li.gap' {
  105. button {
  106. color = 'var(--color-text-muted, #555)'
  107. background = 'transparent'
  108. border = '0'
  109. minWidth = '0'
  110. minHeight = '0'
  111. padding = '.35rem .2rem'
  112. cursor = 'default'
  113. pointerEvents = 'none'
  114. }
  115. }
  116. }
  117. }
  118. View {
  119. pagination {
  120. nav { title = "Pagination"
  121. ol { id = "pagination-items" for (it of items) { li { class = it.cls button { type = "button" class = "quiet" 'data-page' = it.target it.label on click(e) { emit paginationGo(e) } } } } }
  122. }
  123. }
  124. }
  125. // the target is read from the clicked button FIRST (its `data-page`, written for the page shown now), then the list is rebuilt and
  126. // the host told — so neither a real click (the rebuild can run before a host's own listener) nor a script's `click()` sees another page
  127. on paginationGo(e) {
  128. b = e.target.closest('button')
  129. to = b == null ? null : toNumber(b.getAttribute('data-page'))
  130. if (to == null || to < 1 || to > pages || to == page) { return null }
  131. show(to)
  132. if (onPage != null) { onPage(to) }
  133. }

Branches

Latest commits

  • ae3b80dc|||PR records: HM55b briefTracker
  • 7ef3cb3bMerge branch 'records-st55' into mainTracker
  • fec2e080|||PR records: STATUS HM55Tracker
  • 8e174918Merge branch 'records-hm55b' into mainTracker
  • b1ecee57|||PR records: HM55 stateTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
  • b9c7c3c8Merge branch 'records-dp74' into mainTracker
  • 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
  • b1496147Merge branch 'ap61' into mainTracker
  • 2047955bMerge branch 'u12-gateports' into mainTracker
  • c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker