@toptal/picasso-button 1.0.10-alpha-FX-5195-fix-update-problems-902f38edb.16 → 1.0.10-alpha-feature-migrate-buttons-6d6012711.21
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 +39 -47
- package/dist-package/src/Button/Button.js.map +1 -1
- package/dist-package/src/Button/styles.d.ts +19 -45
- package/dist-package/src/Button/styles.d.ts.map +1 -1
- package/dist-package/src/Button/styles.js +160 -178
- 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 +20 -28
- package/dist-package/src/ButtonAction/ButtonAction.js.map +1 -1
- package/dist-package/src/ButtonAction/styles.d.ts +11 -3
- package/dist-package/src/ButtonAction/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonAction/styles.js +36 -55
- package/dist-package/src/ButtonAction/styles.js.map +1 -1
- package/dist-package/src/ButtonBase/ButtonBase.d.ts +29 -0
- package/dist-package/src/ButtonBase/ButtonBase.d.ts.map +1 -0
- package/dist-package/src/ButtonBase/ButtonBase.js +78 -0
- package/dist-package/src/ButtonBase/ButtonBase.js.map +1 -0
- package/dist-package/src/ButtonBase/index.d.ts +5 -0
- package/dist-package/src/ButtonBase/index.d.ts.map +1 -0
- package/dist-package/src/ButtonBase/index.js +2 -0
- package/dist-package/src/ButtonBase/index.js.map +1 -0
- package/dist-package/src/ButtonBase/styles.d.ts +6 -0
- package/dist-package/src/ButtonBase/styles.d.ts.map +1 -0
- package/dist-package/src/ButtonBase/styles.js +29 -0
- package/dist-package/src/ButtonBase/styles.js.map +1 -0
- package/dist-package/src/ButtonCircular/ButtonCircular.d.ts.map +1 -1
- package/dist-package/src/ButtonCircular/ButtonCircular.js +12 -26
- package/dist-package/src/ButtonCircular/ButtonCircular.js.map +1 -1
- package/dist-package/src/ButtonCircular/styles.d.ts +15 -3
- package/dist-package/src/ButtonCircular/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonCircular/styles.js +92 -57
- 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/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 +5 -27
- package/dist-package/src/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist-package/src/ButtonGroup/styles.d.ts +1 -2
- package/dist-package/src/ButtonGroup/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonGroup/styles.js +20 -47
- 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 +17 -12
- package/dist-package/src/ButtonGroupItem/ButtonGroupItem.js.map +1 -1
- package/dist-package/src/ButtonGroupItem/styles.d.ts +13 -3
- package/dist-package/src/ButtonGroupItem/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonGroupItem/styles.js +39 -17
- 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 +28 -24
- package/dist-package/src/ButtonSplit/ButtonSplit.js.map +1 -1
- package/dist-package/src/ButtonSplit/styles.d.ts +9 -3
- package/dist-package/src/ButtonSplit/styles.d.ts.map +1 -1
- package/dist-package/src/ButtonSplit/styles.js +13 -50
- package/dist-package/src/ButtonSplit/styles.js.map +1 -1
- package/package.json +19 -15
- package/src/Button/Button.tsx +69 -100
- package/src/Button/__snapshots__/test.tsx.snap +6 -5
- package/src/Button/styles.ts +213 -221
- package/src/Button/test.tsx +3 -1
- package/src/ButtonAction/ButtonAction.tsx +36 -48
- package/src/ButtonAction/styles.ts +57 -57
- package/src/ButtonBase/ButtonBase.tsx +182 -0
- package/src/ButtonBase/index.ts +5 -0
- package/src/ButtonBase/styles.ts +36 -0
- package/src/ButtonCheckbox/__snapshots__/test.tsx.snap +3 -3
- package/src/ButtonCircular/ButtonCircular.tsx +22 -37
- package/src/ButtonCircular/styles.ts +127 -75
- package/src/ButtonGroup/ButtonGroup.tsx +9 -44
- package/src/ButtonGroup/__snapshots__/test.tsx.snap +7 -7
- package/src/ButtonGroup/styles.ts +21 -63
- package/src/ButtonGroupItem/ButtonGroupItem.tsx +24 -15
- package/src/ButtonGroupItem/styles.ts +62 -28
- package/src/ButtonRadio/__snapshots__/test.tsx.snap +3 -3
- package/src/ButtonSplit/ButtonSplit.tsx +46 -42
- package/src/ButtonSplit/__snapshots__/test.tsx.snap +9 -9
- package/src/ButtonSplit/styles.ts +37 -56
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { createStyles } from '@material-ui/core/styles'
|
|
1
|
+
import type { IconPositionType } from '../ButtonBase'
|
|
3
2
|
|
|
4
|
-
export
|
|
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
|
-
|
|
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,182 @@
|
|
|
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
|
+
const rootElementName =
|
|
115
|
+
as !== 'button' && ('href' in props || 'to' in props) ? 'a' : undefined
|
|
116
|
+
|
|
117
|
+
if (icon) {
|
|
118
|
+
const iconComponent = getIcon({ icon })
|
|
119
|
+
|
|
120
|
+
if (iconPosition === 'left') {
|
|
121
|
+
finalChildren.unshift(iconComponent)
|
|
122
|
+
} else {
|
|
123
|
+
finalChildren.push(iconComponent)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const finalClassName = twMerge(createCoreClassNames({ disabled }), className)
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<MUIButtonBase
|
|
131
|
+
{...rest}
|
|
132
|
+
ref={ref}
|
|
133
|
+
onClick={getClickHandler(loading, onClick)}
|
|
134
|
+
className={finalClassName}
|
|
135
|
+
style={style}
|
|
136
|
+
aria-disabled={disabled}
|
|
137
|
+
disabled={disabled}
|
|
138
|
+
title={title}
|
|
139
|
+
value={value}
|
|
140
|
+
type={type}
|
|
141
|
+
data-component-type='button'
|
|
142
|
+
tabIndex={rest.tabIndex ?? disabled ? -1 : 0}
|
|
143
|
+
role={rest.role ?? 'button'}
|
|
144
|
+
rootElementName={rootElementName}
|
|
145
|
+
slots={{ root: RootElement }}
|
|
146
|
+
>
|
|
147
|
+
<Container
|
|
148
|
+
as='span'
|
|
149
|
+
inline
|
|
150
|
+
flex
|
|
151
|
+
direction='row'
|
|
152
|
+
alignItems='center'
|
|
153
|
+
className={contentClassName}
|
|
154
|
+
>
|
|
155
|
+
{finalChildren}
|
|
156
|
+
</Container>
|
|
157
|
+
|
|
158
|
+
{loading && (
|
|
159
|
+
<Loader
|
|
160
|
+
variant='inherit'
|
|
161
|
+
className='absolute top-1/2 left-1/2 translate-x-[-50%] translate-y-[-50%]'
|
|
162
|
+
inline
|
|
163
|
+
size='small'
|
|
164
|
+
/>
|
|
165
|
+
)}
|
|
166
|
+
</MUIButtonBase>
|
|
167
|
+
)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
ButtonBase.defaultProps = {
|
|
171
|
+
as: 'button',
|
|
172
|
+
children: null,
|
|
173
|
+
disabled: false,
|
|
174
|
+
iconPosition: 'left',
|
|
175
|
+
loading: false,
|
|
176
|
+
onClick: noop,
|
|
177
|
+
type: 'button',
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
ButtonBase.displayName = 'ButtonBase'
|
|
181
|
+
|
|
182
|
+
export default ButtonBase
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const createCoreClassNames = ({
|
|
2
|
+
disabled,
|
|
3
|
+
loading,
|
|
4
|
+
}: {
|
|
5
|
+
disabled?: boolean
|
|
6
|
+
focused?: boolean
|
|
7
|
+
loading?: boolean
|
|
8
|
+
}): string[] => {
|
|
9
|
+
const classNames = [
|
|
10
|
+
'text-lg',
|
|
11
|
+
'inline-flex',
|
|
12
|
+
'items-center',
|
|
13
|
+
'justify-center',
|
|
14
|
+
'select-none',
|
|
15
|
+
'appearance-none',
|
|
16
|
+
'm-0',
|
|
17
|
+
'relative',
|
|
18
|
+
'normal-case',
|
|
19
|
+
'align-middle',
|
|
20
|
+
'transition-colors',
|
|
21
|
+
'duration-350',
|
|
22
|
+
'ease-out',
|
|
23
|
+
'shrink-0',
|
|
24
|
+
'outline-none',
|
|
25
|
+
'[&+&]:ml-4',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
if (!disabled && !loading) {
|
|
29
|
+
classNames.push('cursor-pointer')
|
|
30
|
+
} else {
|
|
31
|
+
classNames.push('cursor-default')
|
|
32
|
+
classNames.push('pointer-events-none')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return classNames
|
|
36
|
+
}
|
|
@@ -6,14 +6,14 @@ exports[`ButtonCheckbox renders 1`] = `
|
|
|
6
6
|
class="Picasso-root"
|
|
7
7
|
>
|
|
8
8
|
<label
|
|
9
|
-
|
|
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
|
|
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 {
|
|
14
|
-
import
|
|
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,39 +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
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
const variantClassNames = createVariantClassNames(variant, {
|
|
56
|
+
disabled,
|
|
57
|
+
focused,
|
|
58
|
+
hovered,
|
|
59
|
+
active,
|
|
60
|
+
})
|
|
68
61
|
|
|
69
|
-
const
|
|
62
|
+
const finalClassName = cx(
|
|
63
|
+
createRootClassNames({ responsive, active, disabled, focused, hovered }),
|
|
64
|
+
variantClassNames,
|
|
65
|
+
className
|
|
66
|
+
)
|
|
70
67
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
<
|
|
75
|
+
<ButtonBase
|
|
85
76
|
{...rest}
|
|
86
77
|
ref={ref}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}}
|
|
91
|
-
className={className}
|
|
92
|
-
size='small'
|
|
93
|
-
active={active}
|
|
94
|
-
hovered={hovered}
|
|
95
|
-
focused={focused}
|
|
78
|
+
loading={loading}
|
|
79
|
+
className={finalClassName}
|
|
80
|
+
contentClassName={contentClassName}
|
|
96
81
|
disabled={disabled}
|
|
97
82
|
/>
|
|
98
83
|
)
|
|
@@ -1,75 +1,127 @@
|
|
|
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
|
-
|
|
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
|
+
}
|