UNPKG

@point-api/dropdown-react

Version:

HOC to add a Point API autocomplete dropdown

76 lines 2.79 kB
import React from "react"; import CheckCircleIcon from "@material-ui/icons/CheckCircle"; import ErrorIcon from "@material-ui/icons/Error"; import InfoIcon from "@material-ui/icons/Info"; import green from "@material-ui/core/colors/green"; import amber from "@material-ui/core/colors/amber"; import Snackbar from "@material-ui/core/Snackbar"; import SnackbarContent from "@material-ui/core/SnackbarContent"; import WarningIcon from "@material-ui/icons/Warning"; import { withStyles, createStyles } from "@material-ui/core/styles"; import { render, unmountComponentAtNode } from "react-dom"; const variantIcon = { success: CheckCircleIcon, warning: WarningIcon, error: ErrorIcon, info: InfoIcon }; const style = (theme) => createStyles({ success: { backgroundColor: green[600] }, error: { backgroundColor: theme.palette.error.dark }, info: { backgroundColor: theme.palette.primary.dark }, warning: { backgroundColor: amber[700] }, icon: { fontSize: 20 }, iconVariant: { opacity: 0.9, marginRight: theme.spacing() }, message: { display: "flex", alignItems: "center" } }); class Alert extends React.Component { constructor(props) { super(props); this.close = () => { this.setState({ open: false }); }; this.state = { open: true }; } render() { const { classes, className, message, variant, autoHideDuration, onClose, ...other } = this.props; const Icon = variantIcon[variant]; return (React.createElement(Snackbar, { anchorOrigin: { vertical: "bottom", horizontal: "left" }, open: this.state.open, autoHideDuration: autoHideDuration, onClose: this.close, onExited: onClose }, React.createElement(SnackbarContent, Object.assign({ className: classes[variant] + " " + className, "aria-describedby": "client-snackbar", message: React.createElement("span", { id: "client-snackbar", className: classes.message }, React.createElement(Icon, { className: classes.icon + " " + classes.iconVariant }), message) }, other)))); } } const StyledAlert = withStyles(style)(Alert); function showAlert(variant, message, autoHideDuration = 1600, props = {}) { const mount = document.createElement("div"); document.body.appendChild(mount); const onClose = () => { unmountComponentAtNode(mount); mount.remove(); }; render(React.createElement(StyledAlert, Object.assign({ variant: variant, message: message, autoHideDuration: autoHideDuration, onClose: onClose }, props)), mount); } export default showAlert; //# sourceMappingURL=Alert.js.map