diff --git a/packages/rdom-components/src/index.ts b/packages/rdom-components/src/index.ts index b6098da48c..7e032723d6 100644 --- a/packages/rdom-components/src/index.ts +++ b/packages/rdom-components/src/index.ts @@ -4,4 +4,5 @@ export * from "./editor.js"; export * from "./icon-button.js"; export * from "./input.js"; export * from "./radio.js"; +export * from "./ruler.js"; export * from "./tabs.js"; diff --git a/packages/rdom-components/src/ruler.ts b/packages/rdom-components/src/ruler.ts new file mode 100644 index 0000000000..03610a439b --- /dev/null +++ b/packages/rdom-components/src/ruler.ts @@ -0,0 +1,42 @@ +import type { Attribs } from "@thi.ng/hiccup-html"; +import { anchor } from "@thi.ng/hiccup-html/inline"; +import { table, tbody, td, tr } from "@thi.ng/hiccup-html/table"; +import { map } from "@thi.ng/transducers/map"; +import { normRange } from "@thi.ng/transducers/norm-range"; + +/** + * Returns a element with rows of labeled percentage anchors as scroll + * targets. `numSteps` default is 4 (aka 25%). + * + * @remarks + * Resulting table structure is shown below. Note: Unless provided by the user, + * the table will be entirely unstyled, but it's recommended to set the + * `vertical-align` of table cells to `top`. + * + * ```html + *
+ * + * + * + * + * + * + * + * + *
0%25%50%75%
+ * ``` + * + * @param attribs + * @param numSteps + */ +export const verticalRuler = (attribs: Partial = {}, numSteps = 4) => + table( + attribs, + tbody( + {}, + ...map((x) => { + const id = `${(x * 100) | 0}%`; + return tr({}, td({ id }, anchor({ href: `#${id}` }, id))); + }, normRange(numSteps, false)) + ) + );