Skip to content

Commit b9960ad

Browse files
Merge pull request #128 from devtron-labs/feat/button-with-selector
feat: button with selector
2 parents 790863f + f06c989 commit b9960ad

File tree

7 files changed

+80
-0
lines changed

7 files changed

+80
-0
lines changed

src/Assets/Icon/ic-open-box.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Common/Constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const URLS = {
2828
GETTING_STARTED: 'getting-started',
2929
STACK_MANAGER_ABOUT: '/stack-manager/about',
3030
APP_LIST_HELM: 'h',
31+
CREATE: '/create',
32+
RELEASES: '/releases',
3133
}
3234

3335
export const ROUTES = {
@@ -433,6 +435,7 @@ export const ZERO_TIME_STRING = '0001-01-01T00:00:00Z'
433435
export const EXCLUDED_FALSY_VALUES = [undefined, null, '', NaN] as const
434436

435437
export const API_STATUS_CODES = {
438+
BAD_REQUEST: 400,
436439
UNAUTHORIZED: 401,
437440
PERMISSION_DENIED: 403,
438441
NOT_FOUND: 404,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { useState } from 'react'
2+
import { ReactComponent as ICDropdown } from '../../../Assets/Icon/ic-chevron-down.svg'
3+
import { PopupMenu } from '../../../Common'
4+
import { ButtonWithSelectorProps } from './types'
5+
import './buttonWithSelector.scss'
6+
7+
/**
8+
* Button With Selector
9+
* @param content Content to show in button
10+
* @param onClick Handler Function for button click
11+
* @param children Dropdown Content
12+
* @param className Other Classes to be applied
13+
*
14+
* @example
15+
* ```tsx
16+
* <ButtonWithSelector content='Create Job' onClick={() => {}} className=''>
17+
* {dropdownOptions}
18+
* </ButtonWithSelector>
19+
* ```
20+
*/
21+
const ButtonWithSelector = ({
22+
content,
23+
onClick,
24+
children,
25+
className = '',
26+
popUpBodyClassName = '',
27+
showPopUp = true,
28+
}: ButtonWithSelectorProps) => {
29+
const [isMenuOpen, setIsMenuOpen] = useState<boolean>(false)
30+
31+
return (
32+
<div className="flexbox">
33+
<button
34+
className={`cta flex h-28 ${showPopUp ? 'dc__no-right-radius' : ''} dc__no-border-imp fs-12 fw-6 lh-20-imp ${className}`}
35+
type="button"
36+
onClick={onClick}
37+
>
38+
{content}
39+
</button>
40+
{showPopUp && (
41+
<PopupMenu autoClose autoPosition onToggleCallback={setIsMenuOpen}>
42+
<PopupMenu.Button rootClassName="flex dc__transparent p-8 w-28 bcb-5 dc__right-radius-4 dc__no-left-radius dc__no-top-border dc__no-bottom-border dc__no-right-border button-with-selector">
43+
<ICDropdown
44+
className="icon-dim-12 fcn-0 dc__no-shrink rotate"
45+
style={{ ['--rotateBy' as any]: isMenuOpen ? '180deg' : '0deg' }}
46+
/>
47+
</PopupMenu.Button>
48+
<PopupMenu.Body rootClassName={`pt-4 pb-4 dc__border dc__overflow-hidden ${popUpBodyClassName}`}>
49+
{children}
50+
</PopupMenu.Body>
51+
</PopupMenu>
52+
)}
53+
</div>
54+
)
55+
}
56+
57+
export default ButtonWithSelector
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.button-with-selector {
2+
&:hover, &:active, &:focus {
3+
border: 1px solid var(--N200);
4+
}
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ButtonWithSelector } from './ButtonWithSelector'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ReactNode } from 'react'
2+
3+
export interface ButtonWithSelectorProps {
4+
content: ReactNode
5+
onClick: () => void
6+
children: ReactNode
7+
className?: string
8+
popUpBodyClassName?: string
9+
showPopUp?: boolean
10+
}

src/Shared/Components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './EditableTextArea'
1515
export * from './Header'
1616
export * from './AnnouncementBanner'
1717
export * from './ButtonWithLoader'
18+
export * from './ButtonWithSelector'

0 commit comments

Comments
 (0)