DocSpace-buildtools/packages/asc-web-components/snackbar/index.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-07-14 14:12:13 +00:00
import React, { useCallback } from "react";
import PropType from "prop-types";
import StyledSnackBar from "./styled-snackbar";
import StyledCrossIcon from "./styled-snackbar-action";
import StyledLogoIcon from "./styled-snackbar-logo";
import Box from "../box";
import Heading from "../heading";
import Text from "../text";
const SnackBar = ({ text, headerText, onAction, ...rest }) => {
const onActionClick = useCallback(
(e) => {
onAction && onAction(e);
},
[onAction]
);
const headerStyles = headerText ? {} : { display: "none" };
2021-06-10 14:20:09 +00:00
2021-07-14 14:12:13 +00:00
return (
<StyledSnackBar {...rest}>
<Box className="logo">
<StyledLogoIcon size="medium" />
</Box>
<Box className="text-container">
<Heading
size="xsmall"
isInline={true}
className="text-header"
style={headerStyles}
>
{headerText}
</Heading>
<Text>{text}</Text>
</Box>
<button className="action" onClick={onActionClick}>
<StyledCrossIcon size="medium" />
</button>
</StyledSnackBar>
);
2021-06-10 14:20:09 +00:00
};
2021-07-14 14:12:13 +00:00
SnackBar.propTypes = {
text: PropType.string,
headerText: PropType.string,
onAction: PropType.func,
2021-06-10 14:20:09 +00:00
};
2021-07-14 14:12:13 +00:00
export default SnackBar;