-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
479cc56
commit e40e68e
Showing
5 changed files
with
219 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/netmanager-app/components/NetManagerMap/components/Button/TabButtons.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import ChevronDownIcon from '@/icons/Common/chevron_downIcon'; | ||
import PropTypes from 'prop-types'; | ||
import Spinner from '../Spinner'; | ||
|
||
/** | ||
* TabButtons Component | ||
* | ||
* A versatile button component that can display icons, text, and handle dropdowns. | ||
* It also supports loading and disabled states. | ||
* | ||
* @param {object} props - Component props | ||
* @returns {JSX.Element} Rendered component | ||
*/ | ||
const TabButtons = ({ | ||
type = 'button', | ||
Icon, | ||
btnText, | ||
btnStyle = 'border-grey-750 px-4 py-2 bg-white', | ||
dropdown = false, | ||
onClick, | ||
id, | ||
tabRef, | ||
isField = true, | ||
isLoading = false, | ||
disabled = false, | ||
}) => { | ||
return ( | ||
<button | ||
ref={tabRef} | ||
id={id} | ||
type={type} | ||
onClick={onClick} | ||
disabled={disabled || isLoading} | ||
aria-disabled={disabled || isLoading} | ||
className={`transition transform active:scale-95 border rounded-xl shadow-sm flex items-center justify-between cursor-pointer ${ | ||
disabled || isLoading ? 'opacity-50 cursor-not-allowed' : '' | ||
} ${btnStyle}`} | ||
> | ||
{/* Loading Spinner */} | ||
{isLoading ? ( | ||
<Spinner width={20} height={20} /> | ||
) : ( | ||
Icon && ( | ||
<span className="p-[2px] md:p-0"> | ||
{typeof Icon === 'function' ? <Icon /> : Icon} | ||
</span> | ||
) | ||
)} | ||
|
||
{/* Button Text */} | ||
{btnText && ( | ||
<span | ||
className={`text-sm text-start w-full px-2 font-medium capitalize ${ | ||
Icon && isField ? 'hidden md:inline-block' : '' | ||
}`} | ||
> | ||
{btnText} | ||
</span> | ||
)} | ||
|
||
{/* Dropdown Icon */} | ||
{dropdown && <ChevronDownIcon />} | ||
</button> | ||
); | ||
}; | ||
|
||
TabButtons.propTypes = { | ||
type: PropTypes.string, | ||
Icon: PropTypes.oneOfType([PropTypes.func, PropTypes.element]), | ||
btnText: PropTypes.string, | ||
isField: PropTypes.bool, | ||
btnStyle: PropTypes.string, | ||
dropdown: PropTypes.bool, | ||
onClick: PropTypes.func, | ||
id: PropTypes.string, | ||
tabRef: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.shape({ current: PropTypes.any }), | ||
]), | ||
isLoading: PropTypes.bool, | ||
disabled: PropTypes.bool, | ||
}; | ||
|
||
export default TabButtons; |
79 changes: 79 additions & 0 deletions
79
src/netmanager-app/components/NetManagerMap/components/Button/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react'; | ||
|
||
const Button = ({ | ||
onClick, | ||
className = '', | ||
path, | ||
children, | ||
dataTestId, | ||
disabled = false, | ||
type = 'button', | ||
variant = 'filled', | ||
color, | ||
bgColor, | ||
Icon, | ||
paddingStyles = 'py-2 px-4 shadow-sm', | ||
...rest | ||
}) => { | ||
// Determine styles based on the variant | ||
const variantStyles = { | ||
filled: { | ||
backgroundColor: bgColor || 'bg-blue-600', | ||
textColor: color || 'text-white', | ||
border: '', | ||
}, | ||
outlined: { | ||
backgroundColor: bgColor || 'bg-white', | ||
textColor: color || 'text-black', | ||
border: 'border b-secondary-neutral-light-100', | ||
}, | ||
text: { | ||
backgroundColor: 'bg-transparent', | ||
textColor: color || 'text-secondary-neutral-light-600', | ||
border: '', | ||
}, | ||
disabled: { | ||
backgroundColor: 'bg-secondary-neutral-light-100', | ||
textColor: 'text-secondary-neutral-light-600', | ||
border: '', | ||
}, | ||
primaryText: { | ||
backgroundColor: 'bg-transparent', | ||
textColor: color || 'text-blue-600', | ||
border: '', | ||
}, | ||
}; | ||
|
||
const { backgroundColor, textColor, border } = | ||
variantStyles[variant] || variantStyles.filled; | ||
|
||
// Combine all styles into a button class | ||
const buttonClass = `flex justify-center items-center cursor-pointer ${paddingStyles} rounded-xl sm:gap-1 ${className} ${textColor} ${backgroundColor} ${border} transition transform active:scale-95 ${disabled ? 'cursor-not-allowed opacity-50' : ''}`; | ||
|
||
// Render tag if `path` is provided | ||
if (path) { | ||
return ( | ||
<a href={path} className={buttonClass} data-testid={dataTestId} {...rest}> | ||
{Icon && <Icon className="w-4 h-4 mr-2" />} | ||
{children} | ||
</a> | ||
); | ||
} | ||
|
||
// Render button element if `path` is not provided | ||
return ( | ||
<button | ||
onClick={onClick} | ||
className={buttonClass} | ||
data-testid={dataTestId} | ||
type={type} | ||
disabled={disabled} | ||
{...rest} | ||
> | ||
{Icon && <Icon className="w-4 h-4 mr-2" />} {/* Icon before text */} | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default Button; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters