data icon indicating copy to clipboard operation
data copied to clipboard

% unit is missing

Open kof opened this issue 3 years ago • 4 comments

I am a bit surprised % is not in the units json, maybe I am not aware of some differentiation? Feel free to close if that's the case

kof avatar Feb 09 '22 17:02 kof

We can add it, but which categories should we put it in?

"%": {
  "groups": [
    "CSS Units",
    "CSS Lengths"
  ],
  "status": "standard"
}

Any more?

teoli2003 avatar Feb 10 '22 07:02 teoli2003

A percent sign (%) is not a unit since doesn't represent a quantity itself but always relative to another quantity. Also a number with a unit produces a <dimension>, at the same time % produces its own type – <percentage>. And a "unit" should be an identifier, but % is not an identifier. See dimension and percentage definitions for more details.

Btw, percentage is not limited to a length but can be used for any quantity, the spec defines the following productions:

  • <length-percentage>
  • <frequency-percentage>
  • <angle-percentage>
  • <time-percentage>

And in syntaxes.json you also can find <number-percentage>.

lahmatiy avatar Feb 13 '22 19:02 lahmatiy

This is getting even more confusing since houdini api calls it a percent and calls it a unit value

CSSStyleValue.parse('width', '10%') // CSSUnitValue {value: 10, unit: 'percent'}

kof avatar Feb 13 '22 19:02 kof

We don't call a % a "unit" largely for historical reasons, but it effectively is. The Typed OM API does call it one for simplicity; otherwise I'd need to invent a new class for it that is otherwise exactly identical to the one for unit values. Note that Typed OM also calls "number" a unit, for the same reason, even tho plain numbers are definitely distinct from unit values.

All of this is to say, whether you categorize % as a "unit" or not is largely a matter of what makes the must sense for your particular case. That's no hard and fast answer.

tabatkins avatar Jan 04 '23 14:01 tabatkins