@bitrise/bitkit 9.22.1 → 9.23.0-alpha-chakra.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": "9.22.1",
4
+ "version": "9.23.0-alpha-chakra.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -9,7 +9,6 @@ const BadgeTheme = {
9
9
  fontWeight: 'bold',
10
10
  textTransform: 'uppercase',
11
11
  borderRadius: '4',
12
- cursor: 'default',
13
12
  },
14
13
  };
15
14
 
@@ -23,4 +23,5 @@ WithProps.args = sortObjectByKey({
23
23
  isDanger: false,
24
24
  isDisabled: false,
25
25
  isLoading: false,
26
+ isTooltipDisabled: false,
26
27
  });
@@ -7,6 +7,7 @@ export interface IconButtonProps extends ChakraIconButtonProps {
7
7
  as?: 'a' | 'button';
8
8
  iconName: TypeIconName;
9
9
  isDanger?: boolean;
10
+ isTooltipDisabled?: boolean;
10
11
  label?: string;
11
12
  size?: 'small' | 'medium';
12
13
  tooltipCloseDelay?: number;
@@ -17,7 +18,7 @@ export interface IconButtonProps extends ChakraIconButtonProps {
17
18
  * IconButton composes the `Button` component except that it renders only an icon.
18
19
  */
19
20
  const IconButton = forwardRef<IconButtonProps, 'button'>((props, ref) => {
20
- const { as, iconName, isDanger, isDisabled, label, tooltipCloseDelay, variant, ...rest } = props;
21
+ const { as, iconName, isDanger, isDisabled, isTooltipDisabled, label, tooltipCloseDelay, variant, ...rest } = props;
21
22
  const properties: ChakraIconButtonProps = {
22
23
  as: isDisabled ? 'button' : as,
23
24
  icon: <Icon name={iconName} />,
@@ -26,7 +27,12 @@ const IconButton = forwardRef<IconButtonProps, 'button'>((props, ref) => {
26
27
  ...rest,
27
28
  };
28
29
  return (
29
- <Tooltip closeDelay={tooltipCloseDelay} label={label || rest['aria-label']} shouldWrapChildren={isDisabled}>
30
+ <Tooltip
31
+ closeDelay={tooltipCloseDelay}
32
+ isDisabled={isTooltipDisabled}
33
+ label={label || rest['aria-label']}
34
+ shouldWrapChildren={isDisabled}
35
+ >
30
36
  <ChakraIconButton {...properties} ref={ref} />
31
37
  </Tooltip>
32
38
  );
@@ -1,23 +1,35 @@
1
1
  import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import { Box, ButtonGroup, HStack, MenuButton, MenuList, useMenuItem, useStyleConfig } from '@chakra-ui/react';
3
- import Button from '../Button/Button';
2
+ import { forwardRef } from '@chakra-ui/react';
3
+ import Badge from '../Badge/Badge';
4
+ import Box from '../Box/Box';
5
+ import Button, { ButtonProps } from '../Button/Button';
6
+ import ButtonGroup from '../ButtonGroup/ButtonGroup';
4
7
  import IconButton from '../IconButton/IconButton';
8
+ import Link from '../Link/Link';
9
+ import Icon from '../Icon/Icon';
5
10
  import Menu from './Menu';
11
+ import MenuButton from './MenuButton';
12
+ import MenuList from './MenuList';
6
13
  import MenuItem from './MenuItem';
7
14
 
8
15
  export default {
9
- title: 'Components/Menu (WIP)',
16
+ title: 'Components/Menu',
10
17
  component: Menu,
11
18
  subcomponents: { MenuButton, MenuList, MenuItem },
12
19
  } as ComponentMeta<typeof Menu>;
13
20
 
14
21
  const List = () => (
15
22
  <MenuList>
16
- <MenuItem iconName="AddonsTuorqouise">Download</MenuItem>
17
- <MenuItem iconName="AddonsTuorqouise">Create a Copy</MenuItem>
18
- <MenuItem iconName="AddonsTuorqouise">Mark as Draft</MenuItem>
19
- <MenuItem iconName="AddonsTuorqouise">Delete</MenuItem>
20
- <MenuItem iconName="AddonsTuorqouise">Attend a Workshop</MenuItem>
23
+ <MenuItem iconName="Download">Download</MenuItem>
24
+ <MenuItem as="a" href="#" iconName="Link">
25
+ As a link
26
+ </MenuItem>
27
+ <MenuItem iconName="Pencil" isDisabled>
28
+ Disabled
29
+ </MenuItem>
30
+ <MenuItem iconName="DeleteNope" isDanger>
31
+ Danger version
32
+ </MenuItem>
21
33
  </MenuList>
22
34
  );
23
35
 
@@ -28,47 +40,51 @@ export const WithButton: ComponentStory<typeof Menu> = () => (
28
40
  </Menu>
29
41
  );
30
42
 
31
- export const WithIconButton: ComponentStory<typeof Menu> = () => (
43
+ export const WithLink: ComponentStory<typeof Menu> = () => (
32
44
  <Menu>
33
- <MenuButton as={IconButton} iconName="AddOnsColorTuorqouise" aria-label="Open menu" />
45
+ <MenuButton as={Link}>Open menu</MenuButton>
34
46
  <List />
35
47
  </Menu>
36
48
  );
37
49
 
38
50
  export const WithButtonGroup: ComponentStory<typeof Menu> = () => (
39
- <HStack justifyContent="end">
51
+ <Box display="flex" justifyContent="flex-end">
40
52
  <ButtonGroup isAttached>
41
53
  <Button>Button</Button>
42
54
  <Menu>
43
- <MenuButton as={IconButton} iconName="AddOnsColorTuorqouise" aria-label="Open menu" />
55
+ <MenuButton as={IconButton} iconName="AddonsTuorqouise" aria-label="Open menu" isTooltipDisabled />
44
56
  <List />
45
57
  </Menu>
46
58
  </ButtonGroup>
47
- </HStack>
59
+ </Box>
48
60
  );
49
61
 
50
- const CustomItem = (props: any) => {
51
- const menuProps = useMenuItem(props);
52
- const { item } = useStyleConfig('Menu') as any;
62
+ const TriggerButton = forwardRef<ButtonProps, 'button'>((props, ref) => (
63
+ <Button gap="12" ref={ref} rightIconName="DropdownArrows" variant="secondary" {...props}>
64
+ <span>Attempt #3</span>
65
+ <Badge>Latest</Badge>
66
+ </Button>
67
+ ));
53
68
 
69
+ export const WithCustomItems: ComponentStory<typeof Menu> = () => {
54
70
  return (
55
- <Box as="button" {...menuProps} type="button" sx={{ ...item, width: '100%' }}>
56
- <span>eee</span>
57
- <br />
58
- <strong>aaa</strong>
59
- </Box>
71
+ <Menu>
72
+ <MenuButton as={TriggerButton} />
73
+ <MenuList>
74
+ <MenuItem>
75
+ <Box display="flex" alignItems="center" gap="8">
76
+ <Icon color="green.50" name="BuildstatusSuccessful" />
77
+ <span>Successful</span>
78
+ <Badge>Latest</Badge>
79
+ </Box>
80
+ </MenuItem>
81
+ <MenuItem>
82
+ <Box display="flex" alignItems="center" gap="8">
83
+ <Icon color="red.50" name="BuildstatusFailed" />
84
+ <span>Failed</span>
85
+ </Box>
86
+ </MenuItem>
87
+ </MenuList>
88
+ </Menu>
60
89
  );
61
90
  };
62
-
63
- export const WithCustomListWIP: ComponentStory<typeof Menu> = () => (
64
- <Menu>
65
- <MenuButton as={Button}>Actions</MenuButton>
66
- <MenuList>
67
- <CustomItem />
68
- <MenuItem iconName="AddonsTuorqouise">Create a Copy</MenuItem>
69
- <MenuItem iconName="AddonsTuorqouise">Mark as Draft</MenuItem>
70
- <MenuItem iconName="AddonsTuorqouise">Delete</MenuItem>
71
- <MenuItem iconName="AddonsTuorqouise">Attend a Workshop</MenuItem>
72
- </MenuList>
73
- </Menu>
74
- );
@@ -1,5 +1,13 @@
1
1
  import type { SystemStyleObject } from '@chakra-ui/theme-tools';
2
2
 
3
+ const disabledItem: SystemStyleObject = {
4
+ _disabled: {
5
+ backgroundColor: 'neutral.100',
6
+ color: 'neutral.70',
7
+ cursor: 'not-allowed',
8
+ },
9
+ };
10
+
3
11
  const MenuTheme: SystemStyleObject = {
4
12
  baseStyle: {
5
13
  list: {
@@ -18,10 +26,13 @@ const MenuTheme: SystemStyleObject = {
18
26
  _focus: {
19
27
  backgroundColor: 'neutral.93',
20
28
  boxShadow: 'none',
29
+ ...disabledItem,
21
30
  },
22
31
  _active: {
23
32
  backgroundColor: 'neutral.90',
33
+ ...disabledItem,
24
34
  },
35
+ ...disabledItem,
25
36
  },
26
37
  },
27
38
  };
@@ -3,6 +3,6 @@ import { Menu as ChakraMenu, MenuProps as ChakraMenuProps } from '@chakra-ui/rea
3
3
 
4
4
  export type MenuProps = ChakraMenuProps;
5
5
 
6
- const Menu = (props: MenuProps) => <ChakraMenu {...props} />;
6
+ const Menu = (props: MenuProps) => <ChakraMenu matchWidth {...props} />;
7
7
 
8
8
  export default Menu;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { MenuButton as ChakraMenuButton, MenuButtonProps as ChakraMenuButtonProps, forwardRef } from '@chakra-ui/react';
3
+
4
+ export type MenuButtonProps = ChakraMenuButtonProps;
5
+
6
+ const MenuButton = forwardRef<MenuButtonProps, 'button'>((props, ref) => {
7
+ return <ChakraMenuButton {...props} ref={ref} />;
8
+ });
9
+
10
+ export default MenuButton;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { MenuItem as ChakraMenuItem, MenuItemProps } from '@chakra-ui/react';
2
+ import { MenuItem as ChakraMenuItem, MenuItemProps as ChakraMenuItemProps, forwardRef } from '@chakra-ui/react';
3
3
  import { Icon, TypeIconName } from '@bitrise/bitkit';
4
4
 
5
5
  const dangerStyle = {
@@ -13,22 +13,28 @@ const dangerStyle = {
13
13
  },
14
14
  };
15
15
 
16
- export type Props = {
17
- children: string;
18
- iconName: TypeIconName;
16
+ export interface MenuItemProps extends ChakraMenuItemProps {
17
+ as?: 'a' | 'button';
18
+ iconName?: TypeIconName;
19
19
  isDanger?: boolean;
20
- onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
21
- };
20
+ }
22
21
 
23
- const MenuItem = (props: Props) => {
24
- const { iconName, isDanger, ...rest } = props;
25
- const properties: MenuItemProps = {
26
- ...rest,
27
- icon: <Icon name={iconName} />,
22
+ const MenuItem = forwardRef<MenuItemProps, 'button'>((props, ref) => {
23
+ const { as, iconName, isDanger, isDisabled, ...rest } = props;
24
+ const properties: ChakraMenuItemProps = {
25
+ as: isDisabled ? 'button' : as,
28
26
  iconSpacing: '12',
29
- sx: isDanger ? dangerStyle : undefined,
27
+ isDisabled,
28
+ ...rest,
30
29
  };
31
- return <ChakraMenuItem {...properties} />;
32
- };
30
+ if (iconName) {
31
+ properties.icon = <Icon name={iconName} />;
32
+ }
33
+ // There is no variant for MenuItem
34
+ if (isDanger) {
35
+ properties.sx = dangerStyle;
36
+ }
37
+ return <ChakraMenuItem {...properties} ref={ref} />;
38
+ });
33
39
 
34
40
  export default MenuItem;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { MenuList as ChakraMenuList, MenuListProps as ChakraMenuListProps, forwardRef } from '@chakra-ui/react';
3
+
4
+ export type MenuListProps = ChakraMenuListProps;
5
+
6
+ const MenuList = forwardRef<MenuListProps, 'div'>((props, ref) => {
7
+ return <ChakraMenuList {...props} ref={ref} />;
8
+ });
9
+
10
+ export default MenuList;
@@ -1,5 +1,5 @@
1
- import { Flex } from '@chakra-ui/react';
2
1
  import { ComponentStory, ComponentMeta } from '@storybook/react';
2
+ import Box from '../Box/Box';
3
3
  import OverflowMenu from './OverflowMenu';
4
4
  import OverflowMenuItem from './OverflowMenuItem';
5
5
 
@@ -9,26 +9,21 @@ export default {
9
9
  } as ComponentMeta<typeof OverflowMenu>;
10
10
 
11
11
  export const WithProps: ComponentStory<typeof OverflowMenu> = (props) => (
12
- <Flex direction="column" alignItems="flex-end" minHeight="400px">
12
+ <Box display="flex" flexDirection="column" alignItems="flex-end" minHeight="400px">
13
13
  <OverflowMenu {...props}>
14
14
  <OverflowMenuItem iconName="PlusAdd">Add member</OverflowMenuItem>
15
15
  <OverflowMenuItem iconName="MinusRemove">Remove member</OverflowMenuItem>
16
- <OverflowMenuItem iconName="Filter">Assign access to apps</OverflowMenuItem>
17
- <OverflowMenuItem iconName="Pencil">Rename group</OverflowMenuItem>
18
- <OverflowMenuItem iconName="Trash" isDanger>
19
- Delete group
16
+ <OverflowMenuItem as="a" iconName="Link" href="#">
17
+ As a link
18
+ </OverflowMenuItem>
19
+ <OverflowMenuItem iconName="Pencil" isDisabled>
20
+ Disabled item
20
21
  </OverflowMenuItem>
21
- </OverflowMenu>
22
- <OverflowMenu {...props}>
23
- <OverflowMenuItem iconName="PlusAdd">Add member</OverflowMenuItem>
24
- <OverflowMenuItem iconName="MinusRemove">Remove member</OverflowMenuItem>
25
- <OverflowMenuItem iconName="Filter">Assign access to apps</OverflowMenuItem>
26
- <OverflowMenuItem iconName="Pencil">Rename group</OverflowMenuItem>
27
22
  <OverflowMenuItem iconName="Trash" isDanger>
28
- Delete group
23
+ Danger version
29
24
  </OverflowMenuItem>
30
25
  </OverflowMenu>
31
- </Flex>
26
+ </Box>
32
27
  );
33
28
  WithProps.args = {
34
29
  ...OverflowMenu.defaultProps,
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- import { MenuButton, MenuList, MenuListProps } from '@chakra-ui/react';
3
2
  import IconButton from '../IconButton/IconButton';
4
- import Menu from '../Menu/Menu';
3
+ import Menu, { MenuProps } from '../Menu/Menu';
4
+ import MenuButton from '../Menu/MenuButton';
5
+ import MenuList, { MenuListProps } from '../Menu/MenuList';
5
6
 
6
- export interface OverflowMenuProps {
7
+ export interface OverflowMenuProps extends MenuProps {
7
8
  children: MenuListProps['children'];
8
9
  triggerLabel?: string;
9
10
  }
@@ -11,7 +12,14 @@ export interface OverflowMenuProps {
11
12
  const OverflowMenu = ({ children, triggerLabel }: OverflowMenuProps) => {
12
13
  return (
13
14
  <Menu isLazy>
14
- <MenuButton aria-label={triggerLabel} as={IconButton} iconName="MoreVertical" size="small" variant="tertiary" />
15
+ <MenuButton
16
+ aria-label={triggerLabel}
17
+ as={IconButton}
18
+ iconName="MoreVertical"
19
+ isTooltipDisabled
20
+ size="small"
21
+ variant="tertiary"
22
+ />
15
23
  <MenuList>{children}</MenuList>
16
24
  </Menu>
17
25
  );
@@ -1,12 +1,13 @@
1
1
  import React from 'react';
2
- import MenuItem, { Props as MenuItemProps } from '../Menu/MenuItem';
2
+ import { forwardRef } from '@chakra-ui/react';
3
+ import MenuItem, { MenuItemProps } from '../Menu/MenuItem';
3
4
 
4
5
  export interface OverflowMenuItemProps extends MenuItemProps {
5
6
  children: MenuItemProps['children'];
6
7
  }
7
8
 
8
- const OverflowMenuItem = (props: OverflowMenuItemProps) => {
9
- return <MenuItem {...props} />;
10
- };
9
+ const OverflowMenuItem = forwardRef<OverflowMenuItemProps, 'button'>((props, ref) => {
10
+ return <MenuItem {...props} ref={ref} />;
11
+ });
11
12
 
12
13
  export default OverflowMenuItem;