Expression input
Text that takes {{ references }} to earlier steps: picked as they are typed, shown as chips.
import { ExpressionInput, variablesFromSample } from "@forgeron/ui";import { TrophyIcon } from "@forgeron/icons";
import { ExpressionInput, variablesFromSample } from "@forgeron/ui";
const deal = { id: 4182, name: "Transalp", amount: 9600, owner: { name: "Léa Martin" } };
export default function Default() {
return (
<div style={{ width: 320 }}>
<ExpressionInput
aria-label="Subject"
defaultValue="Won: {{ deal.name }}"
variables={[variablesFromSample("deal", "Deal moved to Won", deal, TrophyIcon)]}
/>
</div>
);
}Gives Léa Martin won Transalp for €9600.
Shipping by Geodis,
Posted in #sales.
import { Database01Icon, TrophyIcon } from "@forgeron/icons";
import { ExpressionInput, Field, variablesFromSample } from "@forgeron/ui";
import { useState } from "react";
const deal = {
id: 4182,
name: "Transalp",
amount: 9600,
owner: { name: "Léa Martin", email: "lea@atelier.example" },
};
const rates = { carrier: "Geodis", price: 412.5, days: 2 };
// Type {{ to open the outputs of the previous steps, or use the button. With a sample, the line
// under the field says what the text gives.
export default function InAFieldWithPreview() {
const [text, setText] = useState(
"{{ deal.owner.name }} won {{ deal.name }} for €{{ deal.amount }}.\nShipping by {{ rates.carrier }}, ",
);
return (
<div style={{ width: "100%", maxWidth: 480 }}>
<Field label="Message" hint="Posted in #sales.">
{(control) => (
<ExpressionInput
{...control}
multiline
rows={4}
value={text}
onChange={setText}
variables={[
variablesFromSample("rates", "Carrier rates", rates, Database01Icon),
variablesFromSample("deal", "Deal moved to Won", deal, TrophyIcon),
]}
sample={{ deal, rates }}
/>
)}
</Field>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
value / defaultValue / onChange | string | — | The text, references included. |
variables | { id, label, icon?, fields: { path, hint? }[] }[] | — | The outputs of the previous steps, nearest first. variablesFromSample(id, label, sample) builds one from a test output. |
multiline / rows | boolean / number | — | A textarea. |
sample | unknown | — | Data of a test run: the line under the field says what the text becomes. |
id, aria-* | string | — | From Field, to tie it to its label. |
placeholder / disabled | … | — | As on an input. |
className | string | — | Extra classes. |