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