Text
ExpandableText
A long text, for example an error, cut at one line (lines). A click, a tap, Enter or Space opens the full text and details. A text that fits stays plain text. With open and onOpenChange the parent controls it, so another control can open it.
import { ExpandableText } from "@percentsa/ui";Examples
Code
export function ExpandableTextExample() {
const t = useT();
return (
<Stack gap={4}>
<ExpandableText
text={t("Build failed: the step could not read the file because the path is longer than the limit of the file system.", "فشل البناء: تعذّرت على الخطوة قراءة الملف لأن المسار أطول من حد نظام الملفات.")}
details={<Code>job 4f2a</Code>}
/>
<ExpandableText text={t("Build finished.", "اكتمل البناء.")} />
</Stack>
);
}
/** Controlled: a button outside the text opens it. */Code
export function ExpandableTextControlledExample() {
const t = useT();
const [open, setOpen] = useState(false);
return (
<Stack gap={4}>
<Button size="sm" variant="secondary" className="justify-self-start" onClick={() => setOpen(true)}>
{t("Show the error", "أظهر الخطأ")}
</Button>
<ExpandableText
open={open}
onOpenChange={setOpen}
text={t("Build failed: the step could not read the file because the path is longer than the limit of the file system.", "فشل البناء: تعذّرت على الخطوة قراءة الملف لأن المسار أطول من حد نظام الملفات.")}
details={<Code>job 4f2a</Code>}
/>
</Stack>
);
}