芝麻web文件管理V1.00
编辑当前文件:/home/r5772835/public_html/ycreate.jp/wp-content/plugins/snow-monkey-blocks/src/blocks/btn/edit.js
import classnames from 'classnames'; import { Popover, SelectControl, ToggleControl, ToolbarButton, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { BlockControls, ContrastChecker, InspectorControls, RichText, useBlockProps, __experimentalPanelColorGradientSettings as PanelColorGradientSettings, __experimentalLinkControl as LinkControl, __experimentalBorderRadiusControl as BorderRadiusControl, } from '@wordpress/block-editor'; import { useMergeRefs } from '@wordpress/compose'; import { useState, useEffect, useRef } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { link as linkIcon, linkOff as linkOffIcon } from '@wordpress/icons'; import metadata from './block.json'; export default function ( { attributes, setAttributes, className, isSelected, clientId, } ) { const { content, url, target, modifier, borderRadius, backgroundColor, backgroundGradientColor, textColor, wrap, } = attributes; const [ isEditingURL, setIsEditingURL ] = useState( false ); const isURLSet = !! url; const opensInNewTab = target === '_blank'; // Use internal state instead of a ref to make sure that the component // re-renders when the popover's anchor updates. const [ popoverAnchor, setPopoverAnchor ] = useState( null ); // At old version, using .u-clearfix. but no need now. useEffect( () => { if ( !! attributes.className ) { setAttributes( { className: attributes.className.replace( 'u-clearfix', '' ), } ); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [] ); const wrapperClasses = classnames( 'smb-btn-wrapper', className, { [ `smb-btn-wrapper--${ modifier }` ]: !! modifier, } ); const classes = classnames( 'smb-btn', { [ `smb-btn--${ modifier }` ]: !! modifier, 'smb-btn--wrap': wrap, } ); const styles = { '--smb-btn--background-color': backgroundColor || undefined, '--smb-btn--background-image': backgroundGradientColor || undefined, '--smb-btn--border-radius': String( borderRadius ).match( /^\d+$/ ) ? `${ borderRadius }px` : borderRadius, '--smb-btn--color': textColor || undefined, }; if ( !! attributes.className && attributes.className.split( ' ' ).includes( 'is-style-ghost' ) ) { styles[ '--smb-btn--style--ghost--border-color' ] = backgroundColor || undefined; } const ref = useRef(); const richTextRef = useRef(); const blockProps = useBlockProps( { className: wrapperClasses, ref: useMergeRefs( [ setPopoverAnchor, ref ] ), } ); const unlink = () => { setAttributes( { url: undefined, target: undefined, } ); setIsEditingURL( false ); }; return ( <>
modifier !== metadata.attributes.modifier.default } isShownByDefault label={ __( 'Button size', 'snow-monkey-blocks' ) } onDeselect={ () => setAttributes( { modifier: metadata.attributes.modifier.default, } ) } >
setAttributes( { modifier: value, } ) } options={ [ { value: '', label: __( 'Normal size', 'snow-monkey-blocks' ), }, { value: 'little-wider', label: __( 'Litle wider', 'snow-monkey-blocks' ), }, { value: 'wider', label: __( 'Wider', 'snow-monkey-blocks' ), }, { value: 'more-wider', label: __( 'More wider', 'snow-monkey-blocks' ), }, { value: 'full', label: __( 'Full size', 'snow-monkey-blocks' ), }, ] } />
wrap !== metadata.attributes.wrap.default } isShownByDefault label={ __( 'Wrap', 'snow-monkey-blocks' ) } onDeselect={ () => setAttributes( { wrap: metadata.attributes.wrap.default, } ) } >
setAttributes( { wrap: value, } ) } />
setAttributes( { backgroundColor: value, } ), gradientValue: backgroundGradientColor, onGradientChange: ( value ) => setAttributes( { backgroundGradientColor: value, } ), label: __( 'Background color', 'snow-monkey-blocks' ), }, { colorValue: textColor, onColorChange: ( value ) => setAttributes( { textColor: value, } ), label: __( 'Text color', 'snow-monkey-blocks' ), }, ] } __experimentalIsRenderedInSidebar >
borderRadius !== metadata.attributes.borderRadius.default } isShownByDefault label={ __( 'Border radius', 'snow-monkey-blocks' ) } onDeselect={ () => setAttributes( { borderRadius: metadata.attributes.borderRadius.default, } ) } panelId={ clientId } >
{ setAttributes( { borderRadius: value } ); } } />
setAttributes( { content: value, } ) } withoutInteractiveFormatting={ true } ref={ richTextRef } />
{ ! isURLSet && (
{ event.preventDefault(); setIsEditingURL( true ); } } /> ) } { isURLSet && (
) }
{ isSelected && ( isEditingURL || isURLSet ) && (
{ setIsEditingURL( false ); richTextRef.current?.focus(); } } >
{ setAttributes( { url: newUrl, target: ! newOpensInNewTab ? '_self' : '_blank', } ); } } onRemove={ () => { unlink(); richTextRef.current?.focus(); } } forceIsEditingLink={ isEditingURL } />
) } > ); }