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

Support styled(Component)(({ theme }) => ` #31

Closed
oliviertassinari opened this issue May 28, 2024 · 5 comments
Closed

Support styled(Component)(({ theme }) => ` #31

oliviertassinari opened this issue May 28, 2024 · 5 comments

Comments

@oliviertassinari
Copy link

oliviertassinari commented May 28, 2024

I think it would be great to support this pattern styled(Component)(({ theme }) => . Today, it doesn't work:

Screen.Recording.2024-05-28.at.19.34.19.mov

This is pretty much the same request as in styled-components/vscode-styled-components#194.

@hudochenkov
Copy link
Owner

There could be more complexity hidden, that an example. Function could return template literals conditionally, or assign it to a variable, or use explicit return.

const StyledDiv = styled.div((props) => {
	if (props.isDisabled) {
		return `
			background-color: #f9f9f9;
		`;
	}

	return `
		background-color: blue;
	`;
});

const StyledDiv2 = styled.div((props) => {
	let styles = `
		background-color: blue;
	`;

	if (props.isDisabled) {
		styles = `
			background-color: #f9f9f9;
		`;
	}

	return styles;
});

Additionally, I doubt VS Code extension would highlight examples above. Not that it would be blocker, but worth to keep in mind.

@oliviertassinari
Copy link
Author

oliviertassinari commented Jun 2, 2024

Function could return template literals conditionally, or assign it to a variable, or use explicit return.

I guess it's for these use cases that we need to use the css helper.

I doubt VS Code extension would highlight examples above. Not that it would be blocker, but worth to keep in mind.

I see this not correctly highlighted/autocompleted by the VS Code extension:

const StyledDiv = styled.div((props) => {
	return `
		background-color: #f9f9f9;
	`;
});

but this one is correctly highlighted/autocompleted:

const StyledDiv = styled.div((props) => `
	background-color: #f9f9f9;
`);

@hudochenkov
Copy link
Owner

Alright, let's support only implicit return of template literal for an arrow function. I could take a look in a few weeks. PR is always welcome :)

hudochenkov added a commit that referenced this issue Nov 4, 2024
@hudochenkov
Copy link
Owner

Released in 0.7.0. Let me know, if there any issues.

@oliviertassinari
Copy link
Author

oliviertassinari commented Nov 4, 2024

Very cool, it seems to work

SCR-20241105-bocb

411 errors

Someone at http://github.com/mui/ will have fun to fix the codebase 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants