Skip to content

feat: implement css-variables and css-calc #7553

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

Merged
merged 50 commits into from
Aug 19, 2019

Conversation

m-abs
Copy link
Contributor

@m-abs m-abs commented Jul 19, 2019

PR Checklist

What is the current behavior?

No support for css-variable or for css-calc

What is the new behavior?

Adds basic support for css-variable and css-calc

.button {
   --custom-color: black; /** text-color: black **/
   color: var(--custom-color);
}

.button.got-the-blues {
   --custom-color: blue; /** text-color: blue **/
}

.button.red {
   --custom-color: red;  /** text-color: red **/
}

Adds support for calc(...) in CSS, via reduce-css-calc.

StackLayout {
    --my-factor: 1;  /** width: 100% **/
   width: calc(100% * var(--my-factor));
}

StackLayout.slim {
    --my-factor: 0.1;  /** width: 10% **/
}

StackLayout.wide {
    --my-factor: 1.25; /** width: 125% **/
}

What is still missing:

  • Updating the variables via view.style is broken, if already defined in CSS.
  • For CSS-variables to be really useful, support for calc(var(--my-variable) * 2) is needed. I intend to add this to the PR.
  • clean up

Implements #4864

@cla-bot cla-bot bot added the cla: yes label Jul 19, 2019
@m-abs m-abs changed the title feat: implement basic support for css-variables feat: implement css-variables and css-calc Jul 19, 2019
@exejutable
Copy link

this is gonna be merged?

@m-abs
Copy link
Contributor Author

m-abs commented Jul 24, 2019

@exejutable
I hope so, but I need to do some clean up and it needs to be properly reviewed and tested.

@themounthead
Copy link

Can this merged please !!! I'm migrating my web app to a shared codebase and this is last missing piece to handle universal Theming.

@bundyo
Copy link
Contributor

bundyo commented Jul 30, 2019

I've tested this PR a bit and it seems to be working rather nice.

@m-abs
Copy link
Contributor Author

m-abs commented Aug 6, 2019

@manoldonev
Is it okay to depend on reduce-css-calc or should I try to write my own parser?

reduce-css-calc doesn't take up much space and work as advertised, but it is a new extra dependency plus its dependencies.

@m-abs
Copy link
Contributor Author

m-abs commented Aug 6, 2019

@manoldonev
I tried out my own implementation on https://github.com/m-abs/NativeScript/tree/feat/css-variables-own-calc.

Seems to work fine, but it needs a little clean up.

@manoldonev manoldonev added docs needed Additional documentation on this issue/PR is needed ♥ community PR labels Aug 15, 2019
@manoldonev
Copy link
Contributor

test

@m-abs
Copy link
Contributor Author

m-abs commented Aug 19, 2019

Hi @manoldonev,
Thank you for approving the PR.

Unfortunately I have discovered a limitation with the css-calc support.

Expressions like calc(100% - 30px + 20px) are reduced to calc(100% - 10px) because we don't know what the relative size of 100% is at the time.

Can we leave it as a known limitation and print a warning if/when it happens?

@SvetoslavTsenov SvetoslavTsenov merged commit 673c808 into NativeScript:master Aug 19, 2019
@SvetoslavTsenov
Copy link
Contributor

SvetoslavTsenov commented Aug 19, 2019

Hey @m-abs, this feat will be available in the next version of tns-core-modules@next and
in the next official version of tns-core-modules@6.1.0

@m-abs m-abs deleted the feat/css-variables branch August 19, 2019 22:00
@manoldonev
Copy link
Contributor

@m-abs can you log this limitation #7553 (comment) as a separate issue and we will mark it with the "known issues" label for the time being?

@manoldonev
Copy link
Contributor

@m-abs Thank you for the awesome contribution and for taking time to address all comments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes ♥ community PR docs needed Additional documentation on this issue/PR is needed
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

6 participants