Skip to Content
BBRICKSv0.7.4
PR PortalForms and dialogs

ChangePreview

The program editor's "What changes" (the mock's progPrev): the old value struck through, an arrow (mirrored in RTL), the new value in bold; then an example ("On an EGP 1,000 order, the creator earns EGP 100.") and the rule for orders already placed. Unchanged shows "No changes yet."; an invalid value shows its error instead. Announced politely.

import { ChangePreview } from '@ergasti/bricks';

Examples

What changes

Old value, new value, a worked example and a note about when it applies; changed turns the arrow on.

Code
import { ChangePreview } from '@ergasti/bricks';

function Preview() {
  return (
    <div style={{ maxWidth: 480 }}>
      <ChangePreview from="8% of sale" to="10% of sale" changed example={<>On an EGP 1,000 order, the creator earns <b>EGP 100</b>.</>} note="Applies to orders placed after you save. Orders already placed keep the old rate." />
    </div>
  );
}

Stepper

Numbered steps for a builder; finished steps are buttons when you pass onStep.

Code
import { useState } from 'react';
import { Stepper } from '@ergasti/bricks';

function Steps() {
  const [step, setStep] = useState(1);
  return <Stepper steps={['Basics', 'Type & goal', 'Who can join', 'Reward']} current={step} onStep={setStep} />;
}

Nothing changed yet, and an invalid value

changed={false} greys the arrow while the new value equals the old; error replaces the worked example with why the new value cannot be saved.

Code
import { ChangePreview } from '@ergasti/bricks';

function States() {
  return (
    <div style={{ display: 'grid', gap: 16, maxWidth: 480 }}>
      <ChangePreview from="8% of sale" to="8% of sale" changed={false} />
      <ChangePreview from="8% of sale" to="120% of sale" changed error="A commission cannot be more than 100% of the sale." />
    </div>
  );
}

Props

Prop

Type

Labels

Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key prEditing, or with the component's own prop where it has one. A {name} is a value the component fills in.

prEditing
KeyEnglishArabic
noneNo changes yet.مفيش تغييرات لسه.
wasWasكان
nowNowدلوقتي
stepsStepsالخطوات
stepStep {i} of {n}خطوة {i} من {n}
donedoneخلصت

Design guidance

How the BRICKS design system uses ChangePreview. Written in docs/content/components/ChangePreview.md; the props above are read from the code, which wins where the two disagree.

The program editor's "What changes" block: the old value struck through, an arrow, the new value in bold, a worked example and when it applies; use it under any PR form that changes money terms.

ChangePreview is the mock's progPrev. It shows PR the effect of an edit before saving: "8% of sale → 10% of sale", then "On an EGP 1,000 order, the creator earns EGP 100." and the rule for orders already placed. Unchanged shows "No changes yet."; an invalid value shows its error instead. The block is a polite live region, so the preview is read as PR types.

Anatomy

  1. Region: <div aria-live="polite" class="kit-pr-change">.
  2. From → to (changed): 15px line: <del> old value in --ink-3 (hidden "Was:"), an 18px arrow that mirrors in RTL, bold new value (hidden "Now:").
  3. Example (optional): the worked example.
  4. Note (optional): muted rule line.
  5. Unchanged: muted "No changes yet."
  6. Error: role="alert" field error in place of all of the above.

Variants

PropsShows
changedOld → new, example, note
changed={false}"No changes yet."
errorThe error only

States

As above; updates are announced politely.

Usage

import { ChangePreview } from '@ergasti/bricks';

export function Preview() {
  return (
    <div style={{ maxWidth: 480 }}>
      <ChangePreview from="8% of sale" to="10% of sale" changed example={<>On an EGP 1,000 order, the creator earns <b>EGP 100</b>.</>} note="Applies to orders placed after you save. Orders already placed keep the old rate." />
    </div>
  );
}
// Nothing changed yet, and an invalid value
<ChangePreview from="8% of sale" to="8% of sale" changed={false} />
<ChangePreview from="8% of sale" to="120% of sale" changed error="A commission cannot be more than 100% of the sale." />
// Campaign page › Change the commission: choice, field, preview, save
<ChoiceGroup label="How creators earn" value={type} onChange={setType} options={earnOptions} />
<FormField label="Commission"><input inputMode="decimal" value={rate} onChange={(e) => setRate(e.target.value)} /></FormField>
<ChangePreview from={current} to={`${rate}% of sale`} changed={rate !== saved} error={rateError}
  example={<>On an EGP 1,000 order, the creator earns <b>EGP {Number(rate) * 10}</b>.</>}
  note="Applies to orders placed after you save. Orders already placed keep the old rate." />
<Button variant="ink" disabled={!changedOk} onClick={save}>Save</Button>

Where it appears

  • PR Portal › Affiliate programs › Campaigns › a campaign's page › Change the commission › "What changes".
  • Dashboard screen: PrPrograms.

Guidelines

Do

  • Always include the rule for orders already placed.
  • Compute the example from the exact value (2-dp money strings).

Don't

  • Don't show the preview with changed while the new value equals the old.
  • Don't stack it with a separate error message; pass error.

RTL and Arabic

The arrow flips (kit-pr-flip). Arabic: "لسه مفيش تغييرات" style words come from the copy; values are the app's.

Tokens

--ink-3, --bad (field error).

Accessibility

A polite live region; old and new values carry hidden "Was:" / "Now:"; the arrow is decorative; errors are alerts.

Found in the source

  • Roles in the markup: alert.
  • ARIA attributes set: aria-live, aria-hidden, aria-current, aria-label.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: PrIcon · useLanguage · Stepper · BulkAction · DecisionsCard · FigureRow

Source

src/pr/Editing.tsx (line 21) on GitHub.

On this page