@bitrise/bitkit 10.12.0-alpha-export-new-notification.1 → 10.12.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.12.0-alpha-export-new-notification.1",
4
+ "version": "10.12.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -25,18 +25,18 @@ const onButtonClick = (e: MouseEvent<HTMLButtonElement>) => {
25
25
  e.stopPropagation();
26
26
  };
27
27
 
28
- const ButtonContentElement = () => {
28
+ const ButtonContentElement = ({ title }: { title: string }) => {
29
29
  return (
30
30
  <Box display="flex" alignItems="center" flexGrow={1}>
31
31
  <Icon name="Doc" />
32
32
  <Text as="p" align="left" size="3" margin="0 auto 0 1rem">
33
- The buttonContent is a React element
33
+ {title}
34
34
  <br />
35
35
  <Text as="span" size="2" textColor="neutral.40">
36
36
  Generated by clone-build workflow
37
37
  </Text>
38
38
  </Text>
39
- <Button as="a" size="small" onClick={onButtonClick} leftIconName="Download">
39
+ <Button as="a" href="#" size="small" onClick={onButtonClick} leftIconName="Download">
40
40
  Download
41
41
  </Button>
42
42
  </Box>
@@ -48,9 +48,13 @@ export const DefaultVariant: ComponentStory<typeof Accordion> = (props) => (
48
48
  <AccordionItem buttonContent="The buttonContent is a string" fontSize="2" id="first">
49
49
  Content - you can use any style prop on AccordionItem
50
50
  </AccordionItem>
51
- <AccordionItem buttonContent={<ButtonContentElement />} fontSize="2" id="second">
51
+ <AccordionItem
52
+ buttonContent={<ButtonContentElement title="The buttonContent is a React element" />}
53
+ fontSize="2"
54
+ id="second"
55
+ >
52
56
  Content - you can use any style prop on AccordionItem
53
57
  </AccordionItem>
54
- <AccordionItem buttonContent="Without children the button is disabled" id="third" />
58
+ <AccordionItem buttonContent={<ButtonContentElement title="Without children" />} id="third" />
55
59
  </Accordion>
56
60
  );
@@ -0,0 +1,34 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import Accordion from './Accordion';
4
+ import AccordionItem from './AccordionItem';
5
+
6
+ describe('Accordion', () => {
7
+ it('calls the onChange handler with the proper id if Accordion has a conditionally not rendered item', async () => {
8
+ const thirdId = 'third-item';
9
+ const thirdTitle = 'Third item';
10
+
11
+ const handleChange = jest.fn();
12
+
13
+ render(
14
+ <Accordion onChange={handleChange}>
15
+ <AccordionItem id="first" buttonContent="First item">
16
+ First content
17
+ </AccordionItem>
18
+ {false && (
19
+ <AccordionItem id="second" buttonContent="Second item">
20
+ Second content
21
+ </AccordionItem>
22
+ )}
23
+ <AccordionItem id={thirdId} buttonContent={thirdTitle}>
24
+ Third content
25
+ </AccordionItem>
26
+ </Accordion>,
27
+ );
28
+
29
+ const thirdTab = await screen.findByText(thirdTitle);
30
+ await userEvent.click(thirdTab);
31
+
32
+ expect(handleChange).toHaveBeenCalledWith(['third-item'], [1]);
33
+ });
34
+ });
@@ -10,19 +10,18 @@ const AccordionTheme: ComponentStyleConfig = {
10
10
  marginBottom: '16',
11
11
  },
12
12
  button: {
13
+ display: 'flex',
14
+ alignItems: 'center',
15
+ justifyContent: 'space-between',
13
16
  width: '100%',
14
17
  padding: '16',
15
18
  background: colorScheme === 'gray' ? 'neutral.95' : 'neutral.100',
16
19
  borderBottom: '1px solid',
17
20
  borderColor: 'neutral.93',
18
21
  borderRadius: '8',
19
- justifyContent: 'space-between',
20
- _hover: {
22
+ '&[type="button"]:hover': {
21
23
  background: 'purple.95',
22
24
  },
23
- _disabled: {
24
- pointerEvents: 'none',
25
- },
26
25
  '&[aria-expanded="true"]': {
27
26
  borderBottomLeftRadius: '0',
28
27
  borderBottomRightRadius: '0',
@@ -20,6 +20,9 @@ const getItemIds = (props: AccordionProps) => {
20
20
  return ids;
21
21
  };
22
22
 
23
+ /**
24
+ * Accordions display a list of high-level options that can expand/collapse to reveal more information.
25
+ */
23
26
  const Accordion = (props: AccordionProps) => {
24
27
  const prefersReducedMotion = usePrefersReducedMotion();
25
28
  const { children, colorScheme, onChange, ...rest } = props;
@@ -6,8 +6,9 @@ import {
6
6
  AccordionPanel,
7
7
  AccordionPanelProps,
8
8
  AccordionIcon,
9
- useMultiStyleConfig,
9
+ useAccordionStyles,
10
10
  } from '@chakra-ui/react';
11
+ import Box from '../Box/Box';
11
12
  import Text from '../Text/Text';
12
13
 
13
14
  export interface AccordionItemProps extends AccordionPanelProps {
@@ -18,14 +19,16 @@ export interface AccordionItemProps extends AccordionPanelProps {
18
19
 
19
20
  const AccordionItem = (props: AccordionItemProps) => {
20
21
  const { buttonContent, children, id, ...rest } = props;
21
- const styles = useMultiStyleConfig('Accordion');
22
+ const styles = useAccordionStyles();
23
+
24
+ const ButtonComponent = children ? AccordionButton : Box;
22
25
 
23
26
  return (
24
- <ChakraAccordionItem sx={styles.item} id={id} isDisabled={!children}>
25
- <AccordionButton>
27
+ <ChakraAccordionItem sx={styles.item} id={id}>
28
+ <ButtonComponent sx={styles.button}>
26
29
  {isValidElement(buttonContent) ? buttonContent : <Text as="span">{buttonContent}</Text>}
27
- <AccordionIcon />
28
- </AccordionButton>
30
+ <AccordionIcon opacity={children ? 1 : 0.4} />
31
+ </ButtonComponent>
29
32
  {!!children && <AccordionPanel {...rest}>{children}</AccordionPanel>}
30
33
  </ChakraAccordionItem>
31
34
  );
@@ -124,3 +124,12 @@ export const InsideDialog = () => {
124
124
  </Provider>
125
125
  );
126
126
  };
127
+ export const WithIcon = () => {
128
+ return (
129
+ <Dropdown iconName="Calendar" defaultValue="daily">
130
+ <DropdownOption value="daily">Daily</DropdownOption>
131
+ <DropdownOption value="weekly">Weekly</DropdownOption>
132
+ <DropdownOption value="monthly">Monthly</DropdownOption>
133
+ </Dropdown>
134
+ );
135
+ };
@@ -86,6 +86,7 @@ const DropdownTheme = {
86
86
  height: '32',
87
87
  paddingLeft: '12',
88
88
  paddingRight: '12',
89
+ gap: '0.375rem',
89
90
  },
90
91
  },
91
92
  medium: {
@@ -94,6 +95,7 @@ const DropdownTheme = {
94
95
  height: '48',
95
96
  paddingLeft: '16',
96
97
  paddingRight: '16',
98
+ gap: '0.625rem',
97
99
  },
98
100
  },
99
101
  },
@@ -19,7 +19,7 @@ import {
19
19
  useMultiStyleConfig,
20
20
  } from '@chakra-ui/react';
21
21
  import { FloatingFocusManager } from '@floating-ui/react-dom-interactions';
22
- import Icon from '../Icon/Icon';
22
+ import Icon, { TypeIconName } from '../Icon/Icon';
23
23
  import { DropdownEventArgs, DropdownProvider, useDropdownContext, useDropdownStyles } from './Dropdown.context';
24
24
  import { DropdownOption, DropdownGroup, DropdownDetailedOption, DropdownOptionProps } from './DropdownOption';
25
25
  import DropdownButton from './DropdownButton';
@@ -101,6 +101,7 @@ export interface DropdownProps<T> extends ChakraProps {
101
101
  'aria-label'?: string;
102
102
  search?: ReactNode;
103
103
  children?: ReactNode;
104
+ iconName?: TypeIconName;
104
105
  }
105
106
 
106
107
  function useOptionListWithIndexes({ children }: { children: ReactNode }) {
@@ -1,6 +1,6 @@
1
1
  import { forwardRef, ReactNode } from 'react';
2
2
  import { chakra, ChakraProps } from '@chakra-ui/react';
3
- import Icon from '../Icon/Icon';
3
+ import Icon, { TypeIconName } from '../Icon/Icon';
4
4
  import { useDropdownStyles } from './Dropdown.context';
5
5
 
6
6
  interface DropdownButtonProps extends ChakraProps {
@@ -10,17 +10,19 @@ interface DropdownButtonProps extends ChakraProps {
10
10
  formLabel?: ReactNode;
11
11
  size: 'medium' | 'small';
12
12
  children?: ReactNode;
13
+ iconName?: TypeIconName;
13
14
  }
14
15
  const DropdownButton = forwardRef<HTMLButtonElement, DropdownButtonProps>(
15
- ({ size, blurHandler, formLabel, readOnly, placeholder, children, ...rest }, ref) => {
16
+ ({ size, blurHandler, formLabel, readOnly, placeholder, children, iconName, ...rest }, ref) => {
16
17
  const { field, icon } = useDropdownStyles();
17
18
  const iconSize = size === 'medium' ? '24' : '16';
18
19
  return (
19
20
  <chakra.button aria-readonly={readOnly} type="button" ref={ref} onBlur={blurHandler} __css={field} {...rest}>
21
+ {iconName && <Icon aria-hidden="true" __css={icon} name={iconName} size={iconSize} />}
20
22
  <chakra.span overflow="hidden" textOverflow="ellipsis" whiteSpace="nowrap" flexGrow={1}>
21
23
  {formLabel || placeholder}
22
24
  </chakra.span>
23
- <Icon aria-hidden="true" __css={icon} name="DropdownArrows" fontSize={iconSize} size={iconSize} />
25
+ <Icon aria-hidden="true" __css={icon} name="DropdownArrows" size={iconSize} />
24
26
  </chakra.button>
25
27
  );
26
28
  },
@@ -15,9 +15,7 @@ import CloseButton from '../CloseButton/CloseButton';
15
15
  import ColorButton, { ColorButtonProps } from '../ColorButton/ColorButton';
16
16
  import Icon, { TypeIconName } from '../Icon/Icon';
17
17
 
18
- type NotificationStatus = 'info' | 'error' | 'success' | 'warning' | 'progress';
19
-
20
- const STATUSES: Record<NotificationStatus, { colorScheme: ColorScheme; defaultIcon: ReactNode }> = {
18
+ const STATUSES: Record<string, { colorScheme: ColorScheme; defaultIcon: ReactNode }> = {
21
19
  info: { colorScheme: 'blue', defaultIcon: <Icon name="Info" /> },
22
20
  error: { colorScheme: 'red', defaultIcon: <Icon name="ErrorGeneral" /> },
23
21
  success: { colorScheme: 'green', defaultIcon: <Icon name="Tick" /> },
@@ -37,7 +35,7 @@ export type ActionProps = { label: string; href?: string; onClick?: () => void }
37
35
  'as' | 'onClick' | 'colorScheme'
38
36
  >;
39
37
  export interface NotificationProps extends Omit<AlertProps, 'status' | 'colorScheme' | 'onClose'> {
40
- status: NotificationStatus;
38
+ status: keyof typeof STATUSES;
41
39
  onClose?: () => void;
42
40
  action?: ActionProps;
43
41
  iconName?: TypeIconName;
@@ -0,0 +1,36 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import Tabs from './Tabs';
4
+ import TabList from './TabList';
5
+ import Tab from './Tab';
6
+ import TabPanels from './TabPanels';
7
+ import TabPanel from './TabPanel';
8
+
9
+ describe('Tabs', () => {
10
+ it('calls the onChange handler with the proper id if TabList has a conditionally not rendered item', async () => {
11
+ const thirdTabId = 'third-tab';
12
+ const thirdTabTitle = 'Third tab';
13
+
14
+ const handleChange = jest.fn();
15
+
16
+ render(
17
+ <Tabs onChange={handleChange}>
18
+ <TabList>
19
+ <Tab id="first-tab">First tab</Tab>
20
+ {false && <Tab id="second-tab">Second tab</Tab>}
21
+ <Tab id={thirdTabId}>{thirdTabTitle}</Tab>
22
+ </TabList>
23
+ <TabPanels>
24
+ <TabPanel>First content</TabPanel>
25
+ {false && <TabPanel>Second content</TabPanel>}
26
+ <TabPanel>Third content</TabPanel>
27
+ </TabPanels>
28
+ </Tabs>,
29
+ );
30
+
31
+ const thirdTab = await screen.findByText(thirdTabTitle);
32
+ await userEvent.click(thirdTab);
33
+
34
+ expect(handleChange).toHaveBeenCalledWith(1, thirdTabId);
35
+ });
36
+ });
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { isValidElement, ReactElement, useEffect, useState } from 'react';
2
2
  import { Tabs as ChakraTabs, TabsProps as ChakraTabsProps, forwardRef } from '@chakra-ui/react';
3
3
  import { useHistory } from '../../hooks';
4
4
 
@@ -8,13 +8,11 @@ export interface TabsProps extends ChakraTabsProps {
8
8
  withHistory?: boolean;
9
9
  }
10
10
 
11
- const getTabIds = (props: TabsProps) => {
12
- const ids: string[] = [];
13
- const tabs = React.Children.toArray(props.children)[0] as any;
14
- React.Children.forEach(tabs.props.children, (c, index) => {
15
- ids[index] = c?.props?.id;
16
- });
17
- return ids;
11
+ const getTabIds = (props: TabsProps): string[] => {
12
+ const tabList = React.Children.toArray(props.children)[0] as ReactElement;
13
+ const tabs = React.Children.toArray(tabList.props.children) as ReactElement[];
14
+
15
+ return tabs.filter((item) => isValidElement(item)).map((item) => item.props.id);
18
16
  };
19
17
 
20
18
  /**
@@ -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
@@ -152,9 +152,6 @@ 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
-
158
155
  export { BREAKPOINTS } from './Foundations/Breakpoints/Breakpoints';
159
156
 
160
157
  export type { AccordionProps } from './Components/Accordion/Accordion';
package/src/old.ts CHANGED
@@ -51,6 +51,9 @@ 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
+
54
57
  export type { Props as ProgressBarProps } from './Old/Progress/ProgressBar';
55
58
  export { default as ProgressBar } from './Old/Progress/ProgressBar';
56
59