Skip to Content
BBRICKSv0.7.4
Recipes

Compose a PR portal page

The PR theme, AppShell with the v3 navigation, the open decisions card, the signed-in user, and a header with search, the bell and the "+ New" menu.

A PR portal page is the shell from Build an app frame in the PR theme, with the PR portal's own sidebar card and header tools. PrPortalFrame draws all of it from its props; the steps below say what each part is, and Use the PR portal frame builds the same frame by hand. Everything here is a public export of @ergasti/bricks; your app passes the data, the words and the handlers.

The whole page

PrPortalFrame draws the PR portal v3 frame from its props: the PR theme on its own wrapper (with themes/pr.css loaded once), AppShell with the v3 navigation (your NavGroup tree, here the v3 one that PR_PORTAL_NAV also holds: a "Campaigns" heading with indented items, disabled "Next sprint" items with a LATER badge), DecisionsCard tip="focus" in the sidebar card slot, SidebarUser with sign-out, and an AppHeader with HeaderSearch, the bell and the raspberry "+ New" menu. The page body is a campaigns table with the My / All brands switch. To build the same frame by hand, see the "Use the PR portal frame" recipe.

Pinned to TRNDR presetPR theme
Code
import { useState } from 'react';
import { DataTable, ListToolbar, PrPortalFrame, Segmented, campaignColumns, useLanguage, type NavItem, type SearchResult } from '@ergasti/bricks';
import { campaigns, notifications, openDecisions, prBrands, prNav } from './recipes';

const search = async (term: string): Promise<SearchResult[]> =>
  Object.values(prBrands).filter((b) => b.name.toLowerCase().includes(term.toLowerCase())).map((b) => ({ id: b.id, label: b.name, sub: 'Brand', group: 'brands' }));

function Page() {
  const language = useLanguage();
  const [active, setActive] = useState('programs');
  const [scope, setScope] = useState<'my' | 'all'>('my');
  const [q, setQ] = useState('');
  const rows = campaigns.filter((c) => (scope === 'all' || c.id !== 'kemet') && c.brand.name.toLowerCase().includes(q.toLowerCase()));
  return (
    <PrPortalFrame
      nav={prNav} activeId={active} onNavigate={(item: NavItem) => setActive(item.id)}
      decisions={openDecisions} user={{ name: 'Mona Adel', seed: 7 }} onSignOut={() => {}}
      title="Affiliate programs"
      subtitle="Each brand has one active campaign at a time. Brands request changes; only PR changes it."
      search={{ fetcher: search, groupLabels: { brands: 'Brands' }, onSelect: (r: SearchResult) => setQ(String(r.label)) }}
      notifications={{ items: notifications, onOpenItem: () => {}, onMarkAllRead: () => {}, onSeeAll: () => {} }}
      newMenu={[{ id: 'challenge', label: 'Challenge', sub: 'For one brand or all brands', icon: 'motivation' }, { id: 'gifts', label: 'Record gift stock', sub: 'Gifts a brand sent to the warehouse', icon: 'gift' }]}
      onToggleLanguage={() => {}}
    >
      <ListToolbar
        search={{ value: q, onChange: setQ, placeholder: 'Search brands' }}
        actions={<Segmented label="Brands shown" value={scope} onChange={setScope} options={[['my', 'My brands'], ['all', 'All brands']]} />}
      />
      <DataTable label="Campaigns" rows={rows} rowKey={(r) => r.id} columns={campaignColumns(language)} onRowClick={() => {}} />
    </PrPortalFrame>
  );
}

