@toptal/picasso-button 1.0.13-alpha-fx-5263-merge-feature-branch-d124b1f9a.10 → 1.0.13-alpha-fx-4593-migrate-tag-4f7c872c8.4
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.map +1 -1
- package/dist-package/src/Button/Button.js +47 -39
- 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 -161
- 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.d.ts.map +1 -1
- package/dist-package/src/ButtonControlLabel/ButtonControlLabel.js +13 -4
- package/dist-package/src/ButtonControlLabel/ButtonControlLabel.js.map +1 -1
- package/dist-package/src/ButtonControlLabel/styles.d.ts +2 -2
- package/dist-package/src/ButtonControlLabel/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonControlLabel/styles.js +25 -16
- package/dist-package/src/ButtonControlLabel/styles.js.map +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 +15 -19
- package/src/Button/Button.tsx +100 -69
- package/src/Button/__snapshots__/test.tsx.snap +4 -8
- package/src/Button/styles.ts +221 -214
- 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 -4
- package/src/ButtonCircular/ButtonCircular.tsx +37 -22
- package/src/ButtonCircular/styles.ts +75 -127
- package/src/ButtonControlLabel/ButtonControlLabel.tsx +16 -7
- package/src/ButtonControlLabel/styles.ts +26 -30
- package/src/ButtonGroup/ButtonGroup.tsx +44 -9
- package/src/ButtonGroup/__snapshots__/test.tsx.snap +7 -13
- 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 -4
- package/src/ButtonSplit/ButtonSplit.tsx +42 -46
- package/src/ButtonSplit/__snapshots__/test.tsx.snap +9 -13
- 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/__snapshots__/test.tsx.snap +0 -262
- package/src/ButtonBase/index.ts +0 -5
- package/src/ButtonBase/styles.ts +0 -36
- package/src/ButtonBase/test.tsx +0 -212
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Theme } from '@material-ui/core/styles'
|
|
2
|
+
import { createStyles } from '@material-ui/core/styles'
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
4
|
+
export default ({ palette, typography }: Theme) =>
|
|
5
|
+
createStyles({
|
|
6
|
+
root: {
|
|
7
|
+
border: 'none',
|
|
8
|
+
minWidth: 'unset',
|
|
9
|
+
paddingLeft: '0',
|
|
10
|
+
paddingRight: '0',
|
|
11
|
+
backgroundColor: 'transparent',
|
|
12
|
+
'&:active, &$active, &:hover, &$hovered': {
|
|
13
|
+
backgroundColor: 'transparent',
|
|
14
|
+
color: palette.blue.main,
|
|
15
|
+
textDecoration: 'underline',
|
|
16
|
+
},
|
|
17
|
+
'&$loading': {
|
|
18
|
+
textDecoration: 'none',
|
|
19
|
+
cursor: 'default',
|
|
20
|
+
},
|
|
21
|
+
'&$disabled': {
|
|
22
|
+
backgroundColor: 'transparent',
|
|
23
|
+
opacity: 0.48,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
content: {
|
|
27
|
+
fontWeight: typography.fontWeights.semibold,
|
|
28
|
+
color: palette.blue.main,
|
|
29
|
+
},
|
|
30
|
+
small: {
|
|
31
|
+
'& $content': {
|
|
32
|
+
fontSize: '0.875rem',
|
|
33
|
+
lineHeight: '1.375rem',
|
|
34
|
+
},
|
|
35
|
+
'& $iconLeft': {
|
|
36
|
+
marginLeft: 0,
|
|
37
|
+
},
|
|
38
|
+
'& $iconRight': {
|
|
39
|
+
marginRight: 0,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
icon: {
|
|
43
|
+
width: '1rem',
|
|
44
|
+
height: '1rem',
|
|
45
|
+
color: palette.grey.dark,
|
|
46
|
+
},
|
|
47
|
+
iconLeft: {
|
|
48
|
+
marginRight: '0.5rem',
|
|
49
|
+
},
|
|
50
|
+
iconRight: {
|
|
51
|
+
marginLeft: '0.5rem',
|
|
52
|
+
},
|
|
53
|
+
active: {},
|
|
54
|
+
disabled: {},
|
|
55
|
+
hovered: {},
|
|
56
|
+
focused: {},
|
|
57
|
+
loading: {},
|
|
58
|
+
})
|
|
@@ -7,14 +7,13 @@ exports[`ButtonCheckbox renders 1`] = `
|
|
|
7
7
|
>
|
|
8
8
|
<label
|
|
9
9
|
aria-disabled="false"
|
|
10
|
-
class="
|
|
10
|
+
class="MuiButtonBase-root PicassoButton-medium PicassoButton-secondary PicassoButton-root PicassoButtonControlLabel-root PicassoButtonControlLabel-medium"
|
|
11
11
|
data-component-type="button"
|
|
12
12
|
role="button"
|
|
13
13
|
tabindex="0"
|
|
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
|
<span
|
|
20
19
|
class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
|
|
@@ -39,7 +38,7 @@ exports[`ButtonCheckbox renders 1`] = `
|
|
|
39
38
|
</span>
|
|
40
39
|
</span>
|
|
41
40
|
<div
|
|
42
|
-
class="
|
|
41
|
+
class="PicassoButtonControlLabel-content"
|
|
43
42
|
style="margin-left: 0.5rem;"
|
|
44
43
|
>
|
|
45
44
|
Click me!
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { ReactElement, MouseEvent, ElementType } from 'react'
|
|
2
2
|
import React, { forwardRef } from 'react'
|
|
3
3
|
import cx from 'classnames'
|
|
4
|
+
import type { Theme } from '@material-ui/core/styles'
|
|
5
|
+
import { makeStyles } from '@material-ui/core/styles'
|
|
4
6
|
import type {
|
|
5
7
|
BaseProps,
|
|
6
8
|
ButtonOrAnchorProps,
|
|
7
9
|
OverridableComponent,
|
|
8
10
|
} from '@toptal/picasso-shared'
|
|
11
|
+
import { kebabToCamelCase } from '@toptal/picasso-utils'
|
|
9
12
|
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
13
|
+
import { Button } from '../Button'
|
|
14
|
+
import styles from './styles'
|
|
12
15
|
|
|
13
16
|
export type VariantType = 'primary' | 'flat' | 'transparent'
|
|
14
17
|
|
|
@@ -37,6 +40,14 @@ export interface Props extends BaseProps, ButtonOrAnchorProps {
|
|
|
37
40
|
responsive?: boolean
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
// Using { index: -1 } to inject CSS link to the bottom of the head
|
|
44
|
+
// in order to prevent Button's styles to override ButtonCircular's ones
|
|
45
|
+
// Related Jira issue: https://toptal-core.atlassian.net/browse/FX-1520
|
|
46
|
+
const useStyles = makeStyles<Theme>(styles, {
|
|
47
|
+
name: 'PicassoButtonCircular',
|
|
48
|
+
index: -1,
|
|
49
|
+
})
|
|
50
|
+
|
|
40
51
|
export const ButtonCircular: OverridableComponent<Props> = forwardRef<
|
|
41
52
|
HTMLButtonElement,
|
|
42
53
|
Props
|
|
@@ -49,35 +60,39 @@ export const ButtonCircular: OverridableComponent<Props> = forwardRef<
|
|
|
49
60
|
hovered,
|
|
50
61
|
disabled,
|
|
51
62
|
responsive,
|
|
52
|
-
loading,
|
|
53
63
|
...rest
|
|
54
64
|
} = props
|
|
55
|
-
const
|
|
56
|
-
disabled,
|
|
57
|
-
focused,
|
|
58
|
-
hovered,
|
|
59
|
-
active,
|
|
60
|
-
})
|
|
65
|
+
const classes = useStyles()
|
|
61
66
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
className
|
|
66
|
-
)
|
|
67
|
+
const { root: rootClass, focusVisible: focusVisibleClass } = classes
|
|
68
|
+
|
|
69
|
+
const variantClassName = classes[kebabToCamelCase(variant)]
|
|
67
70
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const rootClassName = cx(
|
|
72
|
+
{
|
|
73
|
+
[classes.active]: active,
|
|
74
|
+
[classes.focused]: focused,
|
|
75
|
+
[classes.hovered]: hovered,
|
|
76
|
+
[classes.disabled]: disabled,
|
|
77
|
+
[classes.responsive]: responsive,
|
|
78
|
+
},
|
|
79
|
+
variantClassName,
|
|
80
|
+
rootClass
|
|
72
81
|
)
|
|
73
82
|
|
|
74
83
|
return (
|
|
75
|
-
<
|
|
84
|
+
<Button
|
|
76
85
|
{...rest}
|
|
77
86
|
ref={ref}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
classes={{
|
|
88
|
+
root: rootClassName,
|
|
89
|
+
focusVisible: focusVisibleClass,
|
|
90
|
+
}}
|
|
91
|
+
className={className}
|
|
92
|
+
size='small'
|
|
93
|
+
active={active}
|
|
94
|
+
hovered={hovered}
|
|
95
|
+
focused={focused}
|
|
81
96
|
disabled={disabled}
|
|
82
97
|
/>
|
|
83
98
|
)
|
|
@@ -1,127 +1,75 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} else {
|
|
77
|
-
variantClassNames.push('hover:bg-gray-200')
|
|
78
|
-
variantClassNames.push('active:bg-gray-400')
|
|
79
|
-
|
|
80
|
-
variantClassNames.push(
|
|
81
|
-
'focus-visible:shadow-[0_0_0_3px_rgba(32,78,207,0.48)]'
|
|
82
|
-
)
|
|
83
|
-
if (focused) {
|
|
84
|
-
variantClassNames.push('shadow-[0_0_0_3px_rgba(32,78,207,0.48)]')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (hovered) {
|
|
88
|
-
variantClassNames.push('bg-gray-200')
|
|
89
|
-
} else if (active) {
|
|
90
|
-
variantClassNames.push('bg-gray-400')
|
|
91
|
-
} else {
|
|
92
|
-
variantClassNames.push('bg-transparent')
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
break
|
|
96
|
-
case 'transparent':
|
|
97
|
-
variantClassNames.push('border-none')
|
|
98
|
-
variantClassNames.push('text-white')
|
|
99
|
-
|
|
100
|
-
if (disabled) {
|
|
101
|
-
variantClassNames.push('text-white/[0.48]')
|
|
102
|
-
variantClassNames.push('bg-transparent')
|
|
103
|
-
} else {
|
|
104
|
-
variantClassNames.push('hover:bg-white/[0.08]')
|
|
105
|
-
variantClassNames.push('active:bg-white/[0.16]')
|
|
106
|
-
|
|
107
|
-
variantClassNames.push(
|
|
108
|
-
'focus-visible:shadow-[0_0_0_3px_rgba(255,255,255,0.48)]'
|
|
109
|
-
)
|
|
110
|
-
if (focused) {
|
|
111
|
-
variantClassNames.push('shadow-[0_0_0_3px_rgba(255,255,255,0.48)]')
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (hovered) {
|
|
115
|
-
variantClassNames.push('bg-white/[0.08]')
|
|
116
|
-
} else if (active) {
|
|
117
|
-
variantClassNames.push('bg-white/[0.16]')
|
|
118
|
-
} else {
|
|
119
|
-
variantClassNames.push('bg-transparent')
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
break
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return variantClassNames
|
|
127
|
-
}
|
|
1
|
+
import type { Theme } from '@material-ui/core/styles'
|
|
2
|
+
import { createStyles } from '@material-ui/core/styles'
|
|
3
|
+
import { alpha, outline } from '@toptal/picasso-shared'
|
|
4
|
+
import { screens } from '@toptal/picasso-provider'
|
|
5
|
+
|
|
6
|
+
export default ({ palette }: Theme) =>
|
|
7
|
+
createStyles({
|
|
8
|
+
root: {
|
|
9
|
+
borderRadius: '50%',
|
|
10
|
+
padding: 0,
|
|
11
|
+
minWidth: 'initial',
|
|
12
|
+
width: '1.5em',
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
primary: {},
|
|
16
|
+
|
|
17
|
+
responsive: {
|
|
18
|
+
width: '2.5em',
|
|
19
|
+
height: '2.5em',
|
|
20
|
+
[screens('xl')]: {
|
|
21
|
+
width: '1.5em',
|
|
22
|
+
height: '1.5em',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
flat: {
|
|
27
|
+
color: palette.grey.dark,
|
|
28
|
+
backgroundColor: 'initial',
|
|
29
|
+
|
|
30
|
+
'&:hover, &$hovered': {
|
|
31
|
+
backgroundColor: palette.grey.lighter2,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
'&:active, &$active': {
|
|
35
|
+
backgroundColor: palette.grey.light2,
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
'&$disabled': {
|
|
39
|
+
opacity: 0.48,
|
|
40
|
+
color: palette.grey.dark,
|
|
41
|
+
backgroundColor: 'initial',
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
border: 'none',
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
transparent: {
|
|
48
|
+
border: 'none',
|
|
49
|
+
color: palette.common.white,
|
|
50
|
+
backgroundColor: 'initial',
|
|
51
|
+
|
|
52
|
+
'&$focusVisible, &$focused': {
|
|
53
|
+
...outline(palette.common.white),
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
'&:hover, &$hovered': {
|
|
57
|
+
backgroundColor: alpha(palette.common.white, 0.08),
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
'&:active, &$active': {
|
|
61
|
+
backgroundColor: alpha(palette.common.white, 0.16),
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
'&$disabled': {
|
|
65
|
+
color: alpha(palette.common.white, 0.48),
|
|
66
|
+
backgroundColor: 'initial',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
disabled: {},
|
|
71
|
+
hovered: {},
|
|
72
|
+
focused: {},
|
|
73
|
+
active: {},
|
|
74
|
+
focusVisible: {},
|
|
75
|
+
})
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import type { BaseProps, SizeType } from '@toptal/picasso-shared'
|
|
4
|
-
import {
|
|
4
|
+
import type { Theme } from '@material-ui/core'
|
|
5
|
+
import { makeStyles } from '@material-ui/core'
|
|
6
|
+
import cx from 'classnames'
|
|
5
7
|
import { Container } from '@toptal/picasso-container'
|
|
6
8
|
|
|
7
9
|
import { Button } from '../Button'
|
|
8
|
-
import
|
|
10
|
+
import styles from './styles'
|
|
9
11
|
|
|
10
12
|
export interface Props extends BaseProps {
|
|
11
13
|
/** Show the control initially as checked */
|
|
@@ -35,6 +37,14 @@ export interface Props extends BaseProps {
|
|
|
35
37
|
control: ReactElement
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
// Using { index: -1 } to inject CSS link to the bottom of the head
|
|
41
|
+
// in order to prevent Button's styles to override ButtonAction's ones
|
|
42
|
+
// Related Jira issue: https://toptal-core.atlassian.net/browse/FX-1520
|
|
43
|
+
const useStyles = makeStyles<Theme>(styles, {
|
|
44
|
+
name: 'PicassoButtonControlLabel',
|
|
45
|
+
index: -1,
|
|
46
|
+
})
|
|
47
|
+
|
|
38
48
|
const ButtonControlLabel = ({
|
|
39
49
|
children,
|
|
40
50
|
size = 'medium',
|
|
@@ -47,12 +57,14 @@ const ButtonControlLabel = ({
|
|
|
47
57
|
disabled,
|
|
48
58
|
...props
|
|
49
59
|
}: Props) => {
|
|
60
|
+
const classes = useStyles()
|
|
61
|
+
|
|
50
62
|
const contentLeftSpacing = size === 'large' ? 1 : 0.5
|
|
51
63
|
|
|
52
64
|
return (
|
|
53
65
|
<Button
|
|
54
66
|
{...props}
|
|
55
|
-
className={
|
|
67
|
+
className={cx(className, classes.root, classes[size])}
|
|
56
68
|
variant='secondary'
|
|
57
69
|
size={size}
|
|
58
70
|
as='label'
|
|
@@ -60,10 +72,7 @@ const ButtonControlLabel = ({
|
|
|
60
72
|
disabled={disabled}
|
|
61
73
|
>
|
|
62
74
|
{React.cloneElement(control, { id, checked, value, onChange, disabled })}
|
|
63
|
-
<Container
|
|
64
|
-
className={createContentSizeClassNames(size)}
|
|
65
|
-
left={contentLeftSpacing}
|
|
66
|
-
>
|
|
75
|
+
<Container className={classes.content} left={contentLeftSpacing}>
|
|
67
76
|
{children}
|
|
68
77
|
</Container>
|
|
69
78
|
</Button>
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createStyles } from '@material-ui/core/styles'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return sizeClassNames[size]
|
|
31
|
-
}
|
|
3
|
+
export default () =>
|
|
4
|
+
createStyles({
|
|
5
|
+
root: {
|
|
6
|
+
textAlign: 'center',
|
|
7
|
+
padding: '0.5rem 1.5rem 0.5rem 1rem',
|
|
8
|
+
'&$small': {
|
|
9
|
+
padding: '0.25rem 1rem 0.25rem 0.5rem',
|
|
10
|
+
},
|
|
11
|
+
'&$large': {
|
|
12
|
+
padding: '1rem 2rem 1rem 1rem',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
content: {
|
|
16
|
+
minWidth: 64,
|
|
17
|
+
'$small &': {
|
|
18
|
+
minWidth: 48,
|
|
19
|
+
},
|
|
20
|
+
'$large &': {
|
|
21
|
+
minWidth: 84,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
small: {},
|
|
25
|
+
medium: {},
|
|
26
|
+
large: {},
|
|
27
|
+
})
|
|
@@ -1,25 +1,60 @@
|
|
|
1
|
-
import type { ReactNode, HTMLAttributes } from 'react'
|
|
2
|
-
import React, { forwardRef } from 'react'
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import type { ReactNode, HTMLAttributes, ElementType } from 'react'
|
|
2
|
+
import React, { forwardRef, useMemo } from 'react'
|
|
3
|
+
import type { Theme } from '@material-ui/core/styles'
|
|
4
|
+
import { makeStyles } from '@material-ui/core/styles'
|
|
5
|
+
import cx from 'classnames'
|
|
6
|
+
import type { BaseProps, Classes } from '@toptal/picasso-shared'
|
|
7
|
+
import { addClassesToChildren } from '@toptal/picasso-shared'
|
|
5
8
|
|
|
9
|
+
import { Button } from '../Button'
|
|
6
10
|
import { ButtonGroupItem } from '../ButtonGroupItem'
|
|
7
|
-
import
|
|
11
|
+
import styles from './styles'
|
|
8
12
|
|
|
9
13
|
export interface Props extends BaseProps, HTMLAttributes<HTMLDivElement> {
|
|
10
14
|
/** List of `Button` components which you want to render as `ButtonGroup` */
|
|
11
15
|
children: ReactNode
|
|
12
16
|
}
|
|
13
17
|
|
|
18
|
+
const useStyles = makeStyles<Theme>(styles, {
|
|
19
|
+
name: 'PicassoButtonGroup',
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const getChildrenClassesConfig = (
|
|
23
|
+
classes: Classes
|
|
24
|
+
): [ElementType, Classes][] => [
|
|
25
|
+
[
|
|
26
|
+
Button,
|
|
27
|
+
{
|
|
28
|
+
root: classes.button,
|
|
29
|
+
active: classes.active,
|
|
30
|
+
focused: classes.focused,
|
|
31
|
+
hovered: classes.hovered,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
]
|
|
35
|
+
|
|
14
36
|
export const ButtonGroup = forwardRef<HTMLDivElement, Props>(
|
|
15
37
|
function ButtonGroup(props, ref) {
|
|
16
38
|
const { children, className, style, ...rest } = props
|
|
17
|
-
|
|
18
|
-
const
|
|
39
|
+
const classes = useStyles()
|
|
40
|
+
const childrenWithClasses = useMemo(
|
|
41
|
+
() =>
|
|
42
|
+
addClassesToChildren({
|
|
43
|
+
children,
|
|
44
|
+
classes,
|
|
45
|
+
config: getChildrenClassesConfig,
|
|
46
|
+
}),
|
|
47
|
+
[children, classes]
|
|
48
|
+
)
|
|
19
49
|
|
|
20
50
|
return (
|
|
21
|
-
<div
|
|
22
|
-
{
|
|
51
|
+
<div
|
|
52
|
+
{...rest}
|
|
53
|
+
ref={ref}
|
|
54
|
+
className={cx(classes.root, className)}
|
|
55
|
+
style={style}
|
|
56
|
+
>
|
|
57
|
+
{childrenWithClasses}
|
|
23
58
|
</div>
|
|
24
59
|
)
|
|
25
60
|
}
|