aboutsummaryrefslogtreecommitdiffstats
path: root/client/js/app/src/app/libs/notification/messages.jsx
blob: e9236d7efb3b4dcc3e55120a51d549cc0f2a833d (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
import React from 'react';
import { showNotification } from '@mantine/notifications';
import { Icon } from 'app/components';
import { SHADE } from 'app/styles/theme/colors';

function getStyles(color) {
  return (theme) => ({
    root: {
      color: theme.fn.themeColor(color, SHADE.LOW_CONTRAST_TEXT),
      background: theme.fn.themeColor(color, SHADE.UI_ELEMENT_BACKGROUND),
      borderColor: theme.fn.themeColor(
        color,
        SHADE.UI_ELEMENT_BORDER_AND_FOCUS
      ),
    },
    title: {
      fontWeight: 700,
      color: theme.fn.themeColor(color, SHADE.LOW_CONTRAST_TEXT),
      '&:hover': {
        color: theme.fn.themeColor(color, SHADE.LOW_CONTRAST_TEXT),
      },
    },
    description: {
      color: theme.fn.themeColor(color, SHADE.LOW_CONTRAST_TEXT),
      '&:hover': {
        color: theme.fn.themeColor(color, SHADE.LOW_CONTRAST_TEXT),
      },
    },
    closeButton: {
      color: theme.fn.themeColor(color, SHADE.LOW_CONTRAST_TEXT),
      '&:hover': {
        backgroundColor: theme.fn.themeColor(
          color,
          SHADE.HOVERED_UI_ELEMENT_BACKGROUND
        ),
      },
    },
  });
}

const commonMessage = ({ title, icon, color, message }) => {
  return showNotification({
    styles: getStyles(color),
    icon: <Icon name={icon} />,
    title,
    color,
    message,
  });
};

export const infoMessage = (
  message,
  title = 'Info',
  icon = 'info',
  color = 'blue'
) => commonMessage({ title, icon, color, message });

export const warningMessage = (
  message,
  title = 'Warning',
  icon = 'exclamation',
  color = 'orange'
) => commonMessage({ title, icon, color, message });

export const errorMessage = (
  message,
  title = 'Error',
  icon = 'xmark',
  color = 'red'
) => commonMessage({ title, icon, color, message });

export const successMessage = (
  message,
  title = 'Success',
  icon = 'check',
  color = 'green'
) => commonMessage({ title, icon, color, message });