-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathSnackbar.tsx
62 lines (53 loc) · 1.86 KB
/
Snackbar.tsx
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
import React, { forwardRef, ReactNode, type ReactElement } from 'react';
import { PressEvent } from 'react-aria';
import styled from 'styled-components';
import { SpaceProps, LayoutProps, PositionProps, FlexboxProps } from 'styled-system';
import { get } from '../../../utils/experimental/themeGet';
import { getSemanticValue } from '../../../essentials/experimental';
import { textStyles } from '../Text/Text';
import { XCrossIcon } from '../../../icons';
import { IconButton } from '../IconButton/IconButton';
const Container = styled.div`
position: relative;
justify-content: space-between;
border: none;
outline: none;
border-radius: ${get('radii.4')};
padding: ${get('space.3')} ${get('space.4')};
color: ${getSemanticValue('inverse-on-surface')};
background-color: ${getSemanticValue('inverse-surface')};
display: inline-flex;
align-items: center;
gap: ${get('space.1')};
${textStyles.variants.body2}
`;
const DismissButton = styled(IconButton)`
height: unset;
width: unset;
padding: 0;
`;
interface SnackbarProps
extends SpaceProps,
LayoutProps,
PositionProps,
FlexboxProps,
React.HTMLAttributes<HTMLDivElement> {
children: ReactNode;
hasDismissButton?: boolean;
onDismiss?: (e: PressEvent) => void;
}
const Snackbar = forwardRef<HTMLDivElement, SnackbarProps>(
({ children, hasDismissButton = false, onDismiss = null, ...restProps }, ref): ReactElement => (
<Container ref={ref} {...restProps}>
{children}
{hasDismissButton && (
<DismissButton
label="Close snackbar"
Icon={() => <XCrossIcon size={24} color={getSemanticValue('inverse-on-surface')} />}
onPress={onDismiss}
/>
)}
</Container>
)
);
export { Snackbar, SnackbarProps };