Grid
Fixed columns from 768 px, or as many columns of a minimum width as fit. masonry: each child moves up into the free space of its column, so cards of very different heights (a long details card, a short refunds card) leave no gaps between rows. The reading and tab order stay the DOM order. The server renders a normal grid; the browser measures the children after mount, so use gap (not margins) for the space.
import { Grid } from "@percentsa/ui";Examples
Code
export function GridExample() {
return (
<Stack gap={6} className="w-full">
<Grid cols={3} gap={3}>
{[1, 2, 3, 4, 5, 6].map((n) => (
<Box key={n}>{n}</Box>
))}
</Grid>
<Grid min="10rem" gap={3}>
{[1, 2, 3, 4, 5].map((n) => (
<Box key={n}>min 10rem</Box>
))}
</Grid>
</Stack>
);
}
/** Six cards of very different heights, as on a record page. */
function ShiftCards() {
const t = useT();
const row = (term: string, termAr: string, amount: number) => ({ term: t(term, termAr), details: <Money amount={amount} /> });
return (
<>
<Card title={t("Shift details", "تفاصيل الوردية")} headingLevel={4}>
<DescriptionList
density="compact"
items={[
{ term: t("Branch", "الفرع"), details: t("Riyadh, Olaya", "الرياض، العليا") },
{ term: t("Cashier", "الكاشير"), details: t("Sara Alharbi", "سارة الحربي") },
{ term: t("Opened", "فُتحت"), details: "08:00" },
{ term: t("Closed", "أُغلقت"), details: "16:05" },
{ term: t("Register", "الصندوق"), details: t("Register 2", "الصندوق 2") },
{ term: t("Orders", "الطلبات"), details: "182" },
{ term: t("Voided", "الملغاة"), details: "3" },
{ term: t("Discounts", "الخصومات"), details: <Money amount={420} /> },
{ term: t("Tips", "الإكراميات"), details: <Money amount={310} /> },
{ term: t("Delivery orders", "طلبات التوصيل"), details: "27" },
]}
/>
</Card>
<Card title={t("Refunds", "المرتجعات")} headingLevel={4}>
<DescriptionList density="compact" items={[row("Count", "العدد", 2), row("Total", "الإجمالي", 180)]} />
</Card>
<Card title={t("Cash", "النقد")} headingLevel={4}>
<DescriptionList density="compact" items={[row("Opening", "الافتتاحي", 500), row("Sales", "المبيعات", 9120), row("Expected", "المتوقع", 9620), row("Counted", "المعدود", 9600)]} />
</Card>
<Card title={t("Closure", "الإقفال")} headingLevel={4}>
<DescriptionList density="compact" items={[row("Difference", "الفرق", 20), row("Deposited", "المودع", 9000)]} />
</Card>
<Card title={t("Notes", "الملاحظات")} headingLevel={4}>
<Text size="sm" tone="muted">
{t(
"The card terminal was offline from 11:20 to 11:45. Six orders were paid in cash instead. The manager approved the 20 difference and asked to check the drawer count again at the next opening. A supplier delivered milk at 13:00 and the invoice was filed with the shift.",
"كان جهاز البطاقات خارج الخدمة من 11:20 إلى 11:45، فدُفعت ستة طلبات نقدًا. اعتمد المدير فرق 20 وطلب إعادة عدّ الدرج عند الافتتاح التالي. وصل المورّد بالحليب عند 13:00 وأُرفقت الفاتورة بالوردية.",
)}
</Text>
</Card>
<Card title={t("Activity", "النشاط")} headingLevel={4}>
<List>
{[
["08:00", "Shift opened", "فُتحت الوردية"],
["11:20", "Card terminal offline", "الجهاز خارج الخدمة"],
["11:45", "Card terminal back", "عاد الجهاز"],
["13:00", "Delivery received", "استلام توريد"],
["16:05", "Shift closed", "أُغلقت الوردية"],
].map(([time, en, ar]) => (
<ListItem key={time} title={t(en!, ar!)} trailing={time} />
))}
</List>
</Card>
</>
);
}masonry: each card moves up into the free space of its column.
Shift details
- Branch
- Riyadh, Olaya
- Cashier
- Sara Alharbi
- Opened
- 08:00
- Closed
- 16:05
- Register
- Register 2
- Orders
- 182
- Voided
- 3
- Discounts
- 420
- Tips
- 310
- Delivery orders
- 27
Refunds
- Count
- 2
- Total
- 180
Cash
- Opening
- 500
- Sales
- 9,120
- Expected
- 9,620
- Counted
- 9,600
Closure
- Difference
- 20
- Deposited
- 9,000
Notes
The card terminal was offline from 11:20 to 11:45. Six orders were paid in cash instead. The manager approved the 20 difference and asked to check the drawer count again at the next opening. A supplier delivered milk at 13:00 and the invoice was filed with the shift.
Activity
- Shift opened08:00
- Card terminal offline11:20
- Card terminal back11:45
- Delivery received13:00
- Shift closed16:05
The same cards without masonry: a short card leaves a gap under it.
Shift details
- Branch
- Riyadh, Olaya
- Cashier
- Sara Alharbi
- Opened
- 08:00
- Closed
- 16:05
- Register
- Register 2
- Orders
- 182
- Voided
- 3
- Discounts
- 420
- Tips
- 310
- Delivery orders
- 27
Refunds
- Count
- 2
- Total
- 180
Cash
- Opening
- 500
- Sales
- 9,120
- Expected
- 9,620
- Counted
- 9,600
Closure
- Difference
- 20
- Deposited
- 9,000
Notes
The card terminal was offline from 11:20 to 11:45. Six orders were paid in cash instead. The manager approved the 20 difference and asked to check the drawer count again at the next opening. A supplier delivered milk at 13:00 and the invoice was filed with the shift.
Activity
- Shift opened08:00
- Card terminal offline11:20
- Card terminal back11:45
- Delivery received13:00
- Shift closed16:05
Code
export function GridMasonryExample() {
const t = useT();
return (
<Stack gap={8} className="w-full">
<Stack gap={3}>
<Text size="sm" tone="muted">{t("masonry: each card moves up into the free space of its column.", "masonry: تصعد كل بطاقة إلى المساحة الفارغة في عمودها.")}</Text>
<Grid masonry min="16rem" gap={4} data-testid="masonry-on">
<ShiftCards />
</Grid>
</Stack>
<Stack gap={3}>
<Text size="sm" tone="muted">{t("The same cards without masonry: a short card leaves a gap under it.", "البطاقات نفسها بدون masonry: تترك البطاقة القصيرة فراغًا تحتها.")}</Text>
<Grid min="16rem" gap={4} data-testid="masonry-off">
<ShiftCards />
</Grid>
</Stack>
</Stack>
);
}