2024-12-08 09:33:49 +01:00
|
|
|
import { Button } from '@wordpress/components';
|
2025-01-21 18:57:36 +01:00
|
|
|
|
|
|
|
import { Header, Title, Action, Description } from '../Elements';
|
|
|
|
import SettingsBlock from '../SettingsBlock';
|
2024-12-08 09:33:49 +01:00
|
|
|
import TitleBadge from '../TitleBadge';
|
|
|
|
|
|
|
|
const FeatureSettingsBlock = ( { title, description, ...props } ) => {
|
|
|
|
const printNotes = () => {
|
|
|
|
const notes = props.actionProps?.notes;
|
|
|
|
if ( ! notes || ( Array.isArray( notes ) && notes.length === 0 ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2025-01-24 16:29:03 +01:00
|
|
|
<span className="ppcp--item-notes">
|
2024-12-17 15:03:15 +01:00
|
|
|
{ notes.map( ( note, index ) => (
|
|
|
|
<span key={ index }>{ note }</span>
|
|
|
|
) ) }
|
|
|
|
</span>
|
2024-12-08 09:33:49 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2025-01-24 16:10:28 +01:00
|
|
|
const FeatureButton = ( {
|
|
|
|
className,
|
|
|
|
variant,
|
|
|
|
text,
|
|
|
|
isBusy,
|
|
|
|
url,
|
|
|
|
urls,
|
|
|
|
onClick,
|
|
|
|
} ) => {
|
|
|
|
const buttonProps = {
|
|
|
|
className,
|
|
|
|
isBusy,
|
|
|
|
variant,
|
|
|
|
};
|
2025-01-02 13:55:32 +01:00
|
|
|
|
2025-01-24 16:10:28 +01:00
|
|
|
if ( url || urls ) {
|
|
|
|
buttonProps.href = urls ? urls.live : url;
|
|
|
|
buttonProps.target = '_blank';
|
|
|
|
}
|
|
|
|
if ( ! buttonProps.href ) {
|
|
|
|
buttonProps.onClick = onClick;
|
2025-01-22 18:23:46 +01:00
|
|
|
}
|
|
|
|
|
2025-01-24 16:10:28 +01:00
|
|
|
return <Button { ...buttonProps }>{ text }</Button>;
|
2025-01-02 13:55:32 +01:00
|
|
|
};
|
|
|
|
|
2025-01-23 19:44:39 +04:00
|
|
|
const renderDescription = () => {
|
|
|
|
return (
|
|
|
|
<span
|
|
|
|
className="ppcp-r-feature-item__description ppcp-r-settings-block__feature__description"
|
|
|
|
dangerouslySetInnerHTML={ { __html: description } }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-12-08 09:33:49 +01:00
|
|
|
return (
|
2024-12-17 15:03:15 +01:00
|
|
|
<SettingsBlock { ...props } className="ppcp-r-settings-block__feature">
|
|
|
|
<Header>
|
|
|
|
<Title>
|
|
|
|
{ title }
|
|
|
|
{ props.actionProps?.enabled && (
|
|
|
|
<TitleBadge { ...props.actionProps?.badge } />
|
|
|
|
) }
|
|
|
|
</Title>
|
|
|
|
<Description className="ppcp-r-settings-block__feature__description">
|
2025-01-23 19:44:39 +04:00
|
|
|
{ renderDescription() }
|
2024-12-17 15:03:15 +01:00
|
|
|
{ printNotes() }
|
|
|
|
</Description>
|
|
|
|
</Header>
|
|
|
|
<Action>
|
2025-01-24 16:29:03 +01:00
|
|
|
<div className="ppcp--action-buttons">
|
2025-01-24 16:10:28 +01:00
|
|
|
{ props.actionProps?.buttons.map(
|
|
|
|
( {
|
|
|
|
class: className,
|
|
|
|
type,
|
|
|
|
text,
|
|
|
|
url,
|
|
|
|
urls,
|
|
|
|
onClick,
|
|
|
|
} ) => (
|
|
|
|
<FeatureButton
|
|
|
|
key={ text }
|
|
|
|
className={ className }
|
|
|
|
variant={ type }
|
|
|
|
text={ text }
|
|
|
|
isBusy={ props.actionProps.isBusy }
|
|
|
|
url={ url }
|
|
|
|
urls={ urls }
|
|
|
|
onClick={ onClick }
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
) }
|
2024-12-17 15:03:15 +01:00
|
|
|
</div>
|
|
|
|
</Action>
|
|
|
|
</SettingsBlock>
|
2024-12-08 09:33:49 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FeatureSettingsBlock;
|