@bitrise/bitkit 9.20.0-alpha-chakra.3 → 9.21.0-alpha-chakra.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": "9.20.0-alpha-chakra.3",
4
+ "version": "9.21.0-alpha-chakra.2",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -21,6 +21,5 @@ WithProps.args = sortObjectByKey({
21
21
  children: 'Button',
22
22
  isDanger: false,
23
23
  isDisabled: false,
24
- isIconOnly: false,
25
24
  isLoading: false,
26
25
  });
@@ -4,9 +4,7 @@ import Icon, { TypeIconName } from '../Icon/Icon';
4
4
 
5
5
  export interface ButtonProps extends ChakraButtonProps {
6
6
  as?: 'a' | 'button';
7
- children: React.ReactChild | React.ReactFragment;
8
7
  isDanger?: boolean;
9
- isIconOnly?: boolean;
10
8
  leftIconName?: TypeIconName;
11
9
  rightIconName?: TypeIconName;
12
10
  size?: 'small' | 'medium';
@@ -17,35 +15,24 @@ export interface ButtonProps extends ChakraButtonProps {
17
15
  * The Button component is used to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation.
18
16
  */
19
17
  const Button = forwardRef<ButtonProps, 'button'>((props, ref) => {
20
- const { as, children, isDanger, isDisabled, isIconOnly, leftIconName, rightIconName, size, variant, ...rest } = props;
18
+ const { as, isDanger, isDisabled, leftIconName, rightIconName, size = 'medium', variant, ...rest } = props;
21
19
  const properties: ChakraButtonProps = {
22
- as,
20
+ as: isDisabled ? 'button' : as,
23
21
  isDisabled,
24
22
  size,
25
23
  variant: isDanger ? `${variant}--danger` : variant,
26
24
  ...rest,
27
25
  };
28
- if (isDisabled) {
29
- properties.as = 'button';
30
- }
26
+ const iconSize = size === 'medium' ? '24' : '16';
31
27
  if (leftIconName) {
32
- properties.leftIcon = <Icon name={leftIconName} size={size === 'medium' ? '24' : '16'} />;
28
+ properties.leftIcon = <Icon name={leftIconName} size={iconSize} />;
33
29
  }
34
30
  if (rightIconName) {
35
- properties.rightIcon = <Icon name={rightIconName} size={size === 'medium' ? '24' : '16'} />;
31
+ properties.rightIcon = <Icon name={rightIconName} size={iconSize} />;
36
32
  }
37
33
  if ((properties.leftIcon || properties.rightIcon) && !properties.iconSpacing) {
38
34
  properties.iconSpacing = size === 'medium' ? '0.625rem' : '0.375rem';
39
35
  }
40
- if (isIconOnly) {
41
- properties['aria-label'] = children.toString();
42
- properties.iconSpacing = 0;
43
- properties.padding = 0;
44
- // TODO: Use Tooltip later for this:
45
- // properties.title = children.toString();
46
- } else {
47
- properties.children = children;
48
- }
49
36
 
50
37
  return <ChakraButton {...properties} ref={ref} />;
51
38
  });
@@ -0,0 +1,26 @@
1
+ import { ComponentStory, ComponentMeta } from '@storybook/react';
2
+ import { sortObjectByKey } from '../../utils/storyUtils';
3
+ import IconButton from './IconButton';
4
+
5
+ export default {
6
+ title: 'Components/IconButton',
7
+ component: IconButton,
8
+ argTypes: {
9
+ as: {
10
+ control: 'inline-radio',
11
+ options: ['a', 'button'],
12
+ },
13
+ },
14
+ } as ComponentMeta<typeof IconButton>;
15
+
16
+ const Template: ComponentStory<typeof IconButton> = (props) => <IconButton {...props} />;
17
+
18
+ export const WithProps = Template.bind({});
19
+ WithProps.args = sortObjectByKey({
20
+ ...IconButton.defaultProps,
21
+ 'aria-label': 'This is the label',
22
+ iconName: 'Bitbot',
23
+ isDanger: false,
24
+ isDisabled: false,
25
+ isLoading: false,
26
+ });
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { IconButton as ChakraIconButton, IconButtonProps as ChakraIconButtonProps, forwardRef } from '@chakra-ui/react';
3
+ import Icon, { TypeIconName } from '../Icon/Icon';
4
+ import Tooltip from '../Tooltip/Tooltip';
5
+
6
+ export interface IconButtonProps extends ChakraIconButtonProps {
7
+ as?: 'a' | 'button';
8
+ iconName: TypeIconName;
9
+ isDanger?: boolean;
10
+ label?: string;
11
+ size?: 'small' | 'medium';
12
+ tooltipCloseDelay?: number;
13
+ variant?: 'primary' | 'secondary' | 'tertiary';
14
+ }
15
+
16
+ /**
17
+ * IconButton composes the `Button` component except that it renders only an icon.
18
+ */
19
+ const IconButton = forwardRef<IconButtonProps, 'button'>((props, ref) => {
20
+ const { as, iconName, isDanger, isDisabled, label, tooltipCloseDelay, variant, ...rest } = props;
21
+ const properties: ChakraIconButtonProps = {
22
+ as: isDisabled ? 'button' : as,
23
+ icon: <Icon name={iconName} />,
24
+ isDisabled,
25
+ variant: isDanger ? `${variant}--danger` : variant,
26
+ ...rest,
27
+ };
28
+ return (
29
+ <Tooltip closeDelay={tooltipCloseDelay} label={label || rest['aria-label']} shouldWrapChildren={isDisabled}>
30
+ <ChakraIconButton {...properties} ref={ref} />
31
+ </Tooltip>
32
+ );
33
+ });
34
+
35
+ IconButton.defaultProps = {
36
+ as: 'button',
37
+ size: 'medium',
38
+ tooltipCloseDelay: 0,
39
+ variant: 'primary',
40
+ } as IconButtonProps;
41
+
42
+ export default IconButton;
@@ -4,7 +4,7 @@ import { Icon, IconProps, forwardRef } from '@chakra-ui/react';
4
4
  const BuildstatusLoadingAnimated = forwardRef<IconProps, 'svg'>((props, ref) => (
5
5
  <Icon ref={ref} viewBox="0 0 16 16" {...props}>
6
6
  <circle cx={8} cy={8} r={7} stroke="currentColor" strokeWidth={1.1} strokeDasharray={48} fill="none">
7
- <animate attributeName="stroke-dashoffset" from={48} to={-48} dur="3.5s" repeatCount="indefinite" />
7
+ <animate attributeName="stroke-dashoffset" from={96} to={0} dur="3.5s" repeatCount="indefinite" />
8
8
  <animateTransform
9
9
  attributeName="transform"
10
10
  type="rotate"
@@ -15,7 +15,7 @@ const BuildstatusLoadingAnimated = forwardRef<IconProps, 'svg'>((props, ref) =>
15
15
  />
16
16
  </circle>
17
17
  <circle cx={8} cy={8} r={4} stroke="currentColor" strokeWidth={1.1} strokeDasharray={48} fill="none">
18
- <animate attributeName="stroke-dashoffset" from={48} to={-48} dur="3.5s" repeatCount="indefinite" />
18
+ <animate attributeName="stroke-dashoffset" from={96} to={0} dur="3.5s" repeatCount="indefinite" />
19
19
  <animateTransform
20
20
  attributeName="transform"
21
21
  type="rotate"
@@ -4,7 +4,7 @@ import { Icon, IconProps, forwardRef } from '@chakra-ui/react';
4
4
  const BuildstatusLoadingAnimated = forwardRef<IconProps, 'svg'>((props, ref) => (
5
5
  <Icon ref={ref} viewBox="0 0 24 24" {...props}>
6
6
  <circle cx={12} cy={12} r={11} stroke="currentColor" strokeWidth={2} strokeDasharray={48} fill="none">
7
- <animate attributeName="stroke-dashoffset" from={48} to={-48} dur="3.5s" repeatCount="indefinite" />
7
+ <animate attributeName="stroke-dashoffset" from={96} to={0} dur="3.5s" repeatCount="indefinite" />
8
8
  <animateTransform
9
9
  attributeName="transform"
10
10
  type="rotate"
@@ -15,7 +15,7 @@ const BuildstatusLoadingAnimated = forwardRef<IconProps, 'svg'>((props, ref) =>
15
15
  />
16
16
  </circle>
17
17
  <circle cx={12} cy={12} r={6} stroke="currentColor" strokeWidth={2} strokeDasharray={48} fill="none">
18
- <animate attributeName="stroke-dashoffset" from={48} to={-48} dur="3.5s" repeatCount="indefinite" />
18
+ <animate attributeName="stroke-dashoffset" from={96} to={0} dur="3.5s" repeatCount="indefinite" />
19
19
  <animateTransform
20
20
  attributeName="transform"
21
21
  type="rotate"
@@ -1,6 +1,7 @@
1
1
  import { ComponentStory, ComponentMeta } from '@storybook/react';
2
2
  import { Box, ButtonGroup, HStack, MenuButton, MenuList, useMenuItem, useStyleConfig } from '@chakra-ui/react';
3
3
  import Button from '../Button/Button';
4
+ import IconButton from '../IconButton/IconButton';
4
5
  import Menu from './Menu';
5
6
  import MenuItem from './MenuItem';
6
7
 
@@ -29,9 +30,7 @@ export const WithButton: ComponentStory<typeof Menu> = () => (
29
30
 
30
31
  export const WithIconButton: ComponentStory<typeof Menu> = () => (
31
32
  <Menu>
32
- <MenuButton as={Button} isIconOnly leftIconName="AddonsTuorqouise">
33
- Open menu
34
- </MenuButton>
33
+ <MenuButton as={IconButton} iconName="AddOnsColorTuorqouise" aria-label="Open menu" />
35
34
  <List />
36
35
  </Menu>
37
36
  );
@@ -41,9 +40,7 @@ export const WithButtonGroup: ComponentStory<typeof Menu> = () => (
41
40
  <ButtonGroup isAttached>
42
41
  <Button>Button</Button>
43
42
  <Menu>
44
- <MenuButton as={Button} isIconOnly leftIconName="AddonsTuorqouise">
45
- Open menu
46
- </MenuButton>
43
+ <MenuButton as={IconButton} iconName="AddOnsColorTuorqouise" aria-label="Open menu" />
47
44
  <List />
48
45
  </Menu>
49
46
  </ButtonGroup>
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { MenuButton, MenuList, MenuListProps } from '@chakra-ui/react';
3
- import Button from '../Button/Button';
3
+ import IconButton from '../IconButton/IconButton';
4
4
  import Menu from '../Menu/Menu';
5
5
 
6
6
  export interface OverflowMenuProps {
@@ -11,9 +11,7 @@ export interface OverflowMenuProps {
11
11
  const OverflowMenu = ({ children, triggerLabel }: OverflowMenuProps) => {
12
12
  return (
13
13
  <Menu isLazy>
14
- <MenuButton as={Button} leftIconName="MoreVertical" isIconOnly size="small" variant="tertiary">
15
- {triggerLabel}
16
- </MenuButton>
14
+ <MenuButton aria-label={triggerLabel} as={IconButton} iconName="MoreVertical" size="small" variant="tertiary" />
17
15
  <MenuList>{children}</MenuList>
18
16
  </Menu>
19
17
  );
@@ -0,0 +1,16 @@
1
+ import type { SystemStyleObject } from '@chakra-ui/theme-tools';
2
+
3
+ const TooltipTheme: SystemStyleObject = {
4
+ baseStyle: {
5
+ bg: 'neutral.10',
6
+ color: 'neutral.95',
7
+ fontSize: '2',
8
+ lineHeight: '2',
9
+ paddingX: '12',
10
+ paddingY: '8',
11
+ borderRadius: '8',
12
+ boxShadow: 'tooltip',
13
+ },
14
+ };
15
+
16
+ export default TooltipTheme;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { Tooltip as ChakraTooltip, TooltipProps as ChakraTooltipProps, forwardRef, chakra } from '@chakra-ui/react';
3
+
4
+ export interface TooltipProps extends ChakraTooltipProps {
5
+ shouldWrapChildren?: boolean;
6
+ }
7
+ /**
8
+ * A tooltip is a brief, informative message that appears when a user interacts with an element. Tooltips are usually initiated in one of two ways: through a mouse-hover gesture or through a keyboard-hover gesture.
9
+ */
10
+ const Tooltip = forwardRef<TooltipProps, 'div'>((props, ref) => {
11
+ const { children, shouldWrapChildren, ...rest } = props;
12
+ const properties: ChakraTooltipProps = {
13
+ bg: 'neutral.10',
14
+ children,
15
+ hasArrow: true,
16
+ ...rest,
17
+ };
18
+ if (shouldWrapChildren) {
19
+ properties.children = (
20
+ <chakra.span display="inline-block" tabIndex={0}>
21
+ {children}
22
+ </chakra.span>
23
+ );
24
+ }
25
+ return <ChakraTooltip {...properties} ref={ref} />;
26
+ });
27
+
28
+ export default Tooltip;
@@ -4,6 +4,7 @@ const shadows = {
4
4
  large: '0 0.125rem 1.5rem 0 rgba(0, 0, 0, 0.08)',
5
5
  inner: '0 0.125rem 0.1875rem 0 rgba(0, 0, 0, 0.1) inset',
6
6
  outline: '0 0 0 3px #C289E6',
7
+ tooltip: '0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.2)',
7
8
  none: 'none',
8
9
  };
9
10
 
@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
  const SvgIconsBuildstatusLoadingAnimated = (props: React.SVGProps<SVGSVGElement>) => (
5
5
  <svg {...props} fill="none" viewBox="0 0 24 24">
6
6
  <circle cx={12} cy={12} r={11} stroke="currentColor" strokeWidth={2} strokeDasharray={48}>
7
- <animate attributeName="stroke-dashoffset" from={48} to={-48} dur="3.5s" repeatCount="indefinite" />
7
+ <animate attributeName="stroke-dashoffset" from={96} to={0} dur="3.5s" repeatCount="indefinite" />
8
8
  <animateTransform
9
9
  attributeName="transform"
10
10
  type="rotate"
@@ -15,7 +15,7 @@ const SvgIconsBuildstatusLoadingAnimated = (props: React.SVGProps<SVGSVGElement>
15
15
  />
16
16
  </circle>
17
17
  <circle cx={12} cy={12} r={6} stroke="currentColor" strokeWidth={2} strokeDasharray={48}>
18
- <animate attributeName="stroke-dashoffset" from={48} to={-48} dur="3.5s" repeatCount="indefinite" />
18
+ <animate attributeName="stroke-dashoffset" from={96} to={0} dur="3.5s" repeatCount="indefinite" />
19
19
  <animateTransform
20
20
  attributeName="transform"
21
21
  type="rotate"
package/src/index.ts CHANGED
@@ -59,3 +59,6 @@ export { default as TabPanel } from './Components/Tabs/TabPanel';
59
59
 
60
60
  export type { BadgeProps } from './Components/Badge/Badge';
61
61
  export { default as Badge } from './Components/Badge/Badge';
62
+
63
+ export type { IconButtonProps } from './Components/IconButton/IconButton';
64
+ export { default as IconButton } from './Components/IconButton/IconButton';
package/src/theme.ts CHANGED
@@ -7,6 +7,7 @@ import Link from './Components/Link/Link.theme';
7
7
  import Menu from './Components/Menu/Menu.theme';
8
8
  import Tabs from './Components/Tabs/Tabs.theme';
9
9
  import Text from './Components/Text/Text.theme';
10
+ import Tooltip from './Components/Tooltip/Tooltip.theme';
10
11
 
11
12
  import colors from './Foundations/Colors/Colors';
12
13
  import radii from './Foundations/Radii/Radii';
@@ -57,6 +58,7 @@ const theme = {
57
58
  Menu,
58
59
  Tabs,
59
60
  Text,
61
+ Tooltip,
60
62
  },
61
63
  };
62
64