Skip to content

Commit d7474d8

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-lib into refactor/application-group-overview-table
2 parents 85648ba + df34dac commit d7474d8

25 files changed

+907
-13
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* vivek@devtron.ai @vikramdevtron

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.2.26-beta-2",
3+
"version": "0.2.29",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/ClipboardButton/ClipboardButton.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function ClipboardButton({
3434
content,
3535
copiedTippyText = 'Copied!',
3636
duration = 1000,
37-
trigger = false,
37+
trigger,
3838
setTrigger = noop,
3939
rootClassName = '',
4040
iconSize = 16,
@@ -45,6 +45,8 @@ export default function ClipboardButton({
4545
const handleTextCopied = () => {
4646
setCopied(true)
4747
}
48+
const isTriggerUndefined = typeof trigger === 'undefined'
49+
4850
const handleEnableTippy = () => setEnableTippy(true)
4951
const handleDisableTippy = () => setEnableTippy(false)
5052
const handleCopyContent = useCallback(
@@ -68,7 +70,7 @@ export default function ClipboardButton({
6870
}, [copied, duration, setTrigger])
6971

7072
useEffect(() => {
71-
if (trigger) {
73+
if (!isTriggerUndefined && trigger) {
7274
setCopied(true)
7375
handleCopyContent()
7476
}
@@ -86,7 +88,7 @@ export default function ClipboardButton({
8688
className={`dc__outline-none-imp p-0 flex dc__transparent--unstyled dc__no-border ${rootClassName}`}
8789
onMouseEnter={handleEnableTippy}
8890
onMouseLeave={handleDisableTippy}
89-
onClick={handleCopyContent}
91+
onClick={isTriggerUndefined && handleCopyContent}
9092
>
9193
{copied ? <Check className={iconClassName} /> : <ICCopy className={iconClassName} />}
9294
</button>

src/Common/Tooltip/Tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Tooltip = ({
2828
arrow={false}
2929
placement="top"
3030
{...rest}
31-
className={`default-tt ${wordBreak ? 'dc__word-break-all' : ''} dc__mxw-200 ${rest.className}`}
31+
className={`default-tt ${wordBreak ? 'dc__word-break-all' : ''} dc__mxw-200-imp ${rest.className}`}
3232
>
3333
{cloneElement(child, { ...child.props, ref: refCallback })}
3434
</TippyJS>
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import { ButtonHTMLAttributes, PropsWithChildren } from 'react'
2+
import { Link, LinkProps } from 'react-router-dom'
3+
import { Progressing } from '@Common/Progressing'
4+
import { Tooltip } from '@Common/Tooltip'
5+
import { ComponentSizeType } from '@Shared/constants'
6+
import { ButtonComponentType, ButtonProps, ButtonStyleType, ButtonVariantType } from './types'
7+
import { BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP, BUTTON_SIZE_TO_LOADER_SIZE_MAP } from './constants'
8+
import { getButtonDerivedClass } from './utils'
9+
import './button.scss'
10+
11+
const ButtonElement = ({
12+
component = ButtonComponentType.button,
13+
linkProps,
14+
buttonProps,
15+
onClick,
16+
...props
17+
}: PropsWithChildren<
18+
Omit<
19+
ButtonProps,
20+
| 'text'
21+
| 'variant'
22+
| 'size'
23+
| 'style'
24+
| 'startIcon'
25+
| 'endIcon'
26+
| 'showTooltip'
27+
| 'tooltipProps'
28+
| 'dataTestId'
29+
| 'isLoading'
30+
> & {
31+
className: string
32+
'data-testid': ButtonProps['dataTestId']
33+
}
34+
>) => {
35+
if (component === ButtonComponentType.link) {
36+
return (
37+
<Link
38+
{...linkProps}
39+
{...props}
40+
// Added the specific class to ensure that the link override is applied
41+
className={`${props.className} button__link ${props.disabled ? 'dc__disable-click' : ''}`}
42+
onClick={onClick as LinkProps['onClick']}
43+
/>
44+
)
45+
}
46+
47+
return (
48+
<button
49+
{...buttonProps}
50+
{...props}
51+
// eslint-disable-next-line react/button-has-type
52+
type={buttonProps?.type || 'button'}
53+
onClick={onClick as ButtonHTMLAttributes<HTMLButtonElement>['onClick']}
54+
/>
55+
)
56+
}
57+
58+
/**
59+
* Generic component for Button.
60+
* Should be used in combination of variant, size and style.
61+
*
62+
* @example Default button
63+
* ```tsx
64+
* <Button text="Hello World" />
65+
* ```
66+
*
67+
* @example Custom variant
68+
* ```tsx
69+
* <Button text="Hello World" variant={ButtonVariantType.secondary} />
70+
* ```
71+
*
72+
* @example Custom size
73+
* ```tsx
74+
* <Button text="Hello World" size={ComponentSizeType.medium} />
75+
* ```
76+
*
77+
* @example Custom style
78+
* ```tsx
79+
* <Button text="Hello World" style={ButtonStyleType.positive} />
80+
* ```
81+
*
82+
* @example Disabled state
83+
* ```tsx
84+
* <Button text="Hello World" disabled />
85+
* ```
86+
*
87+
* @example Loading state
88+
* ```tsx
89+
* <Button text="Hello World" isLoading />
90+
* ```
91+
*
92+
* @example With start icon
93+
* ```tsx
94+
* <Button text="Hello World" startIcon={<ICCube />} />
95+
* ```
96+
*
97+
* @example With end icon
98+
* ```tsx
99+
* <Button text="Hello World" endIcon={<ICCube />} />
100+
* ```
101+
*
102+
* @example With tippy
103+
* ```tsx
104+
* <Button text="Hello World" showTippy tippyContent="Tippy content" />
105+
* ```
106+
*
107+
* @example With onClick
108+
* ```tsx
109+
* <Button text="Hello World" onClick={noop} />
110+
* ```
111+
*
112+
* @example Link component
113+
* ```tsx
114+
* <Button component={ButtonComponentType.link} linkProps={{ to: '#' }} />
115+
* ```
116+
*/
117+
const Button = ({
118+
dataTestId,
119+
text,
120+
variant = ButtonVariantType.primary,
121+
size = ComponentSizeType.large,
122+
style = ButtonStyleType.default,
123+
startIcon = null,
124+
endIcon = null,
125+
disabled = false,
126+
isLoading = false,
127+
showTooltip = false,
128+
tooltipProps = {},
129+
...props
130+
}: ButtonProps) => {
131+
const isDisabled = disabled || isLoading
132+
const iconClass = `dc__no-shrink flex dc__fill-available-space ${BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP[size]}`
133+
134+
return (
135+
<Tooltip {...tooltipProps} alwaysShowTippyOnHover={showTooltip && !!tooltipProps?.content}>
136+
<div>
137+
<ButtonElement
138+
{...props}
139+
disabled={isDisabled}
140+
className={`br-4 flex cursor dc__mnw-100 dc__tab-focus dc__position-rel dc__capitalize ${getButtonDerivedClass({ size, variant, style, isLoading })} ${isDisabled ? 'dc__disabled' : ''}`}
141+
data-testid={dataTestId}
142+
>
143+
{startIcon && <span className={iconClass}>{startIcon}</span>}
144+
<span className="dc__mxw-150 dc__align-left dc__truncate">{text}</span>
145+
{endIcon && <span className={iconClass}>{endIcon}</span>}
146+
{isLoading && <Progressing size={BUTTON_SIZE_TO_LOADER_SIZE_MAP[size]} />}
147+
</ButtonElement>
148+
</div>
149+
</Tooltip>
150+
)
151+
}
152+
153+
export default Button

0 commit comments

Comments
 (0)