Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | import React from "react";
import { Avatar } from "~components/avatar";
import { Button } from "~components/button";
import { Card } from "~components/card";
import { Dropdown } from "~components/dropdown";
import { Modal } from "~components/modal";
import { Overlay } from "~components/overlay";
import { Select } from "~components/select";
import { Spinner } from "~components/spinner";
import { Switch } from "~components/switch";
import { Text } from "~components/text";
import { addToast, closeToastById } from "~components/toast";
import { Tooltip } from "~components/tooltip";
import { View } from "~components/view";
import { Group, Section } from "./showcase-section";
const ITEMS = ["Apple", "Banana", "Cherry"];
const DropdownShowcase = () => (
<Section title="Dropdown">
<Dropdown
items={[
{ key: "edit", children: "Edit" },
{ key: "share", children: "Share" },
]}
>
<Button>Open menu</Button>
</Dropdown>
</Section>
);
const SelectShowcase = () => {
const [selectedKeys, setSelectedKeys] = React.useState<string[]>([]);
return (
<Section title="Select">
<Select
label="Fruit"
placeholder="Choose fruit"
items={ITEMS.map((item) => ({ item }))}
selectedKeys={selectedKeys}
onSelectionChange={setSelectedKeys}
selectionMode="multiple"
getKey={({ item }) => item}
getTextValue={({ item }) => item}
renderValue={(items) => (
<Text>{items.map(({ item }) => item).join(", ")}</Text>
)}
>
{({ item }) => (
<View key={item} className="flex flex-row items-center gap-2">
<Avatar hashId={item} size="sm" />
<Text>{item}</Text>
</View>
)}
</Select>
<Text>Selected: {selectedKeys.join(", ") || "none"}</Text>
</Section>
);
};
const ModalShowcase = () => {
const [open, setOpen] = React.useState(false);
return (
<Section title="Modal">
<Button onPress={() => setOpen(true)}>Open modal</Button>
<Modal
label="Example modal"
closeButton
isOpen={open}
onOpenChange={setOpen}
header={<Text variant="h3">Modal heading</Text>}
>
<Text>Modal body</Text>
<Button onPress={() => setOpen(false)}>Close</Button>
</Modal>
</Section>
);
};
const OverlayShowcase = () => {
const [loading, setLoading] = React.useState(false);
return (
<Section title="Overlay">
<Overlay overlay={loading ? <Spinner size="lg" /> : null}>
<Card header={<Text>Overlay target</Text>}>
<Text>Toggle the loading layer</Text>
</Card>
</Overlay>
<Switch isSelected={loading} onValueChange={setLoading} />
</Section>
);
};
const ToastShowcase = () => {
const [ids, setIds] = React.useState<string[]>([]);
const show = () => {
const id = addToast({
title: "Playground toast",
description: "Try closing this toast",
color: "success",
});
if (id) {
setIds((previous) => [...previous, id]);
}
};
const closeLast = () => {
const id = ids.at(-1);
if (id) {
closeToastById(id);
setIds((previous) => previous.filter((item) => item !== id));
}
};
return (
<Section title="Toast">
<View className="flex flex-row gap-2">
<Button onPress={show}>Show toast</Button>
<Button onPress={closeLast} isDisabled={ids.length === 0}>
Close last
</Button>
</View>
</Section>
);
};
const TooltipShowcase = () => {
const [enabled, setEnabled] = React.useState(true);
return (
<Section title="Tooltip">
<Tooltip content="Tooltip content" isDisabled={!enabled}>
<View>
<Text>Hover or press for tooltip</Text>
</View>
</Tooltip>
<Switch isSelected={enabled} onValueChange={setEnabled} />
</Section>
);
};
export const DialogShowcase = () => (
<Group title="Dialog">
<DropdownShowcase />
<SelectShowcase />
<ModalShowcase />
<OverlayShowcase />
<ToastShowcase />
<TooltipShowcase />
</Group>
);
|