-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
feat: Add useSVGIcons option #8260
Conversation
Codecov Report
@@ Coverage Diff @@
## main #8260 +/- ##
==========================================
+ Coverage 82.57% 82.68% +0.10%
==========================================
Files 112 113 +1
Lines 7497 7561 +64
Branches 1809 1818 +9
==========================================
+ Hits 6191 6252 +61
- Misses 1306 1309 +3
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
I like the direction! Two minor comments/thoughts.
build/images.js
Outdated
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 does this file do and when is it run?
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.
looks similar to the build/sandbox.js file
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 was me playing around with how to include /images
in the /dist
directory. Updated package.json with a command to copy the folder to dist.
I believe this should make the file accessible after everything is built, but please let me know if that is not the case or if I should do this some other way :)
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.
Looks great, but I had a thought about the SVG sprite URL.
src/css/_icons.scss
Outdated
.vjs-svg-icon { | ||
display: inline-block !important; | ||
background-repeat: no-repeat; | ||
background-position: center; | ||
|
||
fill: #FFFFFF; | ||
height: 16px; | ||
width: 16px; | ||
|
||
// Overwrite any font content | ||
&:before { | ||
content: none !important; | ||
} | ||
} |
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.
Is there a way to do this without !important
? We should avoid it except in the most unusual cases.
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.
I'm trying to think of a better way.. without it, we basically have 2 icons overlapping each other because the font icons are added through css content. A different option would be to go through everywhere those fonts are added and do a (:not)
check to ensure that the content is only being added when svgs are not supposed to be used, but not sure if that is a better solution.
We can remove this once we remove the font icons entirely, but this might be the best path for now.
src/js/component.js
Outdated
const useEl = document.createElementNS(xmlnsURL, 'use'); | ||
|
||
svgEl.appendChild(useEl); | ||
useEl.setAttributeNS(null, 'href', `../images/icons.svg#vjs-icon-${iconName}`); |
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.
I know we talked about this path being sufficient, but the more I think about it, the more it makes sense for there to be an additional Video.js option for the URL for the SVG sprite.
It could be ../images/icons.svg
by default and that should work for the Video.js CDN or unpkg or similar, but I can see use-cases where a Video.js user will want to point that to a different location.
This would also allow people to create their own icons.
const player = videojs('example', {
iconsUrl: '//my-cdn.com/my-icons.svg'
});
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 is a very good idea! My only question is, do we expect these custom SVG sprites to have the exact same definitions of SVGs as our SVG sprite?
For icons that already exist in VJS, we expect them to have a certain id on the SVG element. If the custom sprite were to work with this implementation, it would need to have those same ids on the defs
in their sprite, or else the preexisting icons won't show up.
Would it make more sense to be able to just pass that URL into the setIcon
function as a param? This way, if a user wanted to overwrite an icon, they could get whatever component they want and call the function to update the icon from their sprite url. This would also allow them to avoid sprites entirely and call a file with a single SVG.
Definitely open to all ideas!
@wseymour15 this feature is absolutely awesome and is a fantastic addition to video.js! 😍 👍🏽 I have a little feedback on the By setting the default font size per |
Thanks @amtins, and great find! It looks like this can be addressed with some additional CSS and toying with the different breakpoints. I will be sure to include this in my updates to this feature. EDIT: @amtins, please feel free to correct me if I am wrong here (as I certainly could be), but it sounds like the feature you are discussing is not anything in the VJS code, but the user's ability to add their own CSS to update the button size per breakpoint. You are absolutely correct that CSS setting the
Please let me know if I am understanding correctly, and I am not sure if the original CSS was documented anywhere, but I am happy to add some documentation to explain this! |
@wseymour15 thank you for your detailed comment 👍🏽
I may not have been precise enough in my comment, sorry. The power of video.js is that you can redefine the size of different components using a single line of css, regardless of responsive mode. This is possible because sizes are defined in Perhaps this comment is better formulated video.js/src/css/components/_layout.scss Lines 13 to 15 in f1558c6
DemonstrationVideo.js with font icons: vjs-font.webmVideo.js with svg px: vjs-svg-before.webmVideo.js with svg em: vjs-svg-after.webm |
Thanks @amtins for the clarification, the videos were extremely helpful. I went ahead and updated the styling on the icons to use em instead of px so it is truly responsive to those style changes. Feel free to take a look and let me know if that appears to fix the issue! |
Nit, but the different volume icons don't seem quite in line with each other, the speaker is larger in the medium and low states. The CC icon seems much more legible at a smaller size now compared to the font. |
@mister-ben Agreed, those did look a bit inconsistent. This is because these were a mix of the Font Awesome and Material UI Icons. Ideally, I wanted to go with all of the Font Awesome Icons here, but some of them required a PRO account. With my most recent commit, I decided to use Material UI Icons for all of the volume SVGs. I had to add a little extra CSS because those icons filled less of the viewBox then the other icons and appeared a bit too small. BONUS: These icons require less data than the Font Awesome ones :) |
This brings back an issue on Chrome in Chinese that the slider handles are misplaced. That was fixed with the font icons in #7990. On the other hand it fixes the placement of the slider on the veritcal slider, which is unresolved with the font. #8092 |
Thanks for pointing this out @mister-ben ! I played around with a combination of the two solutions, and this looks better both in Chinese and non-Chinese browsers.. let me know if you agree! |
Your last changes still didn't look right on my machine. Do my suggestions look right to you? Interesting and frustrating if we're getting different results. |
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.
Looks great. Two small questions
The inconsistencies in these icons are bothering me:
Could we reduce the number of icons? I know why they're in the font, but I think the Facebook etc social icons in particular ought not to be included as they are not used by the core player. Instead, we should have a way for a plugin to supplement icons, some sort of The size of some icons in the source seem inefficient. Are we happy with how rollup-plugin-svg is optimising them in the build? My major concern is how we will allow users to change the icons and how easily, for example to a rounded set. As this is experimental and opt-in, that could be addressed in a later PR as long as the current approach isn't locking that out too much. |
Great points, @mister-ben. I propose that we change the name to |
Thanks @mister-ben, I greatly appreciate this feedback.
I do see that this is slightly off.. I could not find these icons at all in material UI, and the matching fullscreen exit icon required a Font Awesome pro account to download.
Same here.. there IS a better HD icon in Font Awesome.. that requires a pro account.
I made an update to make these icons align more closely. I believe that making the icons more consistent can probably come with future work. I think it would be to our benefit to have access to a Font Awesome Pro account. Material UI doesn't quite have everything we need, and many of the "ideal" icons are locked in Font Awesome behind a pro account.
Great point. I know we do use a few of these social icons on the Brightcove side, but they are not a part of video.js anywhere. I'm leaning towards keeping the same icons as the past for now. However I am all for taking the time later to determine which icons would and would not be valuable to keep.
Most of these icons come straight from material UI or Font Awesome, I am sure there are ways to make some of them smaller, but I think for now we should probably just keep them as is. For the build, this was a talking point on the Brightcove side initially, and we did some testing. We are satisfied with how much larger the build has become after the change, and assume once we remove the fonts entirely, it should be smaller than before. Here is some comparison between the builds before and after.
This sounds related to your idea of a I also think that there will currently be ways the user could add icons by customizing their own player, it would just not be as simple as a function call. Sorry for the story book 😅 All in all, I think we are at a pretty good spot to move forward with what we have, and then iterate with future improvements. |
Totally agree. Updated the current implementation to change the option name, as well as updated the docs in my other PR. |
Description
Directory of Icons: https://deploy-preview-8260--videojs-preview.netlify.app/sandbox/svg-icons.html
Player with SVG Icons enabled: https://deploy-preview-8260--videojs-preview.netlify.app/sandbox/svg-icons-enabled.html
This change adds a player option titled
useSVGIcons
which will replace the font icons fromvideojs/font
with SVGs that are stored in the Players DOM. Eventually, we will want to remove allvideojs/font
styling, but for now we give the user the option to replace it.To test: run this repo locally, use
npm start
, and go tohttp://localhost:9999/sandbox/svg-icons.html
to see the new icons.PR for documentation update can be found here: videojs/videojs.com#171
Specific Changes proposed
useSVGIcons
player option is added, which adds a high levelvjs-svg-icons-enabled
class to thevideo
element.setIcon
Requirements Checklist