@bitrise/bitkit 9.10.0 → 9.11.0

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.10.0",
4
+ "version": "9.11.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -15,7 +15,4 @@ WithProps.args = sortObjectByKey({
15
15
  children: 'Button',
16
16
  isDanger: false,
17
17
  isDisabled: false,
18
- href: '#',
19
- target: '_self',
20
- type: 'button',
21
18
  });
@@ -1,34 +1,23 @@
1
- import React, { forwardRef, HTMLAttributeAnchorTarget } from 'react';
1
+ import React, { HTMLAttributeAnchorTarget } from 'react';
2
2
  import { Button as ChakraButton, ButtonProps as ChackraButtonProps } from '@chakra-ui/react';
3
3
  import Icon from '../../Old/Icon/Icon';
4
4
  import { TypeIconName } from '../../Old/Icon/tsx';
5
5
 
6
- export interface LinkProps extends ChackraButtonProps {
7
- as: 'a';
8
- target?: HTMLAttributeAnchorTarget;
9
- }
10
-
11
6
  export interface ButtonProps extends ChackraButtonProps {
12
- as?: 'button';
13
- }
14
-
15
- export type Props = {
16
- children: string;
17
- className?: string;
7
+ as?: 'a' | 'button';
8
+ href?: string;
18
9
  isDanger?: boolean;
19
- isDisabled?: boolean;
20
10
  leftIconName?: TypeIconName;
21
- onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
22
- ref?: ChackraButtonProps['itemRef'];
23
11
  rightIconName?: TypeIconName;
24
12
  size?: 'small' | 'medium';
13
+ target?: HTMLAttributeAnchorTarget;
25
14
  variant?: 'primary' | 'secondary' | 'tertiary';
26
- } & (LinkProps | ButtonProps);
15
+ }
27
16
 
28
17
  /**
29
18
  * 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.
30
19
  */
31
- const Button = forwardRef<HTMLButtonElement, Props>((props: Props, ref) => {
20
+ const Button = (props: ButtonProps) => {
32
21
  const { as, isDanger, leftIconName, rightIconName, size, variant, ...rest } = props;
33
22
  const properties: ChackraButtonProps = {
34
23
  as,
@@ -42,18 +31,17 @@ const Button = forwardRef<HTMLButtonElement, Props>((props: Props, ref) => {
42
31
  if (rightIconName) {
43
32
  properties.rightIcon = <Icon name={rightIconName} />;
44
33
  }
45
- if (leftIconName || rightIconName) {
34
+ if ((properties.leftIcon || properties.rightIcon) && !properties.iconSpacing) {
46
35
  properties.iconSpacing = size === 'medium' ? '0.625rem' : '0.375rem';
47
36
  }
48
37
 
49
- return <ChakraButton ref={ref} {...properties} />;
50
- });
38
+ return <ChakraButton {...properties} />;
39
+ };
51
40
 
52
41
  Button.defaultProps = {
53
- // eslint-disable-next-line react/default-props-match-prop-types
54
42
  as: 'button',
55
43
  size: 'medium',
56
44
  variant: 'primary',
57
- };
45
+ } as ButtonProps;
58
46
 
59
47
  export default Button;
@@ -1,3 +1,4 @@
1
+ /* eslint-disable jsx-a11y/anchor-is-valid */
1
2
  import { ComponentStory, ComponentMeta } from '@storybook/react';
2
3
  import { sortObjectByKey } from '../../utils/storyUtils';
3
4
  import Text from '../Text/Text';
@@ -12,13 +13,12 @@ const args = sortObjectByKey({
12
13
  ...Link.defaultProps,
13
14
  children: 'The quick brown fox jumps over the lazy dog.',
14
15
  href: '#',
15
- target: '_self',
16
16
  });
17
17
 
18
- export const WithProps: ComponentStory<typeof Link> = ({ ...props }) => <Link {...props} />;
18
+ export const WithProps: ComponentStory<typeof Link> = (props) => <Link {...props} />;
19
19
  WithProps.args = args;
20
20
 
21
- export const InsideText: ComponentStory<typeof Link> = ({ ...props }) => (
21
+ export const InsideText: ComponentStory<typeof Link> = (props) => (
22
22
  <Text size="2">
23
23
  This is a text with link: <Link {...props} />
24
24
  <br />
@@ -1,28 +1,31 @@
1
- import React, { HTMLAttributeAnchorTarget } from 'react';
1
+ import React from 'react';
2
2
  import { Link as ChakraLink, LinkProps as ChakraLinkProps } from '@chakra-ui/react';
3
3
  import { TextSizes } from '../../Foundations/Typography/Typography';
4
4
 
5
5
  export interface LinkProps extends ChakraLinkProps {
6
+ as?: 'a' | 'button';
6
7
  colorScheme?: 'purple' | 'white' | 'gray';
7
8
  isUnderlined?: boolean;
8
9
  size?: TextSizes;
9
- target?: HTMLAttributeAnchorTarget;
10
10
  }
11
11
 
12
12
  /**
13
- * Links are accessible elements used primarily for navigation. This component is styled to resemble a hyperlink and semantically renders an `<a>`
13
+ * Links are accessible elements used primarily for navigation.
14
14
  */
15
15
  const Link = (props: LinkProps) => {
16
- const { isUnderlined, ...rest } = props;
17
- const properties: ChakraLinkProps = { ...rest };
18
- properties.as = 'a';
16
+ const { as, isUnderlined, ...rest } = props;
17
+ const properties: ChakraLinkProps = { as, ...rest };
19
18
  if (isUnderlined) {
20
19
  properties.textDecoration = 'underline';
21
20
  }
21
+ if (as === 'button') {
22
+ properties.type = 'button';
23
+ }
22
24
  return <ChakraLink {...properties} />;
23
25
  };
24
26
 
25
27
  Link.defaultProps = {
28
+ as: 'a',
26
29
  isUnderlined: false,
27
30
  } as LinkProps;
28
31