@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.
Files changed (90) hide show
  1. package/dist-package/src/Button/Button.d.ts.map +1 -1
  2. package/dist-package/src/Button/Button.js +47 -39
  3. package/dist-package/src/Button/Button.js.map +1 -1
  4. package/dist-package/src/Button/styles.d.ts +45 -19
  5. package/dist-package/src/Button/styles.d.ts.map +1 -1
  6. package/dist-package/src/Button/styles.js +178 -161
  7. package/dist-package/src/Button/styles.js.map +1 -1
  8. package/dist-package/src/ButtonAction/ButtonAction.d.ts.map +1 -1
  9. package/dist-package/src/ButtonAction/ButtonAction.js +28 -20
  10. package/dist-package/src/ButtonAction/ButtonAction.js.map +1 -1
  11. package/dist-package/src/ButtonAction/styles.d.ts +3 -11
  12. package/dist-package/src/ButtonAction/styles.d.ts.map +1 -1
  13. package/dist-package/src/ButtonAction/styles.js +55 -36
  14. package/dist-package/src/ButtonAction/styles.js.map +1 -1
  15. package/dist-package/src/ButtonCircular/ButtonCircular.d.ts.map +1 -1
  16. package/dist-package/src/ButtonCircular/ButtonCircular.js +26 -12
  17. package/dist-package/src/ButtonCircular/ButtonCircular.js.map +1 -1
  18. package/dist-package/src/ButtonCircular/styles.d.ts +3 -15
  19. package/dist-package/src/ButtonCircular/styles.d.ts.map +1 -1
  20. package/dist-package/src/ButtonCircular/styles.js +57 -92
  21. package/dist-package/src/ButtonCircular/styles.js.map +1 -1
  22. package/dist-package/src/ButtonCompound/index.d.ts +1 -1
  23. package/dist-package/src/ButtonControlLabel/ButtonControlLabel.d.ts.map +1 -1
  24. package/dist-package/src/ButtonControlLabel/ButtonControlLabel.js +13 -4
  25. package/dist-package/src/ButtonControlLabel/ButtonControlLabel.js.map +1 -1
  26. package/dist-package/src/ButtonControlLabel/styles.d.ts +2 -2
  27. package/dist-package/src/ButtonControlLabel/styles.d.ts.map +1 -1
  28. package/dist-package/src/ButtonControlLabel/styles.js +25 -16
  29. package/dist-package/src/ButtonControlLabel/styles.js.map +1 -1
  30. package/dist-package/src/ButtonGroup/ButtonGroup.d.ts +1 -1
  31. package/dist-package/src/ButtonGroup/ButtonGroup.d.ts.map +1 -1
  32. package/dist-package/src/ButtonGroup/ButtonGroup.js +27 -5
  33. package/dist-package/src/ButtonGroup/ButtonGroup.js.map +1 -1
  34. package/dist-package/src/ButtonGroup/styles.d.ts +2 -1
  35. package/dist-package/src/ButtonGroup/styles.d.ts.map +1 -1
  36. package/dist-package/src/ButtonGroup/styles.js +47 -20
  37. package/dist-package/src/ButtonGroup/styles.js.map +1 -1
  38. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.d.ts +1 -1
  39. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.d.ts.map +1 -1
  40. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js +12 -17
  41. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js.map +1 -1
  42. package/dist-package/src/ButtonGroupItem/styles.d.ts +3 -13
  43. package/dist-package/src/ButtonGroupItem/styles.d.ts.map +1 -1
  44. package/dist-package/src/ButtonGroupItem/styles.js +17 -39
  45. package/dist-package/src/ButtonGroupItem/styles.js.map +1 -1
  46. package/dist-package/src/ButtonSplit/ButtonSplit.d.ts.map +1 -1
  47. package/dist-package/src/ButtonSplit/ButtonSplit.js +24 -28
  48. package/dist-package/src/ButtonSplit/ButtonSplit.js.map +1 -1
  49. package/dist-package/src/ButtonSplit/styles.d.ts +3 -9
  50. package/dist-package/src/ButtonSplit/styles.d.ts.map +1 -1
  51. package/dist-package/src/ButtonSplit/styles.js +50 -13
  52. package/dist-package/src/ButtonSplit/styles.js.map +1 -1
  53. package/package.json +15 -19
  54. package/src/Button/Button.tsx +100 -69
  55. package/src/Button/__snapshots__/test.tsx.snap +4 -8
  56. package/src/Button/styles.ts +221 -214
  57. package/src/Button/test.tsx +1 -3
  58. package/src/ButtonAction/ButtonAction.tsx +48 -36
  59. package/src/ButtonAction/styles.ts +57 -57
  60. package/src/ButtonCheckbox/__snapshots__/test.tsx.snap +3 -4
  61. package/src/ButtonCircular/ButtonCircular.tsx +37 -22
  62. package/src/ButtonCircular/styles.ts +75 -127
  63. package/src/ButtonControlLabel/ButtonControlLabel.tsx +16 -7
  64. package/src/ButtonControlLabel/styles.ts +26 -30
  65. package/src/ButtonGroup/ButtonGroup.tsx +44 -9
  66. package/src/ButtonGroup/__snapshots__/test.tsx.snap +7 -13
  67. package/src/ButtonGroup/styles.ts +63 -21
  68. package/src/ButtonGroupItem/ButtonGroupItem.tsx +15 -24
  69. package/src/ButtonGroupItem/styles.ts +28 -62
  70. package/src/ButtonRadio/__snapshots__/test.tsx.snap +3 -4
  71. package/src/ButtonSplit/ButtonSplit.tsx +42 -46
  72. package/src/ButtonSplit/__snapshots__/test.tsx.snap +9 -13
  73. package/src/ButtonSplit/styles.ts +56 -37
  74. package/dist-package/src/ButtonBase/ButtonBase.d.ts +0 -29
  75. package/dist-package/src/ButtonBase/ButtonBase.d.ts.map +0 -1
  76. package/dist-package/src/ButtonBase/ButtonBase.js +0 -78
  77. package/dist-package/src/ButtonBase/ButtonBase.js.map +0 -1
  78. package/dist-package/src/ButtonBase/index.d.ts +0 -5
  79. package/dist-package/src/ButtonBase/index.d.ts.map +0 -1
  80. package/dist-package/src/ButtonBase/index.js +0 -2
  81. package/dist-package/src/ButtonBase/index.js.map +0 -1
  82. package/dist-package/src/ButtonBase/styles.d.ts +0 -6
  83. package/dist-package/src/ButtonBase/styles.d.ts.map +0 -1
  84. package/dist-package/src/ButtonBase/styles.js +0 -29
  85. package/dist-package/src/ButtonBase/styles.js.map +0 -1
  86. package/src/ButtonBase/ButtonBase.tsx +0 -182
  87. package/src/ButtonBase/__snapshots__/test.tsx.snap +0 -262
  88. package/src/ButtonBase/index.ts +0 -5
  89. package/src/ButtonBase/styles.ts +0 -36
  90. package/src/ButtonBase/test.tsx +0 -212
