@@ -17,10 +17,31 @@ import { useBlockAttributesContext, useBlockSetAttributesContext } from '~stacka
1717 * WordPress dependencies
1818 */
1919import { __ } from '@wordpress/i18n'
20+ import { ExternalLink } from '@wordpress/components'
2021import { INVALID_HTML_ATTRIBUTES } from '.'
2122
22- export const Edit = ( ) => {
23- const customAttributes = useBlockAttributesContext ( attributes => attributes . customAttributes )
23+ const CustomAttributesHelp = ( { hasLink } ) => {
24+ return < p className = "components-base-control__help" >
25+ { hasLink
26+ ? __ ( 'You can type in custom HTML attributes for this block or its link in the fields above. Examples:' , i18n )
27+ : __ ( 'You can type in custom HTML attributes for this block in the field above. Example:' , i18n ) }
28+ < br />
29+ < code > data-id="my-title"</ code >
30+ { hasLink && < >
31+ < br />
32+ < code > aria-label="Open product details"</ code >
33+ </ > }
34+ </ p >
35+ }
36+
37+ export const Edit = props => {
38+ const {
39+ customAttributes,
40+ linkCustomAttributes,
41+ } = useBlockAttributesContext ( attributes => ( {
42+ customAttributes : attributes . customAttributes ,
43+ linkCustomAttributes : props . linkAttributeName ? attributes [ props . linkAttributeName ] : undefined ,
44+ } ) )
2445 const setAttributes = useBlockSetAttributesContext ( )
2546
2647 return (
@@ -30,12 +51,30 @@ export const Edit = () => {
3051 id = "custom-attributes"
3152 >
3253 < CustomAttributesControl
33- label = { __ ( 'Custom Attributes' , i18n ) }
54+ label = { props . linkAttributeName ? __ ( 'Block Custom Attributes' , i18n ) : __ ( 'Custom Attributes' , i18n ) }
3455 value = { customAttributes }
3556 invalidHtmlAttributes = { INVALID_HTML_ATTRIBUTES }
3657 onChange = { customAttributes => setAttributes ( { customAttributes } ) }
3758 />
59+ { props . linkAttributeName && < CustomAttributesControl
60+ label = { __ ( 'Link Custom Attributes' , i18n ) }
61+ value = { linkCustomAttributes }
62+ invalidHtmlAttributes = { INVALID_HTML_ATTRIBUTES }
63+ onChange = { linkCustomAttributes => setAttributes ( { [ props . linkAttributeName ] : linkCustomAttributes } ) }
64+ />
65+ }
66+ < CustomAttributesHelp hasLink = { ! ! props . linkAttributeName } />
67+ < ExternalLink
68+ href = "https://docs.wpstackable.com/article/461-how-to-use-custom-attributes?utm_source=inspector& utm_campaign = learnmore & utm_medium = gutenberg "
69+ target = "_docs"
70+ >
71+ { __ ( 'Learn more about Custom Attributes' , i18n ) }
72+ </ ExternalLink >
3873 </ PanelAdvancedSettings >
3974 </ InspectorAdvancedControls >
4075 )
4176}
77+
78+ Edit . defaultProps = {
79+ linkAttributeName : '' ,
80+ }
0 commit comments