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

Reconsider the API for interpolation #37

Closed
basarat opened this issue Oct 17, 2016 · 3 comments
Closed

Reconsider the API for interpolation #37

basarat opened this issue Oct 17, 2016 · 3 comments

Comments

@basarat
Copy link
Contributor

basarat commented Oct 17, 2016

I can understand if this should be closed as it can be done in userland quite easily. Neverthless I wanted to leverage your opinion on something like the following for interpolation :

interface NestedCSSProperties extends CSSProperties {
  /** Interpolated */
  '&'?: {
    [selector: string]: NestedCSSProperties;
  }
}

Example:

{
  'color' : 'red',
  '&': {
     ':focus': SomeCSSProperties
  }
}

The current implementation is not amenable for typing:

interface NestedCSSProperties extends CSSProperties {
  /** States */
  '&:hover'?: NestedCSSProperties;
  '&:active'?: NestedCSSProperties;
  '&:disabled'?: NestedCSSProperties;
  '&:focus'?: NestedCSSProperties;

  /** Children */
  '&>*'?: NestedCSSProperties;
  '&:first-child'?: NestedCSSProperties;
  '&:last-child'?: NestedCSSProperties;

 /** Others like nth-child cannot be helped :-/ */
}

Again, thanks for being so awesome 🌹

@blakeembrey
Copy link
Owner

Briefly, the nice thing about interpolation today is it's free-form and doesn't force a user into building components a specific way. For instance, I can do a selector like .featured-post & to interpolate the current selector and change the current style based on a classname on the body, etc. Although not the recommended approach, it's quite useful in places (I imagine it'd mix well with existing codebases also, plus tools like https://modernizr.com/ which add classes for you based on feature support).

Based on this, I don't think it's possible to do things like that - unless we treat & keys as every child is interpolation without a space. The benefit of this is missing from me though.

Why couldn't every other selector just be this? I think TypeScript should provide the autocompletion anyway once it sees that it's not an array or primitive. If it doesn't, that might an enhancement request, but I'm pretty sure it does 😄

[selector: string]: undefined | number | string | (number | string)[] | NestedCSSProperties

Is there any other goals, other than simpler auto-completion?

@basarat
Copy link
Contributor Author

basarat commented Oct 18, 2016

[selector: string]: undefined | number | string | (number | string)[] | NestedCSSProperties

Works like a charm! Thanks 🌹

image

@basarat basarat closed this as completed Oct 18, 2016
@basarat
Copy link
Contributor Author

basarat commented Oct 18, 2016

other than simpler auto-completion?

Also error reporting. Thought I'd mention 🌹

image

Thank you for making my life so much easier ❤️

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