Skip to content
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

CustomGradientPicker GradientPicker component not working #36693

Closed
anver opened this issue Nov 21, 2021 · 5 comments
Closed

CustomGradientPicker GradientPicker component not working #36693

anver opened this issue Nov 21, 2021 · 5 comments
Labels
[Package] Components /packages/components

Comments

@anver
Copy link
Contributor

anver commented Nov 21, 2021

Description

I'm creating a new block plugin where I tried to use CustomGradientPicker from @wordpress/components but the component is not rendering and it throws an error

react_devtools_backend.js:2540 Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

I tried to use GradientPicker which is another Component but that too is not working and shows the same error. I tried to replace it with an InputControl and it works fine. All my imports are correct.

//@ts-ignore
import { GradientPicker } from '@wordpress/components';

type Props = { value: any; onChange: (v: string) => void };

const Gradient: React.FC = ({ value, onChange }) => {
const gradients = [
{
name: 'Vivid cyan blue to vivid purple',
gradient:
'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
slug: 'vivid-cyan-blue-to-vivid-purple',
},
];
return (
<GradientPicker
value="#f00"
onChange={() => true}
gradients={gradients}
/>
);
};

export default Gradient;

Step-by-step reproduction instructions

how to replicate

npx npx create-guten-block my-block
cd my-block
npm install @wordpress/components
npm start

Then inside the edit.js under src directory insert this code

import { __ } from '@wordpress/i18n';
import { CustomGradientPicker } from '@wordpress/components'
import { useBlockProps } from '@wordpress/block-editor';
import './editor.scss';

export default function Edit() {
const gradients = [
{
name: 'Vivid cyan blue to vivid purple',
gradient:
'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
slug: 'vivid-cyan-blue-to-vivid-purple',
},
];
return (
<GradientPicker
value="#f00"
onChange={() => true}
gradients={gradients}
/>
);
}

Screenshots, screen recording, code snippet

image

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@talldan
Copy link
Contributor

talldan commented Nov 23, 2021

@anver I'd check that GradientPicker is in the version of the components package you're using. It might be that you're currently using an earlier version.

Also there seem to be problems with the code example you provided. It imports CustomGradientPicker but tries to render GradientPicker.

@talldan talldan added the [Package] Components /packages/components label Nov 23, 2021
@anver
Copy link
Contributor Author

anver commented Nov 23, 2021

@anver I'd check that GradientPicker is in the version of the components package you're using. It might be that you're currently using an earlier version.

Also there seem to be problems with the code example you provided. It imports CustomGradientPicker but tries to render GradientPicker.

Hi @talldan I'm using the latest version and for the imports yes you are right, the imports are wrong but the code looks ok on my computer, it's just there for reference purposes, but you'll see when you create a simple react app and check it.

@talldan
Copy link
Contributor

talldan commented Nov 24, 2021

@anver I tested it out in CodeSandbox and it didn't have any issues:
https://codesandbox.io/s/gradientpickerexample-pgj27

@anver
Copy link
Contributor Author

anver commented Nov 24, 2021

This is my component

//@ts-ignore
import { GradientPicker } from '@wordpress/components';

type Props = { value: any; onChange: (v: string) => void };

const Gradient: React.FC<Props> = ({ value, onChange }) => {
	const handleChange = (value: any) => {
		console.log('value: ', value);
	};

	return (
		<div>
			<GradientPicker />
		</div>
	);
};

export default Gradient;

I have the latest version 19.0.5

still getting the same error, tried deleting node_modules folder and compiling fresh but in vain.
other components from the packages are working fine just CustomGradientPicker and GradientPicker is not

@talldan

@talldan
Copy link
Contributor

talldan commented Nov 25, 2021

I tested again in a local project and it still worked, so I definitely don't think this is a bug, but more an issue with your project. Here's the project if you're interested:
https://github.com/talldan/gradient-picker-test

I'd recommend locating the @wordpress/components folder in the node_modules folder and looking at the package.json file to check the version you have installed. Dependencies in node project are unfortunately not always straightforward. It might be that another dependency of yours is requiring an older version of the components package, and npm is resolving to install that. If that's the case I'd recommend updating those other dependencies too.

Anyway, I'll close the issue as I can't reproduce it. Happy to continue to help troubleshoot though, it'll be interesting to see if that test project works for you.

@talldan talldan closed this as completed Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components
Projects
None yet
Development

No branches or pull requests

2 participants