PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.0.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.0.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / src / admin / components / common / OptimizationButton.js

OptimizationButton.js in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.0.0, at src/admin/components/common/OptimizationButton.js

118 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * OptimizationButton Component
3 *
4 * Standardized optimization button component extracted from Site Identity patterns.
5 * Supports different optimization types (AI, rule-based, validation, testing, generation)
6 * with consistent styling and behavior across all Essential SEO tabs.
7 *
8 * @package ThinkRank
9 * @since 1.0.0
10 */
11
12 import { Button } from '@wordpress/components';
13 import { __ } from '@wordpress/i18n';
14
15 /**
16 * OptimizationButton Component
17 *
18 * @param {Object} props Component props
19 * @param {string} props.type Button type: 'ai', 'rule', 'validate', 'test', 'generate'
20 * @param {Function} props.onClick Click handler function
21 * @param {boolean} props.isBusy Loading/busy state
22 * @param {boolean} props.disabled Disabled state
23 * @param {string} props.label Custom button label (overrides default)
24 * @param {string} props.loadingLabel Custom loading label (overrides default)
25 * @param {string} props.size Button size: 'small', 'default', 'large'
26 * @param {string} props.className Additional CSS classes
27 * @param {Object} props.rest Additional props passed to Button component
28 */
29 const OptimizationButton = ({
30 type = 'rule',
31 onClick,
32 isBusy = false,
33 disabled = false,
34 label,
35 loadingLabel,
36 size = 'default',
37 className = '',
38 ...rest
39 }) => {
40 /**
41 * Get button configuration based on type
42 * Extracted from Site Identity getOptimizationButtonConfig pattern
43 */
44 const getButtonConfig = () => {
45 const configs = {
46 ai: {
47 variant: 'secondary',
48 defaultLabel: __('AI Optimize', 'thinkrank'),
49 defaultLoadingLabel: __('AI Optimizing...', 'thinkrank'),
50 className: 'thinkrank-btn-ai'
51 },
52 rule: {
53 variant: 'secondary',
54 defaultLabel: __('Optimize', 'thinkrank'),
55 defaultLoadingLabel: __('Optimizing...', 'thinkrank'),
56 className: 'thinkrank-btn-rule'
57 },
58 validate: {
59 variant: 'secondary',
60 defaultLabel: __('Validate', 'thinkrank'),
61 defaultLoadingLabel: __('Validating...', 'thinkrank'),
62 className: 'thinkrank-btn-validate'
63 },
64 test: {
65 variant: 'secondary',
66 defaultLabel: __('Test Connection', 'thinkrank'),
67 defaultLoadingLabel: __('Testing...', 'thinkrank'),
68 className: 'thinkrank-btn-test'
69 },
70 generate: {
71 variant: 'secondary',
72 defaultLabel: __('Generate', 'thinkrank'),
73 defaultLoadingLabel: __('Generating...', 'thinkrank'),
74 className: 'thinkrank-btn-generate'
75 }
76 };
77
78 return configs[type] || configs.rule;
79 };
80
81 const config = getButtonConfig();
82
83 // Combine CSS classes following Site Identity pattern
84 const buttonClasses = [
85 config.className,
86 className
87 ].filter(Boolean).join(' ');
88
89 /**
90 * Handle click event with loading state protection
91 * Following Site Identity onClick pattern
92 */
93 const handleClick = (event) => {
94 if (!isBusy && !disabled && onClick) {
95 onClick(event);
96 }
97 };
98
99 return (
100 <Button
101 variant={config.variant}
102 onClick={handleClick}
103 isBusy={isBusy}
104 disabled={disabled || isBusy}
105 size={size}
106 className={buttonClasses}
107 {...rest}
108 >
109 {isBusy
110 ? (loadingLabel || config.defaultLoadingLabel)
111 : (label || config.defaultLabel)
112 }
113 </Button>
114 );
115 };
116
117 export default OptimizationButton;
118