@@ -1,58 +1,58 @@
1
- import type { IconPositionType } from '../ButtonBase'
1
+ import type { Theme } from '@material-ui/core/styles'
2
+ import { createStyles } from '@material-ui/core/styles'
2
3
 
3
- export const createRootClassNames = ({
4
- disabled,
5
- focused,
6
- hovered,
7
- active,
8
- loading,
9
- }: {
10
- disabled?: boolean
11
- focused?: boolean
12
- hovered?: boolean
13
- active?: boolean
14
- loading?: boolean
15
- }) => {
16
- const classNames = ['border-none', 'px-0', 'bg-transparent', 'h-[1.5em]']
17
-
18
- if (disabled) {
19
- classNames.push('opacity-[.48]')
20
- } else if (loading) {
21
- classNames.push('no-underline')
22
- classNames.push('!cursor-default')
23
- } else {
24
- classNames.push('hover:text-blue-500')
25
- classNames.push('hover:underline')
26
- classNames.push('active:text-blue-500')
27
- classNames.push('active:underline')
28
-
29
- if (hovered || active) {
30
- classNames.push('text-blue-500')
31
- classNames.push('underline')
32
- }
33
-
34
- classNames.push('focus-visible:shadow-[0_0_0_3px_rgba(32,78,207,0.48)]')
35
- classNames.push('focus-visible:rounded-sm')
36
-
37
- if (focused) {
38
- classNames.push('shadow-[0_0_0_3px_rgba(32,78,207,0.48)]')
39
- classNames.push('rounded-sm')
40
- }
41
- }
42
-
43
- return classNames
44
- }
45
-
46
- export const createIconClassNames = ({
47
- iconPosition,
48
- }: {
49
- iconPosition?: IconPositionType
50
- }): string[] => {
51
- return [
52
- 'w-4',
53
- 'h-4',
54
- 'text-graphite-700',
55
- iconPosition === 'left' ? 'mr-[0.5rem]' : '',
56
- iconPosition === 'right' ? 'ml-[0.5rem]' : '',
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="base-Button text-lg inline-flex items-center justify-center select-none appearance-none m-0 relative normal-case align-middle transition-colors duration-350 ease-out shrink-0 outline-none [&+&]:ml-4 cursor-pointer no-underline rounded-sm shadow-none focus-visible:shadow-[0_0_0_3px_rgba(32,78,207,0.48)] focus-within:shadow-[0_0_0_3px_rgba(32,78,207,0.48)] border border-solid text-black hover:border-black visited:text-black active:bg-gray active:border-black bg-white border-gray min-w h-8 px-4 text-center py-2 pr-6 pl-4"
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 font-semibold whitespace-nowrap text-button"
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="min-w"
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 { ButtonBase } from '../ButtonBase'
11
- import { createRootClassNames, createVariantClassNames } from './styles'
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 variantClassNames = createVariantClassNames(variant, {
56
- disabled,
57
- focused,
58
- hovered,
59
- active,
60
- })
65
+ const classes = useStyles()
61
66
 
62
- const finalClassName = cx(
63
- createRootClassNames({ responsive, active, disabled, focused, hovered }),
64
- variantClassNames,
65
- className
66
- )
67
+ const { root: rootClass, focusVisible: focusVisibleClass } = classes
68
+
69
+ const variantClassName = classes[kebabToCamelCase(variant)]
67
70
 
68
- const contentClassName = cx(
69
- 'font-semibold whitespace-nowrap',
70
- 'text-button-small',
71
- loading ? 'opacity-0' : ''
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
- <ButtonBase
84
+ <Button
76
85
  {...rest}
77
86
  ref={ref}
78
- loading={loading}
79
- className={finalClassName}
80
- contentClassName={contentClassName}
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 { VariantType } from './ButtonCircular'
2
-
3
- export const createRootClassNames = ({
4
- responsive,
5
- }: {
6
- disabled?: boolean
7
- focused?: boolean
8
- hovered?: boolean
9
- active?: boolean
10
- loading?: boolean
11
- responsive?: boolean
12
- }) => {
13
- const classNames = ['rounded-full', 'p-0']
14
-
15
- if (responsive) {
16
- classNames.push('w-[2.5em] h-[2.5em] xl:w-[1.5em] xl:h-[1.5em]')
17
- } else {
18
- classNames.push('w-[1.5em] h-[1.5em]')
19
- }
20
-
21
- return classNames
22
- }
23
-
24
- export const createVariantClassNames = (
25
- variant: VariantType,
26
- {
27
- disabled,
28
- focused,
29
- hovered,
30
- active,
31
- }: {
32
- disabled?: boolean
33
- focused?: boolean
34
- hovered?: boolean
35
- active?: boolean
36
- }
37
- ): string[] => {
38
- const variantClassNames = []
39
-
40
- switch (variant) {
41
- case 'primary':
42
- variantClassNames.push('border-none')
43
- variantClassNames.push('text-white')
44
- variantClassNames.push('visited:text-white')
45
-
46
- if (disabled) {
47
- variantClassNames.push('bg-gray-400')
48
- } else {
49
- variantClassNames.push('hover:bg-[#4269D6]')
50
- variantClassNames.push('active:bg-[#1A41AB]')
51
-
52
- variantClassNames.push(
53
- 'focus-visible:shadow-[0_0_0_3px_rgba(32,78,207,0.48)]'
54
- )
55
- if (focused) {
56
- variantClassNames.push('shadow-[0_0_0_3px_rgba(32,78,207,0.48)]')
57
- }
58
-
59
- if (hovered) {
60
- variantClassNames.push('bg-[#4269D6]')
61
- } else if (active) {
62
- variantClassNames.push('bg-[#1A41AB]')
63
- } else {
64
- variantClassNames.push('bg-blue-500')
65
- }
66
- }
67
- break
68
- case 'flat':
69
- variantClassNames.push('border-none')
70
- variantClassNames.push('text-graphite-700')
71
-
72
- if (disabled) {
73
- variantClassNames.push('text-graphite-700')
74
- variantClassNames.push('opacity-[0.48]')
75
- variantClassNames.push('bg-transparent')
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 { twMerge } from 'tailwind-merge'
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 { createSizeClassNames, createContentSizeClassNames } from './styles'
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={twMerge('text-center', createSizeClassNames(size), 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 type { SizeType } from '@toptal/picasso-shared'
1
+ import { createStyles } from '@material-ui/core/styles'
2
2
 
3
- export const createSizeClassNames = (
4
- size: 'small' | 'medium' | 'large'
5
- ): string => {
6
- const sizeClassNames: Record<
7
- SizeType<'small' | 'medium' | 'large'>,
8
- string
9
- > = {
10
- small: 'py-1 pr-4 pl-2',
11
- medium: 'py-2 pr-6 pl-4',
12
- large: 'py-4 pr-8 pl-4',
13
- }
14
-
15
- return sizeClassNames[size]
16
- }
17
-
18
- export const createContentSizeClassNames = (
19
- size: 'small' | 'medium' | 'large'
20
- ): string => {
21
- const sizeClassNames: Record<
22
- SizeType<'small' | 'medium' | 'large'>,
23
- string
24
- > = {
25
- small: 'min-w-12',
26
- medium: 'min-w-16',
27
- large: 'min-w-[5.25rem]',
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 { twMerge } from 'tailwind-merge'
4
- import type { BaseProps } from '@toptal/picasso-shared'
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 { createRootClassNames } from './styles'
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 finalClassName = twMerge(createRootClassNames(), className)
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 {...rest} ref={ref} className={finalClassName} style={style}>
22
- {children}
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
  }