2022-12-22 15:01:01 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { Icon } from '@wordpress/icons';
|
|
|
|
import {
|
|
|
|
customerAccountStyle,
|
|
|
|
customerAccountStyleAlt,
|
|
|
|
} from '@woocommerce/icons';
|
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import type { BlockAttributes } from '@wordpress/blocks';
|
|
|
|
import { getSetting } from '@woocommerce/settings';
|
|
|
|
import { createInterpolateElement } from '@wordpress/element';
|
|
|
|
import {
|
|
|
|
PanelBody,
|
|
|
|
SelectControl,
|
|
|
|
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
|
|
|
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
|
|
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
|
|
|
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
|
|
ExternalLink,
|
|
|
|
} from '@wordpress/components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { DisplayStyle, IconStyle } from './types';
|
|
|
|
|
|
|
|
interface BlockSettingsProps {
|
|
|
|
attributes: BlockAttributes;
|
|
|
|
setAttributes: ( attrs: BlockAttributes ) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AccountSettingsLink = () => {
|
|
|
|
const accountSettingsUrl = `${ getSetting(
|
|
|
|
'adminUrl'
|
|
|
|
) }admin.php?page=wc-settings&tab=account`;
|
|
|
|
|
|
|
|
const linkText = createInterpolateElement(
|
2023-12-12 23:05:20 +00:00
|
|
|
`<a>${ __( 'Manage account settings', 'woocommerce' ) }</a>`,
|
2022-12-22 15:01:01 +00:00
|
|
|
{
|
|
|
|
a: <ExternalLink href={ accountSettingsUrl } />,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-02-16 09:07:44 +00:00
|
|
|
return (
|
|
|
|
<div className="wc-block-editor-customer-account__link">
|
|
|
|
{ linkText }
|
|
|
|
</div>
|
|
|
|
);
|
2022-12-22 15:01:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const BlockSettings = ( {
|
|
|
|
attributes,
|
|
|
|
setAttributes,
|
|
|
|
}: BlockSettingsProps ) => {
|
|
|
|
const { displayStyle, iconStyle } = attributes;
|
|
|
|
const displayIconStyleSelector = [
|
|
|
|
DisplayStyle.ICON_ONLY,
|
|
|
|
DisplayStyle.ICON_AND_TEXT,
|
|
|
|
].includes( displayStyle );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<InspectorControls key="inspector">
|
2023-04-12 17:12:54 +00:00
|
|
|
<PanelBody>
|
|
|
|
<AccountSettingsLink />
|
|
|
|
</PanelBody>
|
2023-12-12 23:05:20 +00:00
|
|
|
<PanelBody title={ __( 'Display settings', 'woocommerce' ) }>
|
2022-12-22 15:01:01 +00:00
|
|
|
<SelectControl
|
|
|
|
className="customer-account-display-style"
|
2023-12-12 23:05:20 +00:00
|
|
|
label={ __( 'Icon options', 'woocommerce' ) }
|
2022-12-22 15:01:01 +00:00
|
|
|
value={ displayStyle }
|
|
|
|
onChange={ ( value: DisplayStyle ) => {
|
|
|
|
setAttributes( { displayStyle: value } );
|
|
|
|
} }
|
|
|
|
help={ __(
|
|
|
|
'Choose if you want to include an icon with the customer account link.',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2022-12-22 15:01:01 +00:00
|
|
|
) }
|
|
|
|
options={ [
|
|
|
|
{
|
|
|
|
value: DisplayStyle.ICON_AND_TEXT,
|
2023-12-12 23:05:20 +00:00
|
|
|
label: __( 'Icon and text', 'woocommerce' ),
|
2022-12-22 15:01:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: DisplayStyle.TEXT_ONLY,
|
2023-12-12 23:05:20 +00:00
|
|
|
label: __( 'Text-only', 'woocommerce' ),
|
2022-12-22 15:01:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: DisplayStyle.ICON_ONLY,
|
2023-12-12 23:05:20 +00:00
|
|
|
label: __( 'Icon-only', 'woocommerce' ),
|
2022-12-22 15:01:01 +00:00
|
|
|
},
|
|
|
|
] }
|
|
|
|
/>
|
|
|
|
{ displayIconStyleSelector ? (
|
|
|
|
<ToggleGroupControl
|
2023-12-12 23:05:20 +00:00
|
|
|
label={ __( 'Display Style', 'woocommerce' ) }
|
2022-12-22 15:01:01 +00:00
|
|
|
value={ iconStyle }
|
|
|
|
onChange={ ( value: IconStyle ) =>
|
|
|
|
setAttributes( {
|
|
|
|
iconStyle: value,
|
|
|
|
} )
|
|
|
|
}
|
2023-04-13 12:36:38 +00:00
|
|
|
className="wc-block-editor-customer-account__icon-style-toggle"
|
2022-12-22 15:01:01 +00:00
|
|
|
>
|
|
|
|
<ToggleGroupControlOption
|
|
|
|
value={ IconStyle.DEFAULT }
|
|
|
|
label={
|
|
|
|
<Icon
|
|
|
|
icon={ customerAccountStyle }
|
|
|
|
size={ 16 }
|
|
|
|
className={ classNames(
|
2023-04-13 12:36:38 +00:00
|
|
|
'wc-block-editor-customer-account__icon-option',
|
2022-12-22 15:01:01 +00:00
|
|
|
{
|
|
|
|
active:
|
|
|
|
iconStyle === IconStyle.DEFAULT,
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<ToggleGroupControlOption
|
|
|
|
value={ IconStyle.ALT }
|
|
|
|
label={
|
|
|
|
<Icon
|
|
|
|
icon={ customerAccountStyleAlt }
|
2022-12-23 09:08:44 +00:00
|
|
|
size={ 20 }
|
2022-12-22 15:01:01 +00:00
|
|
|
className={ classNames(
|
2023-04-13 12:36:38 +00:00
|
|
|
'wc-block-editor-customer-account__icon-option',
|
2022-12-22 15:01:01 +00:00
|
|
|
{
|
|
|
|
active: iconStyle === IconStyle.ALT,
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</ToggleGroupControl>
|
|
|
|
) : null }
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
|
|
|
);
|
|
|
|
};
|