@toptal/picasso-button 1.0.10-alpha-dependabot-npm-and-yarn-debounce-2.0.0-7bd37151a.8 → 1.0.10-alpha-feature-migrate-buttons-638be38bb.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.
Files changed (80) hide show
  1. package/dist-package/src/Button/Button.d.ts.map +1 -1
  2. package/dist-package/src/Button/Button.js +39 -47
  3. package/dist-package/src/Button/Button.js.map +1 -1
  4. package/dist-package/src/Button/styles.d.ts +19 -45
  5. package/dist-package/src/Button/styles.d.ts.map +1 -1
  6. package/dist-package/src/Button/styles.js +160 -178
  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 +20 -28
  10. package/dist-package/src/ButtonAction/ButtonAction.js.map +1 -1
  11. package/dist-package/src/ButtonAction/styles.d.ts +11 -3
  12. package/dist-package/src/ButtonAction/styles.d.ts.map +1 -1
  13. package/dist-package/src/ButtonAction/styles.js +36 -55
  14. package/dist-package/src/ButtonAction/styles.js.map +1 -1
  15. package/dist-package/src/ButtonBase/ButtonBase.d.ts +29 -0
  16. package/dist-package/src/ButtonBase/ButtonBase.d.ts.map +1 -0
  17. package/dist-package/src/ButtonBase/ButtonBase.js +77 -0
  18. package/dist-package/src/ButtonBase/ButtonBase.js.map +1 -0
  19. package/dist-package/src/ButtonBase/index.d.ts +5 -0
  20. package/dist-package/src/ButtonBase/index.d.ts.map +1 -0
  21. package/dist-package/src/ButtonBase/index.js +2 -0
  22. package/dist-package/src/ButtonBase/index.js.map +1 -0
  23. package/dist-package/src/ButtonBase/styles.d.ts +8 -0
  24. package/dist-package/src/ButtonBase/styles.d.ts.map +1 -0
  25. package/dist-package/src/ButtonBase/styles.js +29 -0
  26. package/dist-package/src/ButtonBase/styles.js.map +1 -0
  27. package/dist-package/src/ButtonCircular/ButtonCircular.d.ts.map +1 -1
  28. package/dist-package/src/ButtonCircular/ButtonCircular.js +12 -26
  29. package/dist-package/src/ButtonCircular/ButtonCircular.js.map +1 -1
  30. package/dist-package/src/ButtonCircular/styles.d.ts +15 -3
  31. package/dist-package/src/ButtonCircular/styles.d.ts.map +1 -1
  32. package/dist-package/src/ButtonCircular/styles.js +92 -57
  33. package/dist-package/src/ButtonCircular/styles.js.map +1 -1
  34. package/dist-package/src/ButtonCompound/index.d.ts +1 -1
  35. package/dist-package/src/ButtonControlLabel/styles.d.ts +1 -1
  36. package/dist-package/src/ButtonGroup/ButtonGroup.d.ts +1 -1
  37. package/dist-package/src/ButtonGroup/ButtonGroup.d.ts.map +1 -1
  38. package/dist-package/src/ButtonGroup/ButtonGroup.js +5 -27
  39. package/dist-package/src/ButtonGroup/ButtonGroup.js.map +1 -1
  40. package/dist-package/src/ButtonGroup/styles.d.ts +1 -2
  41. package/dist-package/src/ButtonGroup/styles.d.ts.map +1 -1
  42. package/dist-package/src/ButtonGroup/styles.js +20 -47
  43. package/dist-package/src/ButtonGroup/styles.js.map +1 -1
  44. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.d.ts +1 -1
  45. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.d.ts.map +1 -1
  46. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js +17 -12
  47. package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js.map +1 -1
  48. package/dist-package/src/ButtonGroupItem/styles.d.ts +13 -3
  49. package/dist-package/src/ButtonGroupItem/styles.d.ts.map +1 -1
  50. package/dist-package/src/ButtonGroupItem/styles.js +39 -17
  51. package/dist-package/src/ButtonGroupItem/styles.js.map +1 -1
  52. package/dist-package/src/ButtonSplit/ButtonSplit.d.ts.map +1 -1
  53. package/dist-package/src/ButtonSplit/ButtonSplit.js +28 -24
  54. package/dist-package/src/ButtonSplit/ButtonSplit.js.map +1 -1
  55. package/dist-package/src/ButtonSplit/styles.d.ts +9 -3
  56. package/dist-package/src/ButtonSplit/styles.d.ts.map +1 -1
  57. package/dist-package/src/ButtonSplit/styles.js +13 -50
  58. package/dist-package/src/ButtonSplit/styles.js.map +1 -1
  59. package/package.json +19 -15
  60. package/src/Button/Button.tsx +69 -100
  61. package/src/Button/__snapshots__/test.tsx.snap +6 -5
  62. package/src/Button/styles.ts +213 -221
  63. package/src/Button/test.tsx +3 -1
  64. package/src/ButtonAction/ButtonAction.tsx +36 -48
  65. package/src/ButtonAction/styles.ts +57 -57
  66. package/src/ButtonBase/ButtonBase.tsx +177 -0
  67. package/src/ButtonBase/index.ts +5 -0
  68. package/src/ButtonBase/styles.ts +38 -0
  69. package/src/ButtonCheckbox/__snapshots__/test.tsx.snap +3 -3
  70. package/src/ButtonCircular/ButtonCircular.tsx +22 -34
  71. package/src/ButtonCircular/styles.ts +127 -75
  72. package/src/ButtonGroup/ButtonGroup.tsx +9 -44
  73. package/src/ButtonGroup/__snapshots__/test.tsx.snap +7 -7
  74. package/src/ButtonGroup/styles.ts +21 -63
  75. package/src/ButtonGroupItem/ButtonGroupItem.tsx +24 -15
  76. package/src/ButtonGroupItem/styles.ts +62 -28
  77. package/src/ButtonRadio/__snapshots__/test.tsx.snap +3 -3
  78. package/src/ButtonSplit/ButtonSplit.tsx +46 -42
  79. package/src/ButtonSplit/__snapshots__/test.tsx.snap +9 -9
  80. package/src/ButtonSplit/styles.ts +37 -56
