gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit42fefa4e42fefa4emodal: nest Style rules in the language's formmre42fefa4e/components/pagination/pagination.hl

4.6 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. let 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. let 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 { display = 'block' }
  69. 'pagination ol' { display = 'flex' flexWrap = 'wrap' gap = '.3rem' margin = '0' padding = '0' listStyle = 'none' }
  70. 'pagination button' { font = 'inherit' fontWeight = '600' minWidth = '2.75rem' minHeight = '2.75rem' padding = '.35rem .6rem' color = 'var(--color-text, #000)' background = 'transparent' border = '0' borderRadius = '.4rem' cursor = 'pointer' }
  71. 'pagination button:hover' { background = 'var(--color-surface, #f2f2f2)' }
  72. // a keyboard focus ring in the base grey (else Chrome draws its own coloured one — seen at 390 px in mission 005)
  73. 'pagination button:focus-visible' { outline = '2px solid var(--color-accent, #555)' outlineOffset = '1px' }
  74. 'pagination li.current button' { color = 'var(--color-accent-text, #fff)' background = 'var(--color-accent, #000)' border = '0' }
  75. 'pagination li.gap button' { color = 'var(--color-text-muted, #555)' background = 'transparent' border = '0' minWidth = '0' minHeight = '0' padding = '.35rem .2rem' cursor = 'default' pointerEvents = 'none' }
  76. }
  77. View {
  78. pagination {
  79. nav { title = "Pagination"
  80. 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) } } } } }
  81. }
  82. }
  83. }
  84. // the target is read from the clicked button FIRST (its `data-page`, written for the page shown now), then the list is rebuilt and
  85. // 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
  86. on paginationGo(e) {
  87. b = e.target.closest('button')
  88. to = b == null ? null : toNumber(b.getAttribute('data-page'))
  89. if (to == null || to < 1 || to > pages || to == page) { return null }
  90. show(to)
  91. if (onPage != null) { onPage(to) }
  92. }

Branches

Latest commits

  • 42fefa4emodal: nest Style rules in the language's formmre
  • 6fd953e3range-picker: nest Style rules in the language's formmre
  • f661951ddate-picker: nest Style rules in the language's formmre
  • 363577e6media-player: nest Style rules in the language's formmre
  • 0b3fd8c9comments: nest Style rules in the language's formmre
  • 67e043c8plugins/web/README.md from hybriel cb9e480dmre
  • 519b56e9styles.hl: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • 29f63d01md-editor: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • 869f49c7files-upload: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • f60dab20month-view: Style in the language's form (nested like the View, one declaration per line, bare @media)mre
  • 5b3c349aRe-vendor to Hybriel set day35 (cb9e480d): plugins core and web sources, README vendoring notemre
  • 3449b117components: a startup error prints its message before exit 1 (hybriel#247)mre
  • 59704ce1Merge branch 'n5b-pipes'mre
  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • ad4e929bMdEditor: pipe rows without a delimiter row are a table (first row = header, short rows padded, written back without an invented | --- | line) (notes#5)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre