Skip to content

fix: use module import for deps in Block #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions js/FeedzyBlock/Editor.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/**
* WordPress dependencies
*/
const { __, sprintf } = wp.i18n;

const { apiRequest } = wp;

const { Component, Fragment } = wp.element;

const { ExternalLink, Placeholder, TextControl, Button, Spinner } =
wp.components;
import {
ExternalLink,
Placeholder,
TextControl,
Button,
Spinner,
} from '@wordpress/components';

import queryString from 'query-string';
import Inspector from './inspector';
import { __, sprintf } from '@wordpress/i18n';
import { apiFetch as apiRequest } from '@wordpress/api-fetch';
import { Component, Fragment } from '@wordpress/element';
import {
unescapeHTML,
filterData,
Expand Down
9 changes: 2 additions & 7 deletions js/FeedzyBlock/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// jshint ignore: start
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';

/**
* Block dependencies
Expand All @@ -7,13 +9,6 @@ import './style.scss';
import blockAttributes from './attributes.js';
import Editor from './Editor.js';

/**
* Internal block libraries
*/
const { __ } = wp.i18n;

const { registerBlockType } = wp.blocks;

/**
* Register block
*/
Expand Down
21 changes: 6 additions & 15 deletions js/FeedzyBlock/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
/**
* Block dependencies
*/
import { RawHTML } from '@wordpress/element';
import { Component, Fragment } from '@wordpress/element';
import RadioImageControl from './radio-image-control/';

/**
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal block libraries
*/
const { __ } = wp.i18n;

const { applyFilters } = wp.hooks;

const { InspectorControls, MediaUpload } = wp.blockEditor || wp.editor;

const { Component, Fragment } = wp.element;

const {
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { InspectorControls, MediaUpload } from '@wordpress/block-editor';
import {
BaseControl,
ExternalLink,
PanelBody,
Expand All @@ -34,7 +25,7 @@ const {
SelectControl,
ResponsiveWrapper,
Dashicon,
} = wp.components;
} from '@wordpress/components';

/**
* Create an Inspector Controls wrapper Component
Expand Down
97 changes: 55 additions & 42 deletions js/FeedzyBlock/radio-image-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,63 @@
* Block dependencies
*/
import './style.scss';
import { isEmpty } from 'lodash';
import { BaseControl } from '@wordpress/components';
import { withInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
*/
const { isEmpty } = lodash;

const { BaseControl } = wp.components;

const { withInstanceId } = wp.compose;


function RadioImageControl( { label, selected, help, instanceId, onChange, disabled, options = [] } ) {
const id = `inspector-radio-image-control-${ instanceId }`;
const onChangeValue = ( event ) => onChange( event.target.value );
function RadioImageControl({
label,
selected,
help,
instanceId,
onChange,
disabled,
options = [],
}) {
const id = `inspector-radio-image-control-${instanceId}`;
const onChangeValue = (event) => onChange(event.target.value);

return ! isEmpty( options ) && (
<BaseControl label={ label } id={ id } help={ help } className="components-radio-image-control feedzy-template">
<div className="components-radio-image-control__container">
{ options.map( ( option, index ) =>
<div
key={ `${ id }-${ index }` }
className="components-radio-image-control__option"
>
<input
id={ `${ id }-${ index }` }
className="components-radio-image-control__input"
type="radio"
name={ id }
value={ option.value }
onChange={ onChangeValue }
checked={ option.value === selected }
aria-describedby={ !! help ? `${ id }__help` : undefined }
disabled={ disabled }
/>
<label htmlFor={ `${ id }-${ index }` } title={ option.label }>
<img src={ option.src } />
<span class="image-clickable"></span>
</label>
<span>{ option.label }</span>
</div>
) }
</div>
</BaseControl>
return (
!isEmpty(options) && (
<BaseControl
label={label}
id={id}
help={help}
className="components-radio-image-control feedzy-template"
>
<div className="components-radio-image-control__container">
{options.map((option, index) => (
<div
key={`${id}-${index}`}
className="components-radio-image-control__option"
>
<input
id={`${id}-${index}`}
className="components-radio-image-control__input"
type="radio"
name={id}
value={option.value}
onChange={onChangeValue}
checked={option.value === selected}
aria-describedby={
!!help ? `${id}__help` : undefined
}
disabled={disabled}
/>
<label
htmlFor={`${id}-${index}`}
title={option.label}
>
<img src={option.src} />
<span className="image-clickable"></span>
</label>
<span>{option.label}</span>
</div>
))}
</div>
</BaseControl>
)
);
}

export default withInstanceId( RadioImageControl );
export default withInstanceId(RadioImageControl);
Loading