@popsure/dirty-swan 0.44.1 → 0.45.0-alpha

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.
@@ -1,5 +1,5 @@
1
1
  import classNames from 'classnames';
2
- import React, { ReactElement, ReactNode } from 'react';
2
+ import React, { ReactElement, ElementType, ComponentProps, ReactNode } from 'react';
3
3
 
4
4
  type ButtonVariant =
5
5
  | 'filledColor'
@@ -22,7 +22,11 @@ const buttonTypeClassNameMap: { [K in ButtonVariant]: string } = {
22
22
  filledError: 'p-btn--danger',
23
23
  };
24
24
 
25
- type ButtonProps = {
25
+ const buttonDefaultAs = 'button' as const
26
+ type ButtonDefaultAsType = typeof buttonDefaultAs;
27
+
28
+ type ButtonOwnProps<E> = {
29
+ as?: E;
26
30
  children: ReactNode;
27
31
  variant?: ButtonVariant;
28
32
  leftIcon?: ReactElement;
@@ -31,8 +35,12 @@ type ButtonProps = {
31
35
  hideLabel?: boolean;
32
36
  } & Omit<JSX.IntrinsicElements['button'], 'children'>;
33
37
 
34
- const Button = React.forwardRef((
38
+ export type ButtonProps<E extends ElementType = ButtonDefaultAsType> = ButtonOwnProps<E> &
39
+ Omit<ComponentProps<E>, keyof ButtonOwnProps<E>>;
40
+
41
+ const Button = React.forwardRef(<E extends ElementType = ButtonDefaultAsType>(
35
42
  {
43
+ as,
36
44
  className,
37
45
  loading = false,
38
46
  children,
@@ -41,10 +49,13 @@ const Button = React.forwardRef((
41
49
  rightIcon,
42
50
  hideLabel,
43
51
  ...props
44
- }: ButtonProps,
45
- ref?: React.ForwardedRef<HTMLButtonElement>
46
- ) => (
47
- <button
52
+ }: ButtonProps<E>,
53
+ ref?: React.ForwardedRef<E>
54
+ ) => {
55
+ const ButtonTag = as || 'button';
56
+
57
+ return (
58
+ <ButtonTag
48
59
  ref={ref}
49
60
  className={classNames(
50
61
  buttonTypeClassNameMap[variant],
@@ -92,9 +103,9 @@ const Button = React.forwardRef((
92
103
  )}
93
104
  </div>
94
105
  ) : children}
95
- </button>
106
+ </ButtonTag>
96
107
  )
97
- );
108
+ });
98
109
 
99
110
  export { Button };
100
- export type { ButtonProps, ButtonVariant };
111
+ export type { ButtonVariant };
@@ -36,7 +36,7 @@ type CardOwnProps<E extends ElementType = CardDefaultAsType> = {
36
36
  }
37
37
 
38
38
  export type CardProps<E extends ElementType = CardDefaultAsType> = CardOwnProps<E> &
39
- Omit<ComponentProps<E>, keyof CardOwnProps<E>>
39
+ Omit<ComponentProps<E>, keyof CardOwnProps<E>>;
40
40
 
41
41
  const Card = <E extends ElementType = CardDefaultAsType>({
42
42
  as,