Description
I'd like to propose a feature, but I'd like to get feedback first.
In #1112, we added a function, extract(@pad, 2)
that can be used to extract a top/right/bottom/left dimension from a padding shorthand (or ANY shorthand, since it's index based).
We originally wanted to specify a keyword, such as extract(@pad, right)
, but that requires Less to have intrinsic knowledge of CSS, and have special keywords, which was just not a good idea.
The only problem with the index-based approach is that it would be nice to also allow short-shorthand, such @pad: 1px;
or @pad: 1px 2px 3px;
but there's no reliable way to extract the right, bottom, or left values.
Here's my proposed solution: Allow "backup indexes" as follows:
@left: extract(@pad, 4 2 1)
, @bottom: extract(@pad, 3 1)
, @right: extract(@pad, 2 1)
.
The @left
example tries to extract the 4th parameter, but if there aren't 4 parameters, it tries the 2nd, and if there aren't 2, it tries the 1st.
This puts the Less user in charge, and makes them responsible for the intrinsic CSS knowledge. But maybe I'm just off my rocker.