@popsure/dirty-swan 0.41.18 → 0.42.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.
@@ -1,10 +1,14 @@
1
- import { ReactNode } from 'react';
1
+ import { ElementType, ReactNode } from 'react';
2
2
  import classNamesUtil from 'classnames';
3
3
  import { ChevronRightIcon } from '../icon';
4
4
 
5
5
  import styles from './style.module.scss';
6
6
 
7
- export interface CardProps {
7
+ const CardDefault = 'section' as const
8
+ type CardDefaultAsType = typeof CardDefault;
9
+
10
+ type CardOwnProps<E extends ElementType = CardDefaultAsType> = {
11
+ as?: E;
8
12
  children?: ReactNode;
9
13
  classNames?: {
10
14
  buttonWrapper?: string;
@@ -29,7 +33,11 @@ export interface CardProps {
29
33
  showActionIcon?: boolean;
30
34
  }
31
35
 
32
- const CardContent = ({
36
+ export type CardProps<E extends ElementType = CardDefaultAsType> = CardOwnProps<E> &
37
+ Omit<React.ComponentProps<E>, keyof CardOwnProps<E>>
38
+
39
+ const Card = <E extends ElementType = CardDefaultAsType>({
40
+ as,
33
41
  children,
34
42
  classNames,
35
43
  density = 'balanced',
@@ -42,113 +50,111 @@ const CardContent = ({
42
50
  actionIcon,
43
51
  title,
44
52
  titleVariant = 'large',
45
- showActionIcon
46
- }: CardProps) => {
53
+ showActionIcon,
54
+ ...rest
55
+ }: CardProps<E>) => {
47
56
  const hideActionIcon = typeof actionIcon !== 'undefined' && !actionIcon;
48
-
57
+ const propsWithActionIcon = onClick || rest?.href || rest.to;
58
+ const cardDefaultTag = onClick ? 'button' : CardDefault;
59
+ const Tag = as || cardDefaultTag;
60
+
49
61
  return (
50
- <section
62
+ <Tag
51
63
  className={classNamesUtil(
52
- 'd-flex fd-column jc-center br8 bg-white w100 ta-left',
53
- { 'bs-sm': dropShadow },
64
+ classNames?.buttonWrapper,
65
+ ' d-flex w100 br8 ai-stretch',
54
66
  {
55
- compact: 'p16',
56
- balanced: 'p24',
57
- spacious: 'p32',
58
- }[density],
59
- classNames?.wrapper
67
+ 'c-pointer': propsWithActionIcon,
68
+ [styles.button]: propsWithActionIcon
69
+ },
60
70
  )}
71
+ {...onClick && {
72
+ onClick,
73
+ type: "button"
74
+ }}
75
+ {...rest}
61
76
  >
62
- <div className="d-flex w100">
63
- {icon && (
64
- <div
65
- className={classNamesUtil(
66
- `d-flex ai-center tc-primary-500`,
67
- styles.icon,
68
- styles[`icon${density}`],
69
- classNames?.icon
70
- )}
71
- >
72
- {icon}
73
- </div>
77
+ <div
78
+ className={classNamesUtil(
79
+ 'd-flex fd-column jc-center br8 bg-white w100 ta-left',
80
+ { 'bs-sm': dropShadow },
81
+ {
82
+ compact: 'p16',
83
+ balanced: 'p24',
84
+ spacious: 'p32',
85
+ }[density],
86
+ classNames?.wrapper
74
87
  )}
88
+ >
89
+ <div className="d-flex w100">
90
+ {icon && (
91
+ <div
92
+ className={classNamesUtil(
93
+ `d-flex ai-center tc-primary-500`,
94
+ styles.icon,
95
+ styles[`icon${density}`],
96
+ classNames?.icon
97
+ )}
98
+ >
99
+ {icon}
100
+ </div>
101
+ )}
75
102
 
76
- <div className="d-flex jc-between w100">
77
- <div className="d-flex jc-center gap8 fd-column tc-grey-900 w100">
78
- {label && (
79
- <h3 className={classNamesUtil('p-p--small', classNames?.label)}>
80
- {label}
81
- </h3>
82
- )}
103
+ <div className="d-flex jc-between w100">
104
+ <div className="d-flex jc-center gap8 fd-column tc-grey-900 w100">
105
+ {label && (
106
+ <h3 className={classNamesUtil('p-p--small', classNames?.label)}>
107
+ {label}
108
+ </h3>
109
+ )}
83
110
 
84
- {title && (
85
- <h2
86
- className={classNamesUtil(
87
- classNames?.title,
88
- {
89
- large: 'p-h3',
90
- medium: 'p-h4',
91
- small: 'p-p',
92
- }[titleVariant]
93
- )}
94
- >
95
- {title}
96
- </h2>
97
- )}
111
+ {title && (
112
+ <h2
113
+ className={classNamesUtil(
114
+ classNames?.title,
115
+ {
116
+ large: 'p-h3',
117
+ medium: 'p-h4',
118
+ small: 'p-p',
119
+ }[titleVariant]
120
+ )}
121
+ >
122
+ {title}
123
+ </h2>
124
+ )}
98
125
 
99
- {description && (
126
+ {description && (
127
+ <div
128
+ className={classNamesUtil(
129
+ 'tc-grey-600',
130
+ classNames?.description,
131
+ descriptionVariant === 'small' ? 'p-p--small' : 'p-p'
132
+ )}
133
+ >
134
+ {description}
135
+ </div>
136
+ )}
137
+ </div>
138
+
139
+ {(showActionIcon || (propsWithActionIcon && !hideActionIcon)) && (
100
140
  <div
101
141
  className={classNamesUtil(
102
- 'tc-grey-600',
103
- classNames?.description,
104
- descriptionVariant === 'small' ? 'p-p--small' : 'p-p'
142
+ styles.actionIcon,
143
+ classNames?.actionIcon,
144
+ styles[`actionIcon${density}`],
145
+ 'd-flex ai-center'
105
146
  )}
106
147
  >
107
- {description}
148
+ {actionIcon || <ChevronRightIcon size={24} />}
108
149
  </div>
109
150
  )}
110
151
  </div>
111
-
112
- {(showActionIcon || (onClick && !hideActionIcon)) && (
113
- <div
114
- className={classNamesUtil(
115
- styles.actionIcon,
116
- classNames?.actionIcon,
117
- styles[`actionIcon${density}`],
118
- 'd-flex ai-center'
119
- )}
120
- >
121
- {actionIcon || <ChevronRightIcon size={24} />}
122
- </div>
123
- )}
124
152
  </div>
125
- </div>
126
153
 
127
- {children && <div className={classNames?.children}>{children}</div>}
128
- </section>
154
+ {children && <div className={classNames?.children}>{children}</div>}
155
+ </div>
156
+ </Tag>
129
157
  );
130
158
  };
131
159
 
132
- const Card = (props: CardProps) => {
133
- const { onClick } = props;
134
-
135
- if (onClick) {
136
- return (
137
- <button
138
- className={classNamesUtil(
139
- 'c-pointer d-flex w100 br8 ai-stretch',
140
- styles.button,
141
- props.classNames?.buttonWrapper
142
- )}
143
- onClick={onClick}
144
- type="button"
145
- >
146
- <CardContent {...props} />
147
- </button>
148
- );
149
- }
150
-
151
- return <CardContent {...props} />;
152
- };
153
-
154
160
  export { Card };
@@ -5,6 +5,7 @@
5
5
  color: $ds-grey-900;
6
6
  outline: 1px solid transparent;
7
7
  transition: all 0.2s ease-in-out;
8
+ text-decoration: none;
8
9
 
9
10
  &:hover {
10
11
  outline: 1px solid $ds-primary-500;