Skip to content

Commit b2006bc

Browse files
committed
feat(toast): add placement vaiants examples
1 parent d970f95 commit b2006bc

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

example/src/app/(home)/components/toast.tsx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,93 @@ const DefaultVariantsContent = () => {
142142

143143
// ------------------------------------------------------------------------------
144144

145+
const PlacementVariantsContent = () => {
146+
const [isTopToastVisible, setIsTopToastVisible] = useState(false);
147+
const [isBottomToastVisible, setIsBottomToastVisible] = useState(false);
148+
149+
const { toast } = useToast();
150+
151+
const showTopToast = () =>
152+
toast.show({
153+
variant: 'success',
154+
placement: 'top',
155+
label: 'You have upgraded your plan',
156+
description: 'You can continue using HeroUI Chat',
157+
icon: (
158+
<StyledOcticons
159+
name="shield-check"
160+
size={18}
161+
className="text-success mt-0.5"
162+
/>
163+
),
164+
actionLabel: 'Close',
165+
onActionPress: ({ hide }) => hide(),
166+
});
167+
168+
const showBottomToast = () =>
169+
toast.show({
170+
variant: 'warning',
171+
placement: 'bottom',
172+
label: 'You have no credits left',
173+
description: 'Upgrade to a paid plan to continue',
174+
icon: (
175+
<StyledOcticons
176+
name="shield"
177+
size={18}
178+
className="text-warning mt-0.5"
179+
/>
180+
),
181+
actionLabel: 'Close',
182+
onActionPress: ({ hide }) => hide(),
183+
});
184+
185+
return (
186+
<View className="flex-1 items-center justify-center px-5 gap-5">
187+
<Button
188+
variant="secondary"
189+
onPress={() => {
190+
setIsTopToastVisible(true);
191+
if (isBottomToastVisible) {
192+
toast.hide('all');
193+
setIsBottomToastVisible(false);
194+
setTimeout(() => {
195+
showTopToast();
196+
}, 300);
197+
}
198+
if (!isBottomToastVisible) {
199+
showTopToast();
200+
}
201+
}}
202+
>
203+
Top toast
204+
</Button>
205+
<Button
206+
variant="secondary"
207+
onPress={() => {
208+
setIsBottomToastVisible(true);
209+
if (isTopToastVisible) {
210+
toast.hide('all');
211+
setIsTopToastVisible(false);
212+
setTimeout(() => {
213+
showBottomToast();
214+
}, 300);
215+
}
216+
if (!isTopToastVisible) {
217+
showBottomToast();
218+
}
219+
}}
220+
>
221+
Bottom toast
222+
</Button>
223+
<Button onPress={() => toast.hide('all')} variant="destructive-soft">
224+
Hide all toasts
225+
</Button>
226+
</View>
227+
);
228+
};
229+
230+
// ------------------------------------------------------------------------------
231+
145232
const DifferentContentSizesContent = () => {
146233
const { toast } = useToast();
147234

@@ -419,6 +506,11 @@ const TOAST_VARIANTS: UsageVariant[] = [
419506
label: 'Default variants',
420507
content: <DefaultVariantsContent />,
421508
},
509+
{
510+
value: 'placement-variants',
511+
label: 'Placement variants',
512+
content: <PlacementVariantsContent />,
513+
},
422514
{
423515
value: 'different-content-sizes',
424516
label: 'Different content sizes',

0 commit comments

Comments
 (0)