@bitrise/bitkit 10.5.0-alpha-notification.1 → 10.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "10.5.0-alpha-notification.1",
4
+ "version": "10.5.2",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -1,5 +1,5 @@
1
1
  import { Button as ChakraButton, ButtonProps as ChakraButtonProps, forwardRef, useStyleConfig } from '@chakra-ui/react';
2
- import { ColorScheme } from '@/Foundations/Colors/Colors';
2
+ import { ColorScheme } from '../../Foundations/Colors/Colors';
3
3
 
4
4
  export interface ColorButtonProps extends ChakraButtonProps {
5
5
  as?: 'a' | 'button';
@@ -31,12 +31,28 @@ export default {
31
31
  },
32
32
  } as ComponentMeta<typeof Notification>;
33
33
 
34
- export const Default: ComponentStoryFn<typeof Notification> = ({ title, description, ...args }) => (
35
- <Notification {...args}>
34
+ const Template: ComponentStoryFn<typeof Notification> = ({ title, description, ...props }) => (
35
+ <Notification {...props}>
36
36
  <NotificationTitle>{title}</NotificationTitle>
37
37
  <NotificationText>{description}</NotificationText>
38
38
  </Notification>
39
39
  );
40
+
41
+ export const Default: ComponentStoryFn<typeof Notification> = (props) => <Template {...props} />;
40
42
  Default.args = {
41
43
  action: undefined,
42
44
  };
45
+
46
+ export const WithCustomIcon: ComponentStoryFn<typeof Notification> = (props) => <Template {...props} />;
47
+ WithCustomIcon.storyName = 'With custom icon';
48
+ WithCustomIcon.args = {
49
+ action: undefined,
50
+ iconName: 'Bitbot',
51
+ };
52
+
53
+ export const WithoutIcon: ComponentStoryFn<typeof Notification> = (props) => <Template {...props} />;
54
+ WithoutIcon.storyName = 'Without icon';
55
+ WithoutIcon.args = {
56
+ action: undefined,
57
+ showIcon: false,
58
+ };
@@ -13,17 +13,17 @@ import { ColorScheme } from '@/Foundations/Colors/Colors';
13
13
  import Box from '../Box/Box';
14
14
  import CloseButton from '../CloseButton/CloseButton';
15
15
  import ColorButton, { ColorButtonProps } from '../ColorButton/ColorButton';
16
- import Icon from '../Icon/Icon';
16
+ import Icon, { TypeIconName } from '../Icon/Icon';
17
17
 
18
- const STATUSES: Record<string, { colorScheme: ColorScheme; icon: ReactNode }> = {
19
- info: { colorScheme: 'blue', icon: <Icon flexShrink={0} name="Info" /> },
20
- error: { colorScheme: 'red', icon: <Icon flexShrink={0} name="ErrorGeneral" /> },
21
- success: { colorScheme: 'green', icon: <Icon flexShrink={0} name="Tick" /> },
22
- warning: { colorScheme: 'yellow', icon: <Icon flexShrink={0} name="Warning" /> },
18
+ const STATUSES: Record<string, { colorScheme: ColorScheme; defaultIcon: ReactNode }> = {
19
+ info: { colorScheme: 'blue', defaultIcon: <Icon name="Info" /> },
20
+ error: { colorScheme: 'red', defaultIcon: <Icon name="ErrorGeneral" /> },
21
+ success: { colorScheme: 'green', defaultIcon: <Icon name="Tick" /> },
22
+ warning: { colorScheme: 'yellow', defaultIcon: <Icon name="Warning" /> },
23
23
  progress: {
24
24
  colorScheme: 'purple',
25
- icon: (
26
- <chakra.span w="24" h="24" p="2" flexShrink={0}>
25
+ defaultIcon: (
26
+ <chakra.span w="24" h="24" p="2">
27
27
  <Spinner w="100%" h="100%" />
28
28
  </chakra.span>
29
29
  ),
@@ -38,6 +38,8 @@ export interface NotificationProps extends Omit<AlertProps, 'status' | 'colorSch
38
38
  status: keyof typeof STATUSES;
39
39
  onClose?: () => void;
40
40
  action?: ActionProps;
41
+ iconName?: TypeIconName;
42
+ showIcon?: boolean;
41
43
  }
42
44
 
43
45
  const ActionContext = createContext<{ colorScheme: ColorScheme }>({ colorScheme: 'blue' });
@@ -59,8 +61,9 @@ const NotificationAction = ({ label, href, ...rest }: ActionProps) => {
59
61
  };
60
62
 
61
63
  const Notification = forwardRef<NotificationProps, 'div'>((props, ref) => {
62
- const { status, action, children, onClose, ...rest } = props;
63
- const { colorScheme, icon } = STATUSES[status];
64
+ const { status, action, children, onClose, showIcon = true, iconName, ...rest } = props;
65
+ const { colorScheme, defaultIcon } = STATUSES[status];
66
+ const icon = iconName ? <Icon name={iconName} /> : defaultIcon;
64
67
  let actionButton;
65
68
  if (action) {
66
69
  actionButton = <NotificationAction marginRight="12" {...action} alignSelf="center" />;
@@ -69,7 +72,7 @@ const Notification = forwardRef<NotificationProps, 'div'>((props, ref) => {
69
72
  return (
70
73
  <ChakraAlert ref={ref} {...rest} colorScheme={colorScheme}>
71
74
  <ActionContext.Provider value={actionContext}>
72
- {icon}
75
+ {showIcon && <Box flexShrink={0}>{icon}</Box>}
73
76
  <Box wordBreak="break-word" display="flex" flexDirection="column" flexGrow={1}>
74
77
  {children}
75
78
  </Box>
@@ -1,7 +1,8 @@
1
1
  import { createContext, useContext, useMemo } from 'react';
2
2
  import { Alert as ChakraAlert, AlertProps, forwardRef } from '@chakra-ui/react';
3
3
 
4
- import { ColorScheme } from '@/Foundations/Colors/Colors';
4
+ import { ColorScheme } from '../../Foundations/Colors/Colors';
5
+ import { BREAKPOINTS } from '../../Foundations/Breakpoints/Breakpoints';
5
6
  import CloseButton from '../CloseButton/CloseButton';
6
7
  import ColorButton, { ColorButtonProps } from '../ColorButton/ColorButton';
7
8
  import Icon from '../Icon/Icon';
@@ -61,9 +62,22 @@ const Ribbon = forwardRef<RibbonProps, 'div'>((props, ref) => {
61
62
  {...rest}
62
63
  >
63
64
  <ActionContext.Provider value={actionContext}>
64
- {onClose && <Box width={24} height={24} marginRight="auto" />}
65
- {children}
66
- {actionButton}
65
+ {onClose && (
66
+ <Box
67
+ display={{ [BREAKPOINTS.MOBILE]: 'none', [BREAKPOINTS.DESKTOP]: 'block' }}
68
+ width={24}
69
+ height={24}
70
+ marginEnd="auto"
71
+ />
72
+ )}
73
+ <Box
74
+ display="flex"
75
+ flexDirection={{ [BREAKPOINTS.MOBILE]: 'column', [BREAKPOINTS.DESKTOP]: 'row' }}
76
+ gap={{ [BREAKPOINTS.MOBILE]: 12, [BREAKPOINTS.DESKTOP]: 16 }}
77
+ >
78
+ {children}
79
+ {actionButton}
80
+ </Box>
67
81
  {onClose && (
68
82
  <CloseButton flexShrink={0} colorScheme={colorScheme} marginStart="auto" onClick={onClose}>
69
83
  <Icon name="CloseSmall" />
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
- import Text, { Props as TextProps } from '../Text/Text';
2
+ import Text, { TextProps } from '../../Components/Text/Text';
3
3
 
4
4
  export type Props = TextProps;
5
5
 
6
6
  /** Provides specific styling for an inline input label */
7
7
  const InputInlineHelp: React.FunctionComponent<Props> = (props: Props) => {
8
- return <Text margin="x2" size="2" textColor="neutral.50" {...props} />;
8
+ return <Text marginY="8" size="2" color="neutral.50" {...props} />;
9
9
  };
10
10
 
11
11
  export default InputInlineHelp;
@@ -0,0 +1,34 @@
1
+ .Notification {
2
+ border: 0.0625rem solid transparent;
3
+ border-radius: var(--size--x2);
4
+ }
5
+
6
+ .Notification--type-alert {
7
+ border-color: var(--color-red--3);
8
+ background-color: var(--color-red--1);
9
+ color: var(--color-red--4);
10
+ }
11
+
12
+ .Notification--type-inform {
13
+ border-color: var(--color-blue--2);
14
+ background-color: var(--color-blue--1);
15
+ color: var(--color-blue--4);
16
+ }
17
+
18
+ .Notification--type-progress {
19
+ border-color: var(--color-grape--2);
20
+ background-color: var(--color-grape--1);
21
+ color: var(--color-eggplant);
22
+ }
23
+
24
+ .Notification--type-success {
25
+ border-color: var(--color-green--2);
26
+ background-color: var(--color-green--1);
27
+ color: var(--color-green--5);
28
+ }
29
+
30
+ .Notification--type-warning {
31
+ border-color: var(--color-yellow--3);
32
+ background-color: var(--color-yellow--1);
33
+ color: var(--color-yellow--5);
34
+ }
@@ -0,0 +1,33 @@
1
+ import { shallow } from 'enzyme';
2
+ import { shallowToJson } from 'enzyme-to-json';
3
+ import Notification from './Notification';
4
+
5
+ describe('Notification', () => {
6
+ test('default template', () => {
7
+ expect(shallowToJson(shallow(<Notification type="alert">Content</Notification>))).toMatchSnapshot();
8
+ });
9
+
10
+ test('default icon can be overridden', () => {
11
+ expect(
12
+ shallowToJson(
13
+ shallow(
14
+ <Notification icon="Bell" type="alert">
15
+ Content
16
+ </Notification>,
17
+ ),
18
+ ),
19
+ ).toMatchSnapshot();
20
+ });
21
+
22
+ test('with onRemove has a close icon', () => {
23
+ expect(
24
+ shallowToJson(
25
+ shallow(
26
+ <Notification onRemove={() => {}} type="alert">
27
+ Content
28
+ </Notification>,
29
+ ),
30
+ ),
31
+ ).toMatchSnapshot();
32
+ });
33
+ });
@@ -0,0 +1,69 @@
1
+ import * as React from 'react';
2
+ import classnames from 'classnames';
3
+ import Flex, { Props as FlexProps } from '../Flex/Flex';
4
+ import Icon, { TypeIconName } from '../../Components/Icon/Icon';
5
+ import Link from '../../Components/Link/Link';
6
+ import ProgressSpinner from '../Progress/ProgressSpinner';
7
+ import './Notification.css';
8
+
9
+ type TypeNotificationType = 'alert' | 'inform' | 'progress' | 'success' | 'warning';
10
+
11
+ export interface Props extends FlexProps {
12
+ /**
13
+ * A callback to remove the notification, that when provided will
14
+ * render a clickable cross, that when clicked will call the given
15
+ * function.
16
+ */
17
+ onRemove?: (e: React.SyntheticEvent) => void;
18
+ /**
19
+ * Name of one of the Bitkit icons that will accompany the message
20
+ * of the notification. By default, some of the notification
21
+ * types have icons, but these can be overridden.
22
+ */
23
+ icon?: TypeIconName;
24
+ /**
25
+ * The type of the notification that affects the styling and content.
26
+ */
27
+ type: TypeNotificationType;
28
+ }
29
+
30
+ const defaultIcons: {
31
+ [key: string]: TypeIconName;
32
+ } = {
33
+ alert: 'ErrorGeneral',
34
+ success: 'Tick',
35
+ warning: 'Warning',
36
+ };
37
+
38
+ /**
39
+ * Notification component used to inform the user of something important.
40
+ */
41
+ const Notification: React.FunctionComponent<Props> = (props: Props) => {
42
+ const { children, onRemove, type, icon, className, ...rest } = props;
43
+
44
+ const classes = classnames('Notification', `Notification--type-${type}`, className);
45
+ const defaultIcon = defaultIcons[type];
46
+
47
+ return (
48
+ <Flex {...rest} alignChildrenVertical="middle" className={classes} direction="horizontal" gap="x2" padding="x3">
49
+ {(icon || defaultIcon || type === 'progress') && (
50
+ <Flex>{type === 'progress' ? <ProgressSpinner /> : <Icon name={icon || defaultIcon} />}</Flex>
51
+ )}
52
+
53
+ <Flex grow shrink>
54
+ {children}
55
+ </Flex>
56
+
57
+ {onRemove && (
58
+ <Flex>
59
+ {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
60
+ <Link as="button" onClick={onRemove}>
61
+ <Icon name="CloseSmall" />
62
+ </Link>
63
+ </Flex>
64
+ )}
65
+ </Flex>
66
+ );
67
+ };
68
+
69
+ export default Notification;
@@ -0,0 +1,78 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Notification default icon can be overridden 1`] = `
4
+ <Flex
5
+ alignChildrenVertical="middle"
6
+ className="Notification Notification--type-alert"
7
+ direction="horizontal"
8
+ gap="x2"
9
+ padding="x3"
10
+ >
11
+ <Flex>
12
+ <ForwardRef
13
+ name="Bell"
14
+ />
15
+ </Flex>
16
+ <Flex
17
+ grow={true}
18
+ shrink={true}
19
+ >
20
+ Content
21
+ </Flex>
22
+ </Flex>
23
+ `;
24
+
25
+ exports[`Notification default template 1`] = `
26
+ <Flex
27
+ alignChildrenVertical="middle"
28
+ className="Notification Notification--type-alert"
29
+ direction="horizontal"
30
+ gap="x2"
31
+ padding="x3"
32
+ >
33
+ <Flex>
34
+ <ForwardRef
35
+ name="ErrorGeneral"
36
+ />
37
+ </Flex>
38
+ <Flex
39
+ grow={true}
40
+ shrink={true}
41
+ >
42
+ Content
43
+ </Flex>
44
+ </Flex>
45
+ `;
46
+
47
+ exports[`Notification with onRemove has a close icon 1`] = `
48
+ <Flex
49
+ alignChildrenVertical="middle"
50
+ className="Notification Notification--type-alert"
51
+ direction="horizontal"
52
+ gap="x2"
53
+ padding="x3"
54
+ >
55
+ <Flex>
56
+ <ForwardRef
57
+ name="ErrorGeneral"
58
+ />
59
+ </Flex>
60
+ <Flex
61
+ grow={true}
62
+ shrink={true}
63
+ >
64
+ Content
65
+ </Flex>
66
+ <Flex>
67
+ <ForwardRef
68
+ as="button"
69
+ isUnderlined={false}
70
+ onClick={[Function]}
71
+ >
72
+ <ForwardRef
73
+ name="CloseSmall"
74
+ />
75
+ </ForwardRef>
76
+ </Flex>
77
+ </Flex>
78
+ `;
package/src/index.ts CHANGED
@@ -139,7 +139,4 @@ export { default as BreadcrumbLink } from './Components/Breadcrumb/BreadcrumbLin
139
139
  export type { RibbonProps } from './Components/Ribbon/Ribbon';
140
140
  export { default as Ribbon } from './Components/Ribbon/Ribbon';
141
141
 
142
- export type { NotificationProps } from './Components/Notification/Notification';
143
- export { default as Notification } from './Components/Notification/Notification';
144
-
145
142
  export { BREAKPOINTS } from './Foundations/Breakpoints/Breakpoints';
package/src/old.ts CHANGED
@@ -54,6 +54,9 @@ export { default as InputLabel } from './Old/Input/InputLabel';
54
54
  export type { Props as LogoProps } from './Old/Logo/Logo';
55
55
  export { default as Logo } from './Old/Logo/Logo';
56
56
 
57
+ export type { Props as NotificationProps } from './Old/Notification/Notification';
58
+ export { default as Notification } from './Old/Notification/Notification';
59
+
57
60
  export type { Props as ProgressBarProps } from './Old/Progress/ProgressBar';
58
61
  export { default as ProgressBar } from './Old/Progress/ProgressBar';
59
62