@bitrise/bitkit 10.16.2 → 10.17.0-alpha-export-new-notification.1

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.16.2",
4
+ "version": "10.17.0-alpha-export-new-notification.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -56,3 +56,11 @@ WithoutIcon.args = {
56
56
  action: undefined,
57
57
  showIcon: false,
58
58
  };
59
+
60
+ export const WithAction: ComponentStoryFn<typeof Notification> = (props) => <Template {...props} />;
61
+ WithAction.storyName = 'With action';
62
+ WithAction.args = {
63
+ action: {
64
+ label: 'Upgrade',
65
+ },
66
+ };
@@ -1,4 +1,4 @@
1
- import { createContext, ReactNode, useContext, useMemo } from 'react';
1
+ import { cloneElement, createContext, ReactElement, useContext, useMemo } from 'react';
2
2
  import {
3
3
  Alert as ChakraAlert,
4
4
  AlertTitle as NotificationTitle,
@@ -15,7 +15,9 @@ import CloseButton from '../CloseButton/CloseButton';
15
15
  import ColorButton, { ColorButtonProps } from '../ColorButton/ColorButton';
16
16
  import Icon, { TypeIconName } from '../Icon/Icon';
17
17
 
18
- const STATUSES: Record<string, { colorScheme: ColorScheme; defaultIcon: ReactNode }> = {
18
+ type NotificationStatus = 'info' | 'error' | 'success' | 'warning' | 'progress';
19
+
20
+ const STATUSES: Record<NotificationStatus, { colorScheme: ColorScheme; defaultIcon: ReactElement }> = {
19
21
  info: { colorScheme: 'blue', defaultIcon: <Icon name="Info" /> },
20
22
  error: { colorScheme: 'red', defaultIcon: <Icon name="ErrorGeneral" /> },
21
23
  success: { colorScheme: 'green', defaultIcon: <Icon name="Tick" /> },
@@ -24,25 +26,28 @@ const STATUSES: Record<string, { colorScheme: ColorScheme; defaultIcon: ReactNod
24
26
  colorScheme: 'purple',
25
27
  defaultIcon: (
26
28
  <chakra.span w="24" h="24" p="2">
27
- <Spinner w="100%" h="100%" />
29
+ <Spinner w="100" h="100" />
28
30
  </chakra.span>
29
31
  ),
30
32
  },
31
33
  } as const;
32
34
 
33
- export type ActionProps = { label: string; href?: string; onClick?: () => void } & Omit<
34
- ColorButtonProps,
35
- 'as' | 'onClick' | 'colorScheme'
36
- >;
35
+ export type ActionProps = {
36
+ label: string;
37
+ href?: string;
38
+ onClick?: () => void;
39
+ } & Omit<ColorButtonProps, 'as' | 'onClick' | 'colorScheme'>;
37
40
  export interface NotificationProps extends Omit<AlertProps, 'status' | 'colorScheme' | 'onClose'> {
38
- status: keyof typeof STATUSES;
41
+ status: NotificationStatus;
39
42
  onClose?: () => void;
40
43
  action?: ActionProps;
41
44
  iconName?: TypeIconName;
42
45
  showIcon?: boolean;
43
46
  }
44
47
 
45
- const ActionContext = createContext<{ colorScheme: ColorScheme }>({ colorScheme: 'blue' });
48
+ const ActionContext = createContext<{ colorScheme: ColorScheme }>({
49
+ colorScheme: 'blue',
50
+ });
46
51
 
47
52
  const NotificationAction = ({ label, href, ...rest }: ActionProps) => {
48
53
  const actionContext = useContext(ActionContext);
@@ -69,11 +74,14 @@ const Notification = forwardRef<NotificationProps, 'div'>((props, ref) => {
69
74
  actionButton = <NotificationAction marginRight="12" {...action} alignSelf="center" />;
70
75
  }
71
76
  const actionContext = useMemo(() => ({ colorScheme }), [colorScheme]);
77
+ // This is needed when the actionButton is rendered with a one-liner text.
78
+ // Without this both the icon and the text would be strangely aligned.
79
+ const marginTop = actionButton ? 4 : undefined;
72
80
  return (
73
81
  <ChakraAlert ref={ref} {...rest} colorScheme={colorScheme}>
74
82
  <ActionContext.Provider value={actionContext}>
75
- {showIcon && <Box flexShrink={0}>{icon}</Box>}
76
- <Box wordBreak="break-word" display="flex" flexDirection="column" flexGrow={1}>
83
+ {showIcon && cloneElement(icon, { flexShrink: 0, marginTop })}
84
+ <Box wordBreak="break-word" display="flex" flexDirection="column" flexGrow={1} marginTop={marginTop}>
77
85
  {children}
78
86
  </Box>
79
87
  {actionButton}
package/src/index.ts CHANGED
@@ -152,6 +152,9 @@ export {
152
152
  typedDropdown,
153
153
  } from './Components/Dropdown/Dropdown';
154
154
 
155
+ export type { NotificationProps } from './Components/Notification/Notification';
156
+ export { default as Notification } from './Components/Notification/Notification';
157
+
155
158
  export { BREAKPOINTS } from './Foundations/Breakpoints/Breakpoints';
156
159
 
157
160
  export type { AccordionProps } from './Components/Accordion/Accordion';
package/src/old.ts CHANGED
@@ -51,9 +51,6 @@ export { default as InputLabel } from './Old/Input/InputLabel';
51
51
  export type { Props as LogoProps } from './Old/Logo/Logo';
52
52
  export { default as Logo } from './Old/Logo/Logo';
53
53
 
54
- export type { Props as NotificationProps } from './Old/Notification/Notification';
55
- export { default as Notification } from './Old/Notification/Notification';
56
-
57
54
  export type { Props as ProgressBarProps } from './Old/Progress/ProgressBar';
58
55
  export { default as ProgressBar } from './Old/Progress/ProgressBar';
59
56