tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
482 stars 38 forks source link

Support the `style:property` directive #267

Closed TheOnlyTails closed 1 year ago

TheOnlyTails commented 2 years ago

Svelte was recently updated with a new directive: style:property={value}, which lets you set a CSS property of an element.

Some things which could be considered:

https://svelte.dev/docs#template-syntax-element-directives-style-property

Update: style: has now been officially released in Svelte 3.46.

TheOnlyTails commented 2 years ago

Another idea - we should have highlighting and validation on the actual values, based on the property.

tomblachut commented 2 years ago

@TheOnlyTails what's the difference between your "validation on the actual values, based on the property" & "possibly type validation in combination with TypeScript?"? Isn't it the same thing said differently?

TheOnlyTails commented 2 years ago

it is lol, my bad.

tomblachut commented 2 years ago

Ok there are "levels" that can be understood with validation here

First of all I hope to be able to connect the static part in quotes with property name and provide the same validations as in pure CSS, for example: when using font you need to pass font-family, but when using font-size, just pixels is fine. image. style:font="32px" could be marked as error

Secondly, when you use Svelte expressions to dynamically pass e.g. number into style:transform="translate({variable}px, 0)" this will result in the same problem as #80

Thirdly, e.g. with ternaries you can pass strings of CSS (style:position={absolute ? "absol-oops" : null}), and contents of those strings could be in theory highlighted and validated as CSS, but this must be carefully considered, and e.g. disabled when doing dynamic stuff like string concatenation .

Anyway I have lots of work in various plugins right now, so all of these are considered nice to have.

TheOnlyTails commented 2 years ago

I think that even Level 1 would be good. one thing i could imagine is using variable types to verify stuff. for example, style:transform="translate({variable}px, 0)" would only give out an error if variable is not a number. this won't really work for color strings though (maybe? i know that some support for them exists).

I think ternaries are pretty good to have.

sdarnell commented 2 years ago

For reference, the style attributes currently give the error "Attribute style:xyz is not allowed here". The very first level would be to allow style:anything attributes to avoids the error. Then it would be nice to validate the style name style:valid-style. IMHO validating the contents of the style expression potentially nice but extremely complex in general, and way down the priority list.

Note sure how much is shared between plugins, but obviously the Angular plugin does great validation of the Angular equivalent style attributes (style.font="bla" or [style.font]="expr").

tomblachut commented 1 year ago

Migrated to WEB-61793 Svelte: allow style directive attributes & WEB-58748 Svelte: style directive is not supported