Skip to content

Typed CSS Custom PropertiesΒ #8419

@kevmodrome

Description

@kevmodrome

Describe the problem

We've got great support prop types in Svelte but we don't have support for CSS Custom Properties types. It would be great if we could somehow get guard rails when we pass in values to these as well.

Describe the proposed solution

An example of what I would want to happen:

<!-- MyButton.svelte -->

<button>Some Text</button>

<style>
  @property --bg-color {
    syntax: "<color>";
    inherits: false;
    initial-value: blue;
  }
  @property --text-color {
    syntax: "<color>";
    inherits: false;
    initial-value: white;
  }
  button {
    background: var(--bg-color);
    color: var(--text-color)
  }
</style>
<!-- Parent.svelte -->

<MyButton --bg-color="100" /> <!-- Results in error, type is not correct -->

<MyButton --bg-color="blue" /> <!-- OK! No Error -->

If possible we could maybe even infer the types from the CSS Rule itself and skip the @property stuff.

Alternatives considered

The alternative is just having no types. I don't see any other solutions to the problem here.

Importance

nice to have

Edit: I realize now this should've maybe have gone in the language-tools repo πŸ€¦β€β™‚οΈ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions