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

Using calc in a transform expression #495

Open
MelvIsntNormal opened this issue Jan 31, 2019 · 3 comments
Open

Using calc in a transform expression #495

MelvIsntNormal opened this issue Jan 31, 2019 · 3 comments

Comments

@MelvIsntNormal
Copy link

I can't seem to use a calc expression for a transformation. I'm trying to write:

.tooltip {
    /*--- snip ---*/
    transform: translateX(calc(0px - var(--tooltip-offset)));
}

But (what I think is) the elm-css equivalent does not compile:

tooltip : LengthOrAuto (Calc compatible) -> Style
tooltip offset =
    batch
        [ {--- snip ---}
        , transform (translateX (calc (px 0) minus offset))
        ]

I get this error:

-- TYPE MISMATCH ------------------------------------ ./src/App/View/Tooltip.elm

The 1st argument to `translateX` is not what I expect:

115|                         [ transform (translateX (calc (px 0) minus offset))
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^
This `calc` call produces:

    CalculatedLength

But `translateX` needs the 1st argument to be:

    { compatible
        | length : Css.Structure.Compatible
        , numericValue : Float
        , unitLabel : String
        , units : units
        , value : String
    }

Hint: Seems like a record field typo. Maybe numericValue should be value?

Hint: Can more type annotations be added? Type annotations always help me give
more specific messages, and I think they could help a lot in this case!
@tgelu
Copy link

tgelu commented Oct 21, 2020

a bit late, but did you manage to figure this out? I am struggling with a similar case

@sebbes-at-deepgram
Copy link

Same here!

@sebbes-at-deepgram
Copy link

sebbes-at-deepgram commented May 29, 2021

Workaround: in regular old css, rather than calc'ing the translation, you can actually use a series of translates, as long as they're in the same property. So we can do:

Css.transforms
      [ Css.translateX <| Css.px <| 48
      , Css.translateX <| Css.pct <| 50
      ]

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

3 participants