@@ -1,58 +1,58 @@
1
- import type { Theme } from '@material-ui/core/styles'
2
- import { createStyles } from '@material-ui/core/styles'
1
+ import type { IconPositionType } from '../ButtonBase'
3
2
 
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
- })
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
+ }
@@ -0,0 +1,177 @@
1
+ import type {
2
+ ReactNode,
3
+ ReactElement,
4
+ MouseEvent,
5
+ ElementType,
6
+ FC,
7
+ } from 'react'
8
+ import React, { forwardRef } from 'react'
9
+ import { twMerge } from 'tailwind-merge'
10
+ import type {
11
+ StandardProps,
12
+ ButtonOrAnchorProps,
13
+ OverridableComponent,
14
+ TextLabelProps,
15
+ } from '@toptal/picasso-shared'
16
+ import { useTitleCase } from '@toptal/picasso-shared'
17
+ import { Button as MUIButtonBase } from '@mui/base/Button'
18
+ import { Loader } from '@toptal/picasso-loader'
19
+ import { Container } from '@toptal/picasso-container'
20
+ import { noop, toTitleCase } from '@toptal/picasso-utils'
21
+
22
+ import { createCoreClassNames } from './styles'
23
+
24
+ export type IconPositionType = 'left' | 'right'
25
+
26
+ export interface Props
27
+ extends StandardProps,
28
+ TextLabelProps,
29
+ ButtonOrAnchorProps {
30
+ as?: ElementType
31
+ /** Disables button */
32
+ disabled?: boolean
33
+ /** Content of Button component */
34
+ children?: ReactNode
35
+ /** ClassName for the content */
36
+ contentClassName?: string
37
+ /** Add an `<Icon />` along Button's children */
38
+ icon?: ReactElement
39
+ /** Icon can be positioned on the left or right */
40
+ iconPosition?: IconPositionType
41
+ /** Shows a loading indicator and disables click events */
42
+ loading?: boolean
43
+ /** Callback invoked when component is clicked */
44
+ onClick?: (event: MouseEvent<HTMLButtonElement & HTMLAnchorElement>) => void
45
+ /** HTML Value of Button component */
46
+ value?: string | number
47
+ /** HTML title of Button component */
48
+ title?: string
49
+ /** HTML type of Button component */
50
+ type?: 'button' | 'reset' | 'submit'
51
+ }
52
+
53
+ const getClickHandler = (loading?: boolean, handler?: Props['onClick']) =>
54
+ loading ? noop : handler
55
+
56
+ const getIcon = ({ icon }: { icon?: ReactElement }) => {
57
+ if (!icon) {
58
+ return null
59
+ }
60
+
61
+ return React.cloneElement(icon, {
62
+ className: twMerge('text-[1.2em] flex-1', icon.props.className),
63
+ key: 'button-icon',
64
+ })
65
+ }
66
+
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ const isReactComponent = (component: any) => {
69
+ return (
70
+ component &&
71
+ (component.$$typeof === Symbol.for('react.forward_ref') ||
72
+ typeof component === 'function')
73
+ )
74
+ }
75
+
76
+ export const ButtonBase: OverridableComponent<Props> = forwardRef<
77
+ HTMLButtonElement,
78
+ Props
79
+ >(function ButtonBase(props, ref) {
80
+ const {
81
+ icon,
82
+ iconPosition,
83
+ loading,
84
+ children,
85
+ className,
86
+ contentClassName,
87
+ style,
88
+ disabled,
89
+ onClick,
90
+ title,
91
+ value,
92
+ type,
93
+ as = 'button',
94
+ titleCase: propsTitleCase,
95
+ ...rest
96
+ } = props
97
+
98
+ let RootElement: ElementType | FC = as
99
+
100
+ if (isReactComponent(RootElement)) {
101
+ RootElement = forwardRef(
102
+ // We don't need to pass ownerState to the root component
103
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
104
+ ({ ownerState, ...restProps }: { ownerState: object }, rootRef) => {
105
+ const Root = as
106
+
107
+ return <Root ref={rootRef} {...restProps} />
108
+ }
109
+ )
110
+ }
111
+
112
+ const titleCase = useTitleCase(propsTitleCase)
113
+ const finalChildren = [titleCase ? toTitleCase(children) : children]
114
+
115
+ if (icon) {
116
+ const iconComponent = getIcon({ icon })
117
+
118
+ if (iconPosition === 'left') {
119
+ finalChildren.unshift(iconComponent)
120
+ } else {
121
+ finalChildren.push(iconComponent)
122
+ }
123
+ }
124
+
125
+ const finalClassName = twMerge(createCoreClassNames({ disabled }), className)
126
+
127
+ return (
128
+ <MUIButtonBase
129
+ {...rest}
130
+ ref={ref}
131
+ onClick={getClickHandler(loading, onClick)}
132
+ className={finalClassName}
133
+ style={style}
134
+ disabled={disabled}
135
+ title={title}
136
+ value={value}
137
+ type={type}
138
+ data-component-type='button'
139
+ tabIndex={rest.tabIndex ?? disabled ? -1 : 0}
140
+ slots={{ root: RootElement }}
141
+ >
142
+ <Container
143
+ as='span'
144
+ inline
145
+ flex
146
+ direction='row'
147
+ alignItems='center'
148
+ className={contentClassName}
149
+ >
150
+ {finalChildren}
151
+ </Container>
152
+
153
+ {loading && (
154
+ <Loader
155
+ variant='inherit'
156
+ className='absolute top-1/2 left-1/2 translate-x-[-50%] translate-y-[-50%]'
157
+ inline
158
+ size='small'
159
+ />
160
+ )}
161
+ </MUIButtonBase>
162
+ )
163
+ })
164
+
165
+ ButtonBase.defaultProps = {
166
+ as: 'button',
167
+ children: null,
168
+ disabled: false,
169
+ iconPosition: 'left',
170
+ loading: false,
171
+ onClick: noop,
172
+ type: 'button',
173
+ }
174
+
175
+ ButtonBase.displayName = 'ButtonBase'
176
+
177
+ export default ButtonBase
@@ -0,0 +1,5 @@
1
+ import type { Props } from './ButtonBase'
2
+
3
+ export { default as ButtonBase } from './ButtonBase'
4
+ export type { IconPositionType } from './ButtonBase'
5
+ export type ButtonBaseProps = Props
@@ -0,0 +1,38 @@
1
+ export const createCoreClassNames = ({
2
+ disabled,
3
+ loading,
4
+ }: {
5
+ disabled?: boolean
6
+ focused?: boolean
7
+ hovered?: boolean
8
+ active?: boolean
9
+ loading?: boolean
10
+ }): string[] => {
11
+ const classNames = [
12
+ 'text-lg',
13
+ 'inline-flex',
14
+ 'items-center',
15
+ 'justify-center',
16
+ 'select-none',
17
+ 'appearance-none',
18
+ 'm-0',
19
+ 'relative',
20
+ 'normal-case',
21
+ 'align-middle',
22
+ 'transition-colors',
23
+ 'duration-350',
24
+ 'ease-out',
25
+ 'shrink-0',
26
+ 'outline-none',
27
+ '[&+&]:ml-4',
28
+ ]
29
+
30
+ if (!disabled && !loading) {
31
+ classNames.push('cursor-pointer')
32
+ } else {
33
+ classNames.push('cursor-default')
34
+ classNames.push('pointer-events-none')
35
+ }
36
+
37
+ return classNames
38
+ }
@@ -6,14 +6,14 @@ exports[`ButtonCheckbox renders 1`] = `
6
6
  class="Picasso-root"
7
7
  >
8
8
  <label
9
- aria-disabled="false"
10
- class="MuiButtonBase-root PicassoButton-medium PicassoButton-secondary PicassoButton-root PicassoButtonControlLabel-root PicassoButtonControlLabel-medium"
9
+ 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)] 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 py-0 px-4 PicassoButtonControlLabel-root PicassoButtonControlLabel-medium"
11
10
  data-component-type="button"
12
11
  role="button"
13
12
  tabindex="0"
13
+ type="button"
14
14
  >
15
15
  <span
16
- class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline PicassoButton-content"
16
+ class="PicassoContainer-centerAlignItems PicassoContainer-flex PicassoContainer-inline font-semibold whitespace-nowrap text-button"
17
17
  >
18
18
  <span
19
19
  class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
@@ -1,17 +1,14 @@
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'
6
4
  import type {
7
5
  BaseProps,
8
6
  ButtonOrAnchorProps,
9
7
  OverridableComponent,
10
8
  } from '@toptal/picasso-shared'
11
- import { kebabToCamelCase } from '@toptal/picasso-utils'
12
9
 
13
- import { Button } from '../Button'
14
- import styles from './styles'
10
+ import { ButtonBase } from '../ButtonBase'
11
+ import { createRootClassNames, createVariantClassNames } from './styles'
15
12
 
16
13
  export type VariantType = 'primary' | 'flat' | 'transparent'
17
14
 
@@ -40,14 +37,6 @@ export interface Props extends BaseProps, ButtonOrAnchorProps {
40
37
  responsive?: boolean
41
38
  }
42
39
 
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
-
51
40
  export const ButtonCircular: OverridableComponent<Props> = forwardRef<
52
41
  HTMLButtonElement,
53
42
  Props
@@ -60,36 +49,35 @@ export const ButtonCircular: OverridableComponent<Props> = forwardRef<
60
49
  hovered,
61
50
  disabled,
62
51
  responsive,
52
+ loading,
63
53
  ...rest
64
54
  } = props
65
- const classes = useStyles()
66
-
67
- const { root: rootClass, focusVisible: focusVisibleClass } = classes
55
+ const variantClassNames = createVariantClassNames(variant, {
56
+ disabled,
57
+ focused,
58
+ hovered,
59
+ active,
60
+ })
68
61
 
69
- const variantClassName = classes[kebabToCamelCase(variant)]
62
+ const finalClassName = cx(
63
+ createRootClassNames({ responsive, active, disabled, focused, hovered }),
64
+ variantClassNames,
65
+ className
66
+ )
70
67
 
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
68
+ const contentClassName = cx(
69
+ 'font-semibold whitespace-nowrap',
70
+ 'text-button-small',
71
+ loading ? 'opacity-0' : ''
81
72
  )
82
73
 
83
74
  return (
84
- <Button
75
+ <ButtonBase
85
76
  {...rest}
86
77
  ref={ref}
87
- classes={{
88
- root: rootClassName,
89
- focusVisible: focusVisibleClass,
90
- }}
91
- className={className}
92
- size='small'
78
+ loading={loading}
79
+ className={finalClassName}
80
+ contentClassName={contentClassName}
93
81
  active={active}
94
82
  hovered={hovered}
95
83
  focused={focused}
@@ -1,75 +1,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
+ 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
+ }