# Show More

> A list's footer: how many show, and a button for the next page that waits while it loads.

Page: https://uicontext.com/docs/components/show-more

Group: Navigation.

## When to use

A list's footer: how many show, and a button for the next page that waits while it loads. Use [Pagination](https://uicontext.com/docs/components/pagination.md) instead when people jump to a page, not just the next one.

## Usage

```ts
import { ShowMore } from "./ui/uicontext/components/ShowMore.ts"

export const Footer = <M>(h: Html.H<M>, shown: number, loading: boolean, more: M) =>
	ShowMore(h, { shown, total: 134, noun: "order", step: 20, loading, onMore: more })
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A page at a time

The example the page opens with: Show More in “A page at a time”.

```ts title="src/demo.ts" source="www/src/examples/show-more/demo.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { ShowMore } from "./ui/uicontext/components/ShowMore.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	card: { inlineSize: "min(100%, 30rem)", paddingInline: space.md, borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
	list: { margin: 0, padding: 0, listStyle: "none" },
	row: { display: "flex", justifyContent: "space-between", gap: space.md, paddingBlock: space.sm, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line, fontSize: font.sm },
	id: { fontVariantNumeric: "tabular-nums", color: color.muted },
	amount: { fontVariantNumeric: "tabular-nums", fontWeight: 500 },
})

const TOTAL = 23
const STEP = 8
const customers = ["Harborview Supply", "Halvorsen & Co", "Okafor Studio", "Rivera Bakery", "Lindqvist Design", "Tanaka Freight", "Mendes Clinic", "Novak Print"]
const order = (i: number) => ({ id: `#${String(4120 - i)}`, customer: customers[i % customers.length]!, amount: `$${(48 + ((i * 37) % 260)).toFixed(2)}` })

const Message = UiSchema.TaggedEnum({ RequestedMore: {}, LoadedMore: {} })

// stands in for the server: waits, then the next page is there
const FetchPage = Command.make("FetchPage", {}, () => Effect.sleep("700 millis").pipe(Effect.as(Message.LoadedMore())))

// a store's recent orders, eight at a time; the button waits while a page loads
export const RecentOrders = Html.component({
	name: "RecentOrders",
	model: Schema.Struct({ shown: Schema.Number, loading: Schema.Boolean }),
	message: Message,
}).make({
	init: () => ({ shown: STEP, loading: false }),
	update: {
		RequestedMore: ($) => $.evolve({ loading: () => true }).run(FetchPage.make({})),
		LoadedMore: ($) => $.evolve({ shown: (n) => Math.min(TOTAL, n + STEP), loading: () => false }),
	},
	view: (h, model) =>
		h.div.attrs(sx(styles.card)).children(
			h.ul.attrs({ "aria-label": "Recent orders", ...sx(styles.list) }).children(
				Array.from({ length: model.shown }, (_, i) => order(i)).map((o) =>
					h.li.key(o.id).attrs(sx(styles.row)).children(
						h.span.children(h.span.attrs(sx(styles.id)).children(o.id), ` ${o.customer}`),
						h.span.attrs(sx(styles.amount)).children(o.amount),
					)),
			),
			ShowMore(h, { shown: model.shown, total: TOTAL, noun: "order", step: STEP, loading: model.loading, onMore: Message.RequestedMore() }),
		),
})
```

### Cut short in place

`moreLabel` writes “Ada, Tomás, and 5 more” in English; `align: "center"` stacks the count over the button.

```ts title="src/inline.ts" source="www/src/examples/show-more/inline.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { moreLabel, ShowMore } from "./ui/uicontext/components/ShowMore.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	wrap: { display: "grid", gap: space.sm, inlineSize: "min(100%, 26rem)" },
	who: { margin: 0, fontSize: font.sm, color: color.muted },
	list: { display: "grid", gap: space.xs, margin: 0, paddingInlineStart: space.lg, fontSize: font.sm },
})

const watchers = ["Ada Okafor", "Tomás García", "Priya Raman", "Wei Chen", "Lena Fischer", "Marisol Kowalczyk-Hernández", "Yusuf Demir"]

const Message = UiSchema.TaggedEnum({ Expanded: {} })

// who watches an issue: two names and "5 more" in a sentence, then the whole list centered
export const Watchers = Html.component({
	name: "Watchers",
	model: Schema.Struct({ shown: Schema.Number }),
	message: Message,
}).make({
	init: () => ({ shown: 3 }),
	update: { Expanded: ($) => $.evolve({ shown: () => watchers.length }) },
	view: (h, model) =>
		h.div.attrs(sx(styles.wrap)).children(
			h.p.attrs(sx(styles.who)).children(`Watching: ${moreLabel(watchers.slice(0, 2), watchers.length, "en")}`),
			h.ul.attrs({ "aria-label": "Watchers", ...sx(styles.list) }).children(watchers.slice(0, model.shown).map((name) => h.li.key(name).children(name))),
			ShowMore(h, { shown: model.shown, total: watchers.length, noun: "watcher", align: "center", onMore: Message.Expanded() }),
		),
})
```

## API reference

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `shown` (required) | `number` | How many show now. |
| `total` | `number` | How many there are, when it's known. |
| `noun` (required) | `string` | What they are, singular: "order". The plural adds an s; give `nouns` otherwise. |
| `nouns` | `string` | — |
| `onMore` (required) | `Message` | Loads or shows the next page. |
| `step` | `number` | How many the next page adds; the button says "Show 20 more". |
| `loading` | `boolean` | The next page is on its way. |
| `align` | `"split" \| "center"` | The count above the button, centered, instead of beside it. |
| `locale` | `string` | — |
| `style` | `Style` | — |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/show-more
```

With npm: `npx shadcn@latest add checkfu/uicontext/show-more`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/show-more`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/show-more`.

It writes these files:

- `src/ui/uicontext/components/ShowMore.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/ShowMore.ts](https://github.com/checkfu/uicontext/blob/main/src/ShowMore.ts)

## Related

- [App Shell](https://uicontext.com/docs/components/app-shell.md) (`app-shell`): The frame of an app: a sidebar, the page and an optional side panel, on any screen size.
- [Tab Strip](https://uicontext.com/docs/components/tab-strip.md) (`tab-strip`): Document tabs over the page to open, close and drag to reorder.
- [Sidebar](https://uicontext.com/docs/components/sidebar.md) (`sidebar`): A navigation tree of workspaces, teams and pages.
- [Tree View](https://uicontext.com/docs/components/tree-view.md) (`tree-view`): Nested rows you open and close, such as files and folders. Children can load when opened.
- [Page Header](https://uicontext.com/docs/components/page-header.md) (`page-header`): A page's title, description, breadcrumb and actions.
- [Tabs](https://uicontext.com/docs/components/tabs.md) (`tabs`): Switch between panels, or between views of the same data.
