@toptal/picasso-button 1.0.10-alpha-feature-migrate-buttons-876f8c430.20 → 1.0.10-alpha-FX-5195-fix-button-css-precedence-06be01cc1.19
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/dist-package/src/Button/Button.d.ts +0 -1
- package/dist-package/src/Button/Button.d.ts.map +1 -1
- package/dist-package/src/Button/Button.js +52 -42
- package/dist-package/src/Button/Button.js.map +1 -1
- package/dist-package/src/Button/styles.d.ts +45 -19
- package/dist-package/src/Button/styles.d.ts.map +1 -1
- package/dist-package/src/Button/styles.js +178 -160
- package/dist-package/src/Button/styles.js.map +1 -1
- package/dist-package/src/ButtonAction/ButtonAction.d.ts.map +1 -1
- package/dist-package/src/ButtonAction/ButtonAction.js +28 -20
- package/dist-package/src/ButtonAction/ButtonAction.js.map +1 -1
- package/dist-package/src/ButtonAction/styles.d.ts +3 -11
- package/dist-package/src/ButtonAction/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonAction/styles.js +55 -36
- package/dist-package/src/ButtonAction/styles.js.map +1 -1
- package/dist-package/src/ButtonCircular/ButtonCircular.d.ts.map +1 -1
- package/dist-package/src/ButtonCircular/ButtonCircular.js +26 -12
- package/dist-package/src/ButtonCircular/ButtonCircular.js.map +1 -1
- package/dist-package/src/ButtonCircular/styles.d.ts +3 -15
- package/dist-package/src/ButtonCircular/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonCircular/styles.js +57 -92
- package/dist-package/src/ButtonCircular/styles.js.map +1 -1
- package/dist-package/src/ButtonCompound/index.d.ts +1 -1
- package/dist-package/src/ButtonControlLabel/ButtonControlLabel.js +2 -2
- package/dist-package/src/ButtonControlLabel/ButtonControlLabel.js.map +1 -1
- package/dist-package/src/ButtonControlLabel/styles.d.ts +1 -1
- package/dist-package/src/ButtonGroup/ButtonGroup.d.ts +1 -1
- package/dist-package/src/ButtonGroup/ButtonGroup.d.ts.map +1 -1
- package/dist-package/src/ButtonGroup/ButtonGroup.js +27 -5
- package/dist-package/src/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist-package/src/ButtonGroup/styles.d.ts +2 -1
- package/dist-package/src/ButtonGroup/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonGroup/styles.js +47 -20
- package/dist-package/src/ButtonGroup/styles.js.map +1 -1
- package/dist-package/src/ButtonGroupItem/ButtonGroupItem.d.ts +1 -1
- package/dist-package/src/ButtonGroupItem/ButtonGroupItem.d.ts.map +1 -1
- package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js +12 -17
- package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js.map +1 -1
- package/dist-package/src/ButtonGroupItem/styles.d.ts +3 -13
- package/dist-package/src/ButtonGroupItem/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonGroupItem/styles.js +17 -39
- package/dist-package/src/ButtonGroupItem/styles.js.map +1 -1
- package/dist-package/src/ButtonSplit/ButtonSplit.d.ts.map +1 -1
- package/dist-package/src/ButtonSplit/ButtonSplit.js +24 -28
- package/dist-package/src/ButtonSplit/ButtonSplit.js.map +1 -1
- package/dist-package/src/ButtonSplit/styles.d.ts +3 -9
- package/dist-package/src/ButtonSplit/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonSplit/styles.js +50 -13
- package/dist-package/src/ButtonSplit/styles.js.map +1 -1
- package/package.json +14 -19
- package/src/Button/Button.tsx +106 -73
- package/src/Button/__snapshots__/test.tsx.snap +5 -6
- package/src/Button/styles.ts +221 -213
- package/src/Button/test.tsx +1 -3
- package/src/ButtonAction/ButtonAction.tsx +48 -36
- package/src/ButtonAction/styles.ts +57 -57
- package/src/ButtonCheckbox/__snapshots__/test.tsx.snap +3 -3
- package/src/ButtonCircular/ButtonCircular.tsx +37 -22
- package/src/ButtonCircular/styles.ts +75 -127
- package/src/ButtonControlLabel/ButtonControlLabel.tsx +2 -2
- package/src/ButtonGroup/ButtonGroup.tsx +44 -9
- package/src/ButtonGroup/__snapshots__/test.tsx.snap +7 -7
- package/src/ButtonGroup/styles.ts +63 -21
- package/src/ButtonGroupItem/ButtonGroupItem.tsx +15 -24
- package/src/ButtonGroupItem/styles.ts +28 -62
- package/src/ButtonRadio/__snapshots__/test.tsx.snap +3 -3
- package/src/ButtonSplit/ButtonSplit.tsx +42 -46
- package/src/ButtonSplit/__snapshots__/test.tsx.snap +9 -9
- package/src/ButtonSplit/styles.ts +56 -37
- package/dist-package/src/ButtonBase/ButtonBase.d.ts +0 -29
- package/dist-package/src/ButtonBase/ButtonBase.d.ts.map +0 -1
- package/dist-package/src/ButtonBase/ButtonBase.js +0 -78
- package/dist-package/src/ButtonBase/ButtonBase.js.map +0 -1
- package/dist-package/src/ButtonBase/index.d.ts +0 -5
- package/dist-package/src/ButtonBase/index.d.ts.map +0 -1
- package/dist-package/src/ButtonBase/index.js +0 -2
- package/dist-package/src/ButtonBase/index.js.map +0 -1
- package/dist-package/src/ButtonBase/styles.d.ts +0 -6
- package/dist-package/src/ButtonBase/styles.d.ts.map +0 -1
- package/dist-package/src/ButtonBase/styles.js +0 -29
- package/dist-package/src/ButtonBase/styles.js.map +0 -1
- package/src/ButtonBase/ButtonBase.tsx +0 -182
- package/src/ButtonBase/index.ts +0 -5
- package/src/ButtonBase/styles.ts +0 -36
package/src/Button/Button.tsx
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement, MouseEvent, ElementType } from 'react'
|
|
2
2
|
import React, { forwardRef } from 'react'
|
|
3
3
|
import cx from 'classnames'
|
|
4
|
-
import { twMerge } from 'tailwind-merge'
|
|
5
4
|
import type {
|
|
6
5
|
StandardProps,
|
|
7
6
|
SizeType,
|
|
8
7
|
ButtonOrAnchorProps,
|
|
9
8
|
OverridableComponent,
|
|
10
9
|
TextLabelProps,
|
|
10
|
+
Classes,
|
|
11
11
|
} from '@toptal/picasso-shared'
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import '@toptal/picasso-
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
import { useTitleCase } from '@toptal/picasso-shared'
|
|
13
|
+
import type { Theme } from '@material-ui/core'
|
|
14
|
+
import { makeStyles, ButtonBase } from '@material-ui/core'
|
|
15
|
+
import { Loader } from '@toptal/picasso-loader'
|
|
16
|
+
import { Container } from '@toptal/picasso-container'
|
|
17
|
+
import { noop, toTitleCase } from '@toptal/picasso-utils'
|
|
18
|
+
|
|
19
|
+
import styles from './styles'
|
|
20
|
+
|
|
21
|
+
// Using { index: -50 } to inject CSS link to the bottom of the head
|
|
22
|
+
// in order to prevent Link and Typography styles to override Button's ones
|
|
23
|
+
// More specific button components like ButtonCircular, ButtonSplit, ButtonControlLabel, ButtonAction
|
|
24
|
+
// have even lower indexes, so higher priority
|
|
25
|
+
const useStyles = makeStyles<Theme, Props>(styles, {
|
|
26
|
+
name: 'PicassoButton',
|
|
27
|
+
index: -50,
|
|
28
|
+
})
|
|
24
29
|
|
|
25
30
|
export type VariantType =
|
|
26
31
|
| 'primary'
|
|
@@ -67,28 +72,31 @@ export interface Props
|
|
|
67
72
|
type?: 'button' | 'reset' | 'submit'
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
icon?: ReactElement
|
|
75
|
+
const getClickHandler = (loading?: boolean, handler?: Props['onClick']) =>
|
|
76
|
+
loading ? noop : handler
|
|
77
|
+
|
|
78
|
+
const getIcon = (
|
|
79
|
+
classes: Classes,
|
|
80
|
+
children: ReactNode,
|
|
81
|
+
icon?: ReactElement,
|
|
78
82
|
iconPosition?: IconPositionType
|
|
79
|
-
|
|
80
|
-
}) => {
|
|
83
|
+
) => {
|
|
81
84
|
if (!icon) {
|
|
82
|
-
return
|
|
85
|
+
return null
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const {
|
|
89
|
+
icon: iconClass,
|
|
90
|
+
iconLeft: iconLeftClass,
|
|
91
|
+
iconRight: iconRightClass,
|
|
92
|
+
} = classes
|
|
89
93
|
|
|
90
94
|
return React.cloneElement(icon, {
|
|
91
|
-
className:
|
|
95
|
+
className: cx(iconClass, icon.props.className, {
|
|
96
|
+
[iconLeftClass]: children && iconPosition === 'left',
|
|
97
|
+
[iconRightClass]: children && iconPosition === 'right',
|
|
98
|
+
}),
|
|
99
|
+
key: 'button-icon',
|
|
92
100
|
})
|
|
93
101
|
}
|
|
94
102
|
|
|
@@ -100,7 +108,9 @@ export const Button: OverridableComponent<Props> = forwardRef<
|
|
|
100
108
|
icon,
|
|
101
109
|
iconPosition,
|
|
102
110
|
loading,
|
|
111
|
+
children,
|
|
103
112
|
className,
|
|
113
|
+
style,
|
|
104
114
|
fullWidth,
|
|
105
115
|
variant = 'primary',
|
|
106
116
|
size = 'medium',
|
|
@@ -108,63 +118,86 @@ export const Button: OverridableComponent<Props> = forwardRef<
|
|
|
108
118
|
hovered,
|
|
109
119
|
disabled,
|
|
110
120
|
active,
|
|
121
|
+
onClick,
|
|
122
|
+
title,
|
|
123
|
+
value,
|
|
124
|
+
type,
|
|
125
|
+
as = 'button',
|
|
126
|
+
titleCase: propsTitleCase,
|
|
111
127
|
...rest
|
|
112
128
|
} = props
|
|
129
|
+
const classes = useStyles(props)
|
|
113
130
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
disabled,
|
|
128
|
-
focused,
|
|
129
|
-
hovered,
|
|
130
|
-
active,
|
|
131
|
-
})
|
|
132
|
-
const sizeClassNames = createSizeClassNames(size)
|
|
133
|
-
|
|
134
|
-
const finalClassName = twMerge(
|
|
135
|
-
coreClassNames,
|
|
136
|
-
variantClassNames,
|
|
137
|
-
sizeClassNames,
|
|
138
|
-
fullWidth ? 'w-full' : '',
|
|
139
|
-
className
|
|
140
|
-
)
|
|
131
|
+
const {
|
|
132
|
+
root: rootClass,
|
|
133
|
+
hidden: hiddenClass,
|
|
134
|
+
loader: loaderClass,
|
|
135
|
+
content: contentClass,
|
|
136
|
+
} = classes
|
|
137
|
+
|
|
138
|
+
const titleCase = useTitleCase(propsTitleCase)
|
|
139
|
+
|
|
140
|
+
const finalChildren = [titleCase ? toTitleCase(children) : children]
|
|
141
|
+
|
|
142
|
+
if (icon) {
|
|
143
|
+
const iconComponent = getIcon(classes, children, icon, iconPosition)
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
medium: ['text-button-medium'],
|
|
148
|
-
large: ['text-button-large'],
|
|
145
|
+
if (iconPosition === 'left') {
|
|
146
|
+
finalChildren.unshift(iconComponent)
|
|
147
|
+
} else {
|
|
148
|
+
finalChildren.push(iconComponent)
|
|
149
|
+
}
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
const variantClassName = classes[variant]
|
|
153
|
+
const sizeClassName = classes[size]
|
|
154
|
+
|
|
155
|
+
const rootClassName = cx(
|
|
156
|
+
{
|
|
157
|
+
[classes.fullWidth]: fullWidth,
|
|
158
|
+
[classes.active]: active,
|
|
159
|
+
[classes.focused]: focused,
|
|
160
|
+
[classes.hovered]: hovered,
|
|
161
|
+
[classes.disabled]: disabled,
|
|
162
|
+
},
|
|
163
|
+
sizeClassName,
|
|
164
|
+
variantClassName,
|
|
165
|
+
rootClass
|
|
155
166
|
)
|
|
156
167
|
|
|
157
168
|
return (
|
|
158
169
|
<ButtonBase
|
|
159
170
|
{...rest}
|
|
160
171
|
ref={ref}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
classes={{
|
|
173
|
+
root: rootClassName,
|
|
174
|
+
focusVisible: cx(classes.focusVisible),
|
|
175
|
+
}}
|
|
176
|
+
onClick={getClickHandler(loading, onClick)}
|
|
177
|
+
className={className}
|
|
178
|
+
style={style}
|
|
166
179
|
disabled={disabled}
|
|
167
|
-
|
|
180
|
+
title={title}
|
|
181
|
+
value={value}
|
|
182
|
+
type={type}
|
|
183
|
+
component={as}
|
|
184
|
+
data-component-type='button'
|
|
185
|
+
>
|
|
186
|
+
<Container
|
|
187
|
+
as='span'
|
|
188
|
+
inline
|
|
189
|
+
flex
|
|
190
|
+
direction='row'
|
|
191
|
+
alignItems='center'
|
|
192
|
+
className={cx({ [hiddenClass]: loading }, contentClass)}
|
|
193
|
+
>
|
|
194
|
+
{finalChildren}
|
|
195
|
+
</Container>
|
|
196
|
+
|
|
197
|
+
{loading && (
|
|
198
|
+
<Loader variant='inherit' className={loaderClass} inline size='small' />
|
|
199
|
+
)}
|
|
200
|
+
</ButtonBase>
|
|
168
201
|
)
|
|
169
202
|
})
|
|
170
203
|
|
|
@@ -7,14 +7,13 @@ exports[`Button disabled button as link renders disabled version 1`] = `
|
|
|
7
7
|
>
|
|
8
8
|
<a
|
|
9
9
|
aria-disabled="true"
|
|
10
|
-
class="MuiTypography-root MuiLink-root MuiLink-underlineHover PicassoLink-root
|
|
10
|
+
class="MuiTypography-root MuiLink-root MuiLink-underlineHover PicassoLink-root MuiButtonBase-root PicassoButton-disabled PicassoButton-medium PicassoButton-primary PicassoButton-root Mui-disabled PicassoLink-blue MuiTypography-colorPrimary"
|
|
11
11
|
data-component-type="button"
|
|
12
|
-
|
|
12
|
+
role="button"
|
|
13
13
|
tabindex="-1"
|
|
14
|
-
type="button"
|
|
15
14
|
>
|
|
16
15
|
<span
|
|
17
|
-
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline
|
|
16
|
+
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
|
|
18
17
|
>
|
|
19
18
|
Click me!
|
|
20
19
|
</span>
|
|
@@ -29,14 +28,14 @@ exports[`Button disabled button renders disabled version 1`] = `
|
|
|
29
28
|
class="Picasso-root"
|
|
30
29
|
>
|
|
31
30
|
<button
|
|
32
|
-
class="
|
|
31
|
+
class="MuiButtonBase-root PicassoButton-disabled PicassoButton-medium PicassoButton-primary PicassoButton-root Mui-disabled"
|
|
33
32
|
data-component-type="button"
|
|
34
33
|
disabled=""
|
|
35
34
|
tabindex="-1"
|
|
36
35
|
type="button"
|
|
37
36
|
>
|
|
38
37
|
<span
|
|
39
|
-
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline
|
|
38
|
+
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
|
|
40
39
|
>
|
|
41
40
|
Click me!
|
|
42
41
|
</span>
|