Steps

  1. Load the PR theme once and scope it. Import @ergasti/bricks/themes/pr.css after tokens.css (see Stylesheets). PrPortalFrame puts data-bricks-theme="pr" on its own wrapper; by hand, put it on an element above the shell. The theme is variables only, so the same components take the PR look inside that element and the brand look outside it.
  2. Describe the navigation as data. A NavGroup with a heading draws a small group title ("Campaigns"); an item with indent: true sits under it without an icon; disabled: true with badge: { label, tone: 'soon' } shows a "LATER" item that cannot be opened. Give the frame (or AppShell) the tree, activeId and onNavigate. PR_PORTAL_NAV is the v3 tree in both languages and the frame's default.
  3. Fill the sidebar. The frame's decisions, user and onSignOut fill it. By hand, sidebarCard takes DecisionsCard with tip="focus" (the open product decisions as { id, question }, each code a tab stop with its own tooltip, and a switch that tells your app to show decision tags), and sidebarFooter takes SidebarUser with a LogoutButton as its action. LogoutButton posts to your sign-out url with the CSRF token, or calls onLogout when you sign out in JavaScript.
  4. Build the header. The frame's title, subtitle, tools, search, notifications and newMenu fill it. By hand, AppHeader takes the title and subtitle, a HeaderSearch in search (your fetcher returns results with a group), and actions: a NotificationsMenu and the "+ New" TopbarMenu with variant="pill" and tone="rasp". onToggleLanguage adds the language button.
  5. Put the page in the frame. The children are the screen. A list screen in the PR portal has a ListToolbar with the My brands / All brands Segmented at its end, and a DataTable with a column preset such as campaignColumns.

The pieces alone

The sidebar pieces alone

DecisionsCard lists the product decisions still open as codes (with tip="focus" each is a tab stop that shows its question in a tooltip); its switch tells the app to show decision tags on the screens. SidebarUser is the last row: an avatar, a name, a detail line and an action.

Pinned to PR theme
Code
import { useState } from 'react';
import { Avatar, Icon, LogoutButton, DecisionsCard, SidebarUser } from '@ergasti/bricks';
import { openDecisions } from './recipes';

function SidebarParts() {
  const [showTags, setShowTags] = useState(true);
  return (
    <div data-bricks-theme="pr" style={{ display: 'grid', gap: 16, maxWidth: 280 }}>
      <DecisionsCard decisions={openDecisions} tip="focus" showTags={showTags} onShowTagsChange={setShowTags} />
      <SidebarUser avatar={<Avatar name="Mona Adel" seed={7} />} name="Mona Adel" detail="PR team" action={<LogoutButton className="kit-btn kit-btn--sm kit-btn--ghost" url="/logout" csrfToken="token-from-your-page"><Icon name="lock" /><span className="kit-sr">Sign out</span></LogoutButton>} />
    </div>
  );
}

The header tools alone

TopbarMenu with variant="pill" and tone="rasp" is the filled "+ New" pill; each item has a sub line and an icon. The bell's unread count comes from the items.

Pinned to PR theme
Code
import { Icon, NotificationsMenu, TopbarMenu } from '@ergasti/bricks';
import { notifications } from './recipes';

function HeaderTools() {
  return (
    <div data-bricks-theme="pr" style={{ display: 'flex', gap: 10, justifyContent: 'flex-end', alignItems: 'center' }}>
      <NotificationsMenu items={notifications} onOpenItem={() => {}} onSeeAll={() => {}} />
      <TopbarMenu label="New" variant="pill" tone="rasp" trigger={<><Icon name="plus" />New</>} items={[{ id: 'challenge', label: 'Challenge', sub: 'For one brand or all brands', icon: 'motivation' }]} />
    </div>
  );
}

Notes

  • The shell changes layout by itself: an icon rail from 860 to 1024px and a bottom tab bar with a "More" sheet under 860px. The phone tab bar takes the first four enabled items that have an icon unless you pass bottomNavIds. See Responsive layouts.
  • Disabled items render as disabled buttons (never as links) and are left out of the default phone tab bar; their LATER badge says why.
  • The words in the shell (skip link, menu, close) come from the provider; copy on AppShell overrides them.

Related: AppShell, NavGroups, SidebarCard, UserMenu, Theming.

On this page