Skip to content

Commit 6c81d10

Browse files
committed
feat(toast): add toast placement prop
1 parent 21d3185 commit 6c81d10

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/components/toast/toast.styles.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import { tv } from 'tailwind-variants';
33
import { combineStyles } from '../../helpers/theme/utils/combine-styles';
44

55
const root = tv({
6-
base: 'absolute top-0 left-0 right-0 rounded-3xl p-4 bg-surface shadow-2xl shadow-black/10',
6+
base: 'absolute left-0 right-0 rounded-3xl p-4 bg-surface shadow-2xl shadow-black/10',
7+
variants: {
8+
placement: {
9+
top: 'top-0',
10+
bottom: 'bottom-0',
11+
},
12+
},
13+
defaultVariants: {
14+
placement: 'top',
15+
},
716
});
817

918
const label = tv({

src/components/toast/toast.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ const ToastRoot = forwardRef<ViewRef, ToastRootProps>((props, ref) => {
2727
const {
2828
children,
2929
variant = 'default',
30+
placement = 'top',
3031
className,
3132
style,
3233
...restProps
3334
} = props;
3435

3536
const tvStyles = toastStyles.root({
37+
placement,
3638
className,
3739
});
3840

src/components/toast/toast.types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export type ToastVariant =
1212
| 'warning'
1313
| 'danger';
1414

15+
/**
16+
* Toast placement types
17+
*/
18+
export type ToastPlacement = 'top' | 'bottom';
19+
1520
/**
1621
* Props for the Toast.Root component
1722
*/
@@ -21,6 +26,11 @@ export interface ToastRootProps extends ToastPrimitive.RootProps {
2126
* @default 'default'
2227
*/
2328
variant?: ToastVariant;
29+
/**
30+
* Placement of the toast
31+
* @default 'top'
32+
*/
33+
placement?: ToastPlacement;
2434
/**
2535
* Additional CSS class for the toast container
2636
*/

src/providers/toast/provider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export function Toaster({ insets }: ToastProviderProps) {
3737
}}
3838
>
3939
<View className="flex-1">
40-
<Toast variant="accent" className="flex-row items-center gap-3">
40+
<Toast
41+
variant="accent"
42+
placement="bottom"
43+
className="flex-row items-center gap-3"
44+
>
4145
<View className="flex-1">
4246
<Toast.Label>Accent notification</Toast.Label>
4347
<Toast.Description>

0 commit comments

Comments
 (0)