@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
|
@@ -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
|
+
})
|
|
@@ -6,14 +6,14 @@ exports[`ButtonCheckbox renders 1`] = `
|
|
|
6
6
|
class="Picasso-root"
|
|
7
7
|
>
|
|
8
8
|
<label
|
|
9
|
-
|
|
9
|
+
aria-disabled="false"
|
|
10
|
+
class="MuiButtonBase-root PicassoButton-medium PicassoButton-secondary PicassoButton-root PicassoButtonControlLabel-root PicassoButtonControlLabel-medium"
|
|
10
11
|
data-component-type="button"
|
|
11
12
|
role="button"
|
|
12
13
|
tabindex="0"
|
|
13
|
-
type="button"
|
|
14
14
|
>
|
|
15
15
|
<span
|
|
16
|
-
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline
|
|
16
|
+
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
|
|
17
17
|
>
|
|
18
18
|
<span
|
|
19
19
|
class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
|
|
@@ -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: -100 } 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: -100,
|
|
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
|
+
})
|
|
@@ -37,12 +37,12 @@ export interface Props extends BaseProps {
|
|
|
37
37
|
control: ReactElement
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
// Using { index: -
|
|
40
|
+
// Using { index: -100 } to inject CSS link to the bottom of the head
|
|
41
41
|
// in order to prevent Button's styles to override ButtonAction's ones
|
|
42
42
|
// Related Jira issue: https://toptal-core.atlassian.net/browse/FX-1520
|
|
43
43
|
const useStyles = makeStyles<Theme>(styles, {
|
|
44
44
|
name: 'PicassoButtonControlLabel',
|
|
45
|
-
index: -
|
|
45
|
+
index: -100,
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
const ButtonControlLabel = ({
|
|
@@ -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
|
}
|
|
@@ -6,40 +6,40 @@ exports[`ButtonGroup render 1`] = `
|
|
|
6
6
|
class="Picasso-root"
|
|
7
7
|
>
|
|
8
8
|
<div
|
|
9
|
-
class="
|
|
9
|
+
class="PicassoButtonGroup-root"
|
|
10
10
|
>
|
|
11
11
|
<button
|
|
12
|
-
class="
|
|
12
|
+
class="MuiButtonBase-root PicassoButton-medium PicassoButton-secondary PicassoButton-root PicassoButtonGroupItem-root PicassoButtonGroupItem-group"
|
|
13
13
|
data-component-type="button"
|
|
14
14
|
tabindex="0"
|
|
15
15
|
type="button"
|
|
16
16
|
>
|
|
17
17
|
<span
|
|
18
|
-
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline
|
|
18
|
+
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
|
|
19
19
|
>
|
|
20
20
|
One
|
|
21
21
|
</span>
|
|
22
22
|
</button>
|
|
23
23
|
<button
|
|
24
|
-
class="
|
|
24
|
+
class="MuiButtonBase-root PicassoButton-active PicassoButton-medium PicassoButton-secondary PicassoButton-root PicassoButtonGroupItem-root PicassoButtonGroupItem-group PicassoButtonGroupItem-active"
|
|
25
25
|
data-component-type="button"
|
|
26
26
|
tabindex="0"
|
|
27
27
|
type="button"
|
|
28
28
|
>
|
|
29
29
|
<span
|
|
30
|
-
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline
|
|
30
|
+
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
|
|
31
31
|
>
|
|
32
32
|
Two
|
|
33
33
|
</span>
|
|
34
34
|
</button>
|
|
35
35
|
<button
|
|
36
|
-
class="
|
|
36
|
+
class="MuiButtonBase-root PicassoButton-medium PicassoButton-secondary PicassoButton-root PicassoButtonGroupItem-root PicassoButtonGroupItem-group"
|
|
37
37
|
data-component-type="button"
|
|
38
38
|
tabindex="0"
|
|
39
39
|
type="button"
|
|
40
40
|
>
|
|
41
41
|
<span
|
|
42
|
-
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline
|
|
42
|
+
class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
|
|
43
43
|
>
|
|
44
44
|
Three
|
|
45
45
|
</span>
|