import React, { useContext, useMemo } from "react"; import { styled } from "styled-components"; import { variant as systemVariant, space } from "styled-system"; import { WarningIcon, ErrorIcon, CheckmarkCircleFillIcon, InfoFilledIcon } from "../Svg"; import { Text, TextProps } from "../Text"; import { Box } from "../Box"; import { MessageProps } from "./types"; import variants from "./theme"; const MessageContext = React.createContext({ variant: "success" }); const Icons = { warning: WarningIcon, danger: ErrorIcon, success: CheckmarkCircleFillIcon, primary: InfoFilledIcon, }; const MessageContainer = styled.div` background-color: gray; padding: 16px; border-radius: 16px; border: solid 1px; ${space} ${systemVariant({ variants, })} `; const Flex = styled.div` display: flex; `; const colors = { // these color names should be place in the theme once the palette is finalized warning: "#D67E0A", success: "#129E7D", danger: "failure", primary: "text", }; export const MessageText: React.FC> = ({ children, ...props }) => { const ctx = useContext(MessageContext); return ( {children} ); }; const Message: React.FC> = ({ children, variant, icon, action, actionInline, showIcon = true, ...props }) => { const Icon = Icons[variant]; const providerValue = useMemo(() => ({ variant }), [variant]); return ( {showIcon && {icon ?? }} {children} {actionInline && action} {!actionInline && action} ); }; export default Message;