Pre-1.0. Not intended for public use yet. The API is subject to undocumented change, and these pages may already be wrong about it.

Skip to content

React Components ​

Every component the React kit exports, with its props and render props, and the options FeedProvider takes. Import them from the kit's directory, @/components/storyfeed by default.

tsx
<FeedProvider FEED_LINK={Link}>
    <FeedStream page={feed} rail="actor" onLoadMore={loadOlder} />
</FeedProvider>

The Feed ​

FeedStream ​

A page of the feed, with day headings, each node, and a "Load older activity" button while there is a next cursor.

PropDefaultAccepts
pageany page shape as JSON
itemsthe nodes to draw, in place of page
nextCursorthe next page's cursor when you pass items; null at the end of the feed
onLoadMore() => void, called when the reader asks for older activity
loadingMorefalsetrue disables the button and shows "Loading…"
groupedtruefalse hides the day headings
raila rail name or { primary, secondary }; unset draws actor-only
childRailthe rail for expanded group members; unset inherits the group's
interactivefalse draws groups without a disclosure control
collapsedthe initial group state; see Group State
dividers{}labels keyed by item id, drawn on the rail before those items
dividerStyle'branch'how a divider meets the rail: branch or dot
empty'No activity yet.'a React node for an empty page
className''classes for the root element
stylestyles for the root element, including CSS variables such as --sf-font-size
Render PropReceivesReturns
body{ node }content added under each row's meta line, before its bodies
annotations{ node }content added at the end of each row
time{ node, label }each row's timestamp; null omits it

The render props reach activities, groups and expanded group members.

tsx
<FeedStream
    items={items}
    nextCursor={nextCursor}
    loadingMore={loading}
    onLoadMore={loadOlder}
    time={({ node, label }) => (
        <Link href={`/activity/${node.id}`}>{label}</Link>
    )}
/>

FeedNodeView ​

One node. It draws FeedItem or FeedGroup, whichever the node is.

PropDefaultAccepts
iteman activity or group node
isLasttrue ends the rail at this row
raila rail
childRailthe rail for a group's expanded members
interactivefalse draws a group without a disclosure control
collapseda group's initial state
Render PropReceivesReturns
body{ node }content added before the bodies
annotations{ node }content added at the end of the row
time{ node, label }the timestamp; null omits it

Rows ​

FeedItem ​

An activity row.

PropDefaultAccepts
iteman activity node
densefalsetrue draws the compact row used for group members
isLastfalsetrue ends the rail at this row
raila rail
Render PropReceivesReturns
body{ node }content added before the bodies
annotations{ node }content added at the end of the row
time{ node, label }the timestamp; null omits it

FeedGroup ​

A group row, with its strip of member pictures and its members behind a native <details>.

PropDefaultAccepts
itema group node
isLastfalsetrue ends the rail at this row
raila rail
childRailthe rail for expanded members
interactivetruefalse draws no disclosure control
collapsednullthe initial state
Render PropReceivesReturns
body{ node }content for the group and each member
annotations{ node }content at the end of the group and each member
time{ node, label }the group's and each member's timestamp

FeedHeadline ​

A headline, each entity in it linked.

PropDefaultAccepts
templatethe node's headline_template, or null
headlinethe node's headline, drawn when there is no template
entitiesthe node's singular role slots
sample{}a group's sample
distinct{}a group's distinct counts
count0a group's member count
verbthe node's verb, drawn when there is neither
aggregatetrue for a group

FeedMeta ​

The line under a headline: the time, a time range and the roles the headline does not name.

PropDefaultAccepts
nodean activity or group node
templatesthe headline templates the row draws, to tell which roles they name
childrenthe timestamp

The Rail ​

FeedIcon ​

The activity's icon, in a disc or as a badge. Edit FeedIcon.tsx to draw your glyph tokens.

PropDefaultAccepts
iconthe node's glyph token
intentthe node's glyph_intent, written to data-sf-intent
variant'disc'disc or badge

EntityAvatar ​

An entity's face: its media.icon, else its initials on its colour.

