| 1 |
/** |
| 2 |
* AI Button Component |
| 3 |
* |
| 4 |
* Standardized button component for AI-powered features |
| 5 |
* Includes sparkle icon and consistent loading states |
| 6 |
* |
| 7 |
* @package ThinkRank |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
import { Button, Spinner } from '@wordpress/components'; |
| 12 |
import { __ } from '@wordpress/i18n'; |
| 13 |
|
| 14 |
/** |
| 15 |
* AI Button Component |
| 16 |
* |
| 17 |
* @param {Object} props Component props |
| 18 |
* @param {string} props.children Button text |
| 19 |
* @param {boolean} props.isLoading Loading state |
| 20 |
* @param {string} props.variant Button variant (primary, secondary) |
| 21 |
* @param {string} props.size Button size (small, medium, large) |
| 22 |
* @param {boolean} props.showSparkle Show sparkle icon |
| 23 |
* @param {string} props.className Additional CSS classes |
| 24 |
* @param {Function} props.onClick Click handler |
| 25 |
* @param {boolean} props.disabled Disabled state |
| 26 |
* @param {Object} props.rest Additional props |
| 27 |
*/ |
| 28 |
const AIButton = ({ |
| 29 |
children, |
| 30 |
isLoading = false, |
| 31 |
variant = 'primary', |
| 32 |
size = 'medium', |
| 33 |
showSparkle = true, |
| 34 |
className = '', |
| 35 |
onClick, |
| 36 |
disabled = false, |
| 37 |
...rest |
| 38 |
}) => { |
| 39 |
const buttonClasses = [ |
| 40 |
'thinkrank-ai-button', |
| 41 |
`thinkrank-ai-button--${variant}`, |
| 42 |
`thinkrank-ai-button--${size}`, |
| 43 |
className |
| 44 |
].filter(Boolean).join(' '); |
| 45 |
|
| 46 |
const handleClick = (event) => { |
| 47 |
if (!isLoading && !disabled && onClick) { |
| 48 |
onClick(event); |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
return ( |
| 53 |
<Button |
| 54 |
className={buttonClasses} |
| 55 |
disabled={isLoading || disabled} |
| 56 |
onClick={handleClick} |
| 57 |
isPrimary={variant === 'primary'} |
| 58 |
isSecondary={variant === 'secondary'} |
| 59 |
{...rest} |
| 60 |
> |
| 61 |
{isLoading ? ( |
| 62 |
<> |
| 63 |
<Spinner /> |
| 64 |
{__('Processing...', 'thinkrank')} |
| 65 |
</> |
| 66 |
) : ( |
| 67 |
<> |
| 68 |
{showSparkle && ( |
| 69 |
<span className="sparkle-icon" aria-hidden="true">✨</span> |
| 70 |
)} |
| 71 |
{children} |
| 72 |
</> |
| 73 |
)} |
| 74 |
</Button> |
| 75 |
); |
| 76 |
}; |
| 77 |
|
| 78 |
export default AIButton; |
| 79 |
|