postcss-styled-syntax icon indicating copy to clipboard operation
postcss-styled-syntax copied to clipboard

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

Open oliviertassinari opened this issue 1 year ago • 3 comments

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

https://github.com/hudochenkov/postcss-styled-syntax/assets/3165635/bd24c10d-8f8f-4012-8e76-7b4c71f0f61a

This is pretty much the same request as in https://github.com/styled-components/vscode-styled-components/issues/194.

oliviertassinari avatar May 28 '24 17:05 oliviertassinari

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.

hudochenkov avatar May 31 '24 00:05 hudochenkov

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;
`);

oliviertassinari avatar Jun 02 '24 14:06 oliviertassinari

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 avatar Jun 02 '24 22:06 hudochenkov

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

hudochenkov avatar Nov 04 '24 22:11 hudochenkov

Very cool, it seems to work

SCR-20241105-bocb

411 errors

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

oliviertassinari avatar Nov 04 '24 23:11 oliviertassinari