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

[typed-om] Shorter dimension constructors on the CSS namespace? #320

Closed
tabatkins opened this issue Oct 4, 2016 · 5 comments
Closed

[typed-om] Shorter dimension constructors on the CSS namespace? #320

tabatkins opened this issue Oct 4, 2016 · 5 comments

Comments

@tabatkins
Copy link
Member

tabatkins commented Oct 4, 2016

Several years ago I left a comment about Typed OM stuff wherein I suggested that the CSS namespace object could host very short constructors (/ factory functions) for the common dimensions.

That is, right now if you want to make a 5px length, you have to type:

let len = new CSSLengthValue.from(5, 'px');
//or
let len = new CSSSimpleLengthValue(5, 'px');

That's long and ugly and everyone will hate us if we force them to do that everywhere. My idea was to additionally allow:

let len = CSS.px(5);

Basically we'd just add functions to the CSS namespace object for all the dimensions CSS knows about. We can possibly add more for various functions, but it looks like we wouldn't gain much. Like, for transform stuff:

// Current
let trans = new CSSTranslation(CSS.px(5), CSS.px(10));
// Potential new?
let trans = CSS.translate(CSS.px(5), CSS.px(10));

It's a bit better, but not a huge win. It also suggests that we would need to add one for every single CSS function, and somehow deal with the potential places where the same function name means different things in different contexts. (I don't think there are any, but it's potentially allowed by CSS.) I'd be fine with ignoring this, at least unless/until we discover in the wild that people want it. In other words, L2 for this stuff, but L1 for the dimensions.

@shans
Copy link
Contributor

shans commented Oct 5, 2016

The colors might be a big win too:

CSS.rgb(255, 0, 0)
CSS.rgba(255, 0, 0, 0.1)

@tabatkins
Copy link
Member Author

Ah yeah, indeed, if we allowed raw numbers instead of requiring CSSNumberValues.

@tabatkins
Copy link
Member Author

Actually I'd probably want to define them as only taking a 0-1 value for all their arguments. And things which take unitted values get easier:

CSS.hsl(CSS.deg(60), 1, .5)

@tabatkins
Copy link
Member Author

With this change we can remove the static CSSLengthValue.from(value, unit) function, too - the CSS.unit() functions functionally replace them.

@shans
Copy link
Contributor

shans commented Apr 3, 2017

There are "Numeric Factory Functions" now specified (section 4.3.4).

@shans shans closed this as completed Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants