-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Cover Image: Add range slider for background dim #2815
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2815 +/- ##
=========================================
+ Coverage 33.77% 33.97% +0.2%
=========================================
Files 191 191
Lines 5691 6199 +508
Branches 996 1136 +140
=========================================
+ Hits 1922 2106 +184
- Misses 3189 3421 +232
- Partials 580 672 +92
Continue to review full report at Codecov.
|
In my opinion...
Yes, which answers your first two questions. I think we should get rid of the toggle and just show the slider, defaulting to 0. Then, I'd update the label to either "Dimness" or "Opacity" and show the value as a percentage of 100%, rather than 0–1. |
All those sound good! |
Noting that it's an inevitably as we iterate on blocks, but this will likely cause many existing Cover Image blocks to become flagged as invalid, due to markup / class name changes. Related: #2541 |
blocks/library/cover-image/index.js
Outdated
|
||
function dimRatioToClass( ratio ) { | ||
let rounded = Math.round( ratio / 10 ); | ||
// String#padStart not ready for prime time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This a difficult task to implement correctly, and I think the only viable option is to call out to a service which is designed to take on the burden of maintaining this implementation: http://left-pad.io/
On a more serious note, there's: https://lodash.com/docs/4.17.4#padStart
Or my personal preference, the negative slice:
( '0' + rounded ).slice( -2 );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's lodash
Ooh, Dash must have failed me. :) Though I like the negative slice better.
blocks/library/cover-image/index.js
Outdated
if ( rounded < 10 ) { | ||
rounded = '0' + rounded; | ||
} | ||
return 'has-background-dim--' + rounded; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reasoning behind the double dash? Could be misleading as a pattern that we don't encourage. Should be sufficient with the single dash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reasoning, just reflexes. :)
background: rgba( 0,0,0,.9 ); | ||
} | ||
|
||
&.has-background-dim.has-background-dim--10:before { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A SASS loop control could help avoid the duplication here, if maybe a bit overkill:
http://sass-lang.com/documentation/file.SASS_REFERENCE.html#_for
http://thesassway.com/intermediate/if-for-each-while#for
@for $i from 1 through 10 {
&.has-background-dim.has-background-dim-#{ $i } {
background-image: rgba( black, $i * 0.1 );
}
}
(Which, I'm seeing could be an issue for the 0 prefixing, and begs the question: Do we need the padding?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll drop the padding. I think my subconscious reasoning was that classes are strings, thus numbers injected into these should have the padding so that alphabetical sorting matches number sorting. ¯_(ツ)_/¯
blocks/library/cover-image/index.js
Outdated
const style = url | ||
? { backgroundImage: `url(${ url })` } | ||
: undefined; | ||
const classes = classnames( className, { | ||
'has-parallax': hasParallax, | ||
'has-background-dim': hasBackgroundDim, | ||
'has-background-dim': dimRatio !== 0, | ||
[ dimRatioToClass( dimRatio ) ]: dimRatio !== 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe dimRatioToClass
should return an empty string or null value when it is not equal to zero, which we pass as a standalone argument to classnames
to be dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saner, yes.
cb56807
to
e2d6697
Compare
Thanks for the sanity, @aduth! Feedback addressed. |
e2d6697
to
89cd7ff
Compare
className, | ||
dimRatioToClass( dimRatio ), | ||
{ | ||
'has-background-dim': dimRatio !== 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this added to try to preserve backwards compatibility with existing content? I'd have hoped it would be the case, but unfortunately existing cover image blocks appear to be flagged as invalid. The issue appears to be that the old content will have the has-background-dim
class, but the dimRatio
will not be found and therefore default to 0
, thus causing a subsequent save to save without has-background-dim
and cause content loss (the validator in action!). Maybe we should assign the default for dimRatio
to mimic what had previously existed as the default for hasBackgroundDim
effect?
(For debugging validation, see also new #2837)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this added to try to preserve backwards compatibility with existing content?
Not really. For the issue of compatibility, I stopped to consider what we could do at the framework level. Regardless, something as small as this shouldn't be blocked by that, so I pushed 2884db eab53ef. Note, though, the weirdness of
function dimRatioToClass( ratio ) {
- return ratio === 0
+ return ( ratio === 0 || ratio === 50 )
? null
: 'has-background-dim-' + Math.round( ratio / 10 );
}
Since 50% dimming corresponds to the previous default value of hasBackgroundDim
, we need to treat that specifically to avoid altering our block's class list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really.
If not, why do we need has-background-dim
at all? (Edit: I say this, though it may allow us to keep compatibility)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, though, the weirdness of
I think this is fine, expected even. Similar to how we omit default values from serialized comments, we can omit the default value (50) from the class set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... my answer was for the past only. :)
I say this, though it may allow us to keep compatibility
Exactly. At first, it lingered while I pondered on the general compat stuff, but with that eab53ef it makes sense to keep it.
2884db5
to
31ebf85
Compare
blocks/library/cover-image/index.js
Outdated
function dimRatioToClass( ratio ) { | ||
return ( ratio === 0 || ratio === 50 ) | ||
? null | ||
: 'has-background-dim-' + Math.round( ratio / 10 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing: Do we need the division? I might think .has-background-dim-50
is clearer at a glance than .has-background-dim-5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The classes reflected the allowed granularity, but I can change that. Maybe it'll make it more future-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the division might still be needed, but the computation becomes:
10 * Math.round( ratio / 10 )
meaning that 35…44 -> 40, etc. Edit: in case a user inputs a specific value in between 40 and 50
31ebf85
to
7280973
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed back-compat, looks great 👍
Implements #2006
(previous screencast)
In terms of design:
In technical terms:
:before
element. These aren't programmatically manipulable, so fully dynamic dimming (i.e., settingbackground
for any alpha value) isn't possible. The current solution is based on ten hardcoded steps offered to the user.