@equinor/mad-toast
Version:
Toast package built on top of `react-native-toast-message`
62 lines (59 loc) • 1.7 kB
JavaScript
import {
getMaxToastWidth
} from "./chunk-P4BOXWUK.js";
import {
getToastTokenForType
} from "./chunk-DAU4C4AU.js";
import {
getIconNameForToastType
} from "./chunk-FTSMF3PA.js";
// src/components/ToastComponent.tsx
import {
EDSStyleSheet,
Icon,
Paper,
PressableHighlight,
Typography,
useStyles,
useToken
} from "@equinor/mad-components";
import React from "react";
var ToastComponent = ({ text, type, onPress }) => {
const styles = useStyles(theme, type);
const masterToken = useToken();
const { text: textColor } = getToastTokenForType(masterToken, type);
const iconName = getIconNameForToastType(type);
return /* @__PURE__ */ React.createElement(
PressableHighlight,
{
disabled: typeof onPress !== "function",
onPress,
style: styles.pressable
},
/* @__PURE__ */ React.createElement(Paper, { elevation: "raised", style: styles.background }, /* @__PURE__ */ React.createElement(Icon, { name: iconName, color: textColor }), /* @__PURE__ */ React.createElement(Typography, { color: textColor, numberOfLines: 4, style: styles.text }, text))
);
};
var theme = EDSStyleSheet.create((token, type) => {
const { background: backgroundColor } = getToastTokenForType(token, type);
return {
pressable: { borderRadius: 4 },
background: {
flexDirection: "row",
alignItems: "center",
backgroundColor,
borderRadius: 4,
gap: 16,
maxWidth: getMaxToastWidth(),
padding: 16,
userSelect: "none"
},
text: {
maxWidth: "90%",
// prevent selecting text for web, since this disrupts the swipable properties
userSelect: "none"
}
};
});
export {
ToastComponent
};