PropDefaultAccepts
entityan entity, or null for a blank disc
size'md'md, sm, badge, tile or pair
className''classes for the avatar

An entity's label, linked through FEED_LINK when it has a link.

PropDefaultAccepts
entityan entity, or null
fallbackthe text drawn when the entity is null

Pictures ​

FeedMedia ​

One picture, its box reserved from its declared width and height. With FEED_MEDIA provided, that component draws it instead.

PropDefaultAccepts
image{ src, alt, width, height }
hrefa link around the picture
linkAttributesattributes for that link; href and event handlers are dropped
className''classes for the picture

FeedMediaStrip ​

A group's strip: one square tile per member, then a "+N" tile.

PropDefaultAccepts
tilestiles from strip() in shared/strip.ts, or your own { image, href } objects
overflow0the "+N" count
toggle{ expanded, controls, label, onToggle }: the "+N" tile becomes a button that calls onToggle

Bodies ​

The kit draws a body with the renderer registered for its type in FEED_BODIES, else its own. A type with neither draws its $fallback line, or nothing. The built-in renderers live in body/index.tsx, one function per type: CallToAction, ComponentBody, Excerpt, FileAttachment (also Storyfeed/Body/File), Image, ItemList, KeyValue, MediaObject, Prose and Table.

Every renderer receives BodyProps:

tsx
import type { BodyProps } from '@/components/storyfeed';

export default function Shipment({ payload }: BodyProps) {
    return <p>{payload.carrier} · {payload.tracking}</p>;
}

MediaObject ​

PropDefaultAccepts
payloadthe body as it appears in the payload
entityLabelthe label of the entity that carries the body
entityUrlthat entity's link URL
entityLinkthat entity's link: { href, modal, attributes }
entityMediathat entity's media
imagePlacementbeside or below the text; unset reads FEED_MEDIA_OBJECT_PLACEMENT, then beside

BodyProps is these six props. A renderer reads the ones it needs.

FeedProvider ​

FeedProvider supplies the kit's options to everything inside it. A nested provider inherits the outer one's options; its own win, and FEED_BODIES maps merge.

tsx
<FeedProvider FEED_LINK={Link} FEED_BODIES={{ 'Acme/Shipment': Shipment }}>
    <FeedStream page={feed} />
</FeedProvider>
SeamValueDefault
FEED_LINKa component that takes href and children, such as Inertia's Link; receives the entity's attributes and, for a modal link, modal'a'
FEED_BODIES{ [type]: ComponentType<BodyProps> }, body type to renderer; one registered for a built-in type replaces the kit's{}
FEED_COMPONENTS{ [name]: ComponentType }, Component body name to component; receives the body's props{}
FEED_MEDIAa component that receives image, href, linkAttributes and className, and draws every picturenone
FEED_FILE_LABELLER({ name, mediaType }) => string | null; null uses the built-in MIME labelsnone
FEED_MEDIA_OBJECT_PLACEMENT'beside' or 'below''beside'
FEED_NOWa timestamp in milliseconds that pins the clockthe browser's clock

Server Rendering ​

The server render and the first client render draw ISO timestamps and group days in UTC, so they match. After mounting, labels use the browser's locale and time zone and refresh with age. FEED_NOW pins the clock.

Other Exports ​

ExportIs
readPage(page)a page's { items, nextCursor }, whichever shape it has
rail(name)a rail name as { primary, secondary }
RAIL_NAMESthe four rail names
useFeedOptions()the nearest FeedProvider's options
useRelativeTime(iso), useFeedDays(items)the hooks behind the timestamps and day headings
FeedStreamProps, NodeProps, FeedRenderProps, BodyProps, FeedPageLikeprop and page types
FeedNode, ActivityNode, GroupNode, FeedEntity, FeedPayload, FeedPagePayloadpayload types

Words ​

shared/messages.ts holds the role words after the time, "Yesterday", and "from" and "until" for time ranges. The other words, such as "Show all" and "Load older activity", are in the components.

Released under the MIT License.