-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Svg color api #9984
Svg color api #9984
Conversation
core/Controller/SvgController.php
Outdated
* @return DataDisplayResponse|NotFoundException | ||
*/ | ||
public function getSvg(string $fileName, $color = 'ffffff') { | ||
$path = $this->serverRoot . "/core/img/actions/$fileName.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 then needs to be redone for all the other icon locations :/
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, it was a first shot, I'm asking for feedback on how to tackle this :)
how do you think we should handle custom paths? Right now I implemented this for the actions folder only, but in the end we'll probably need this for the apps menu and other stuff.
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.
On the other side I'm fine with doing it like this for now and test it.
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.
Lets first try it like this. I'd rather have 3 endpoints that are dead simple. (and do their own stuff) than 1 endpoint that does a lot of stuff.
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.
@rullzer though we'll need to access icons in apps, so I guess I will add a new endpoint for apps icons
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.
Sure but like I said. Small endpoints beat complex ones. so 🚀
core/css/icons.scss
Outdated
@@ -188,22 +192,22 @@ img, object, video, button, textarea, input, select, div[contenteditable='true'] | |||
} | |||
&:hover, | |||
&:focus { | |||
background-image: url('../img/actions/delete-hover.svg?v=1'); | |||
background-image: url('#{$webroot}/svg/icon-delete/d40000?v=1'); |
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.
icon-star (or icon-starred) then also needs the yellow star color. And the folders the Nextcloud blue (or rather theming color)?
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.
@jancborchardt that's correct, we can extend this to whatever colours we want :)
I think we can add another endpoint that is a bit more generic, so it works for other apps with different icon paths as well. We do have such a route in the theming app already: https://github.com/nextcloud/server/blob/master/apps/theming/appinfo/routes.php#L80-L84 |
I've added a new /svg/app/icon/color path :) |
core/Controller/SvgController.php
Outdated
|
||
// Set cache control | ||
$ttl = 31536000; | ||
$response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable'); |
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.
@skjnldsv I cannot find it, maybe you forgot to push? 😉 |
😅😅 |
f888fae
to
10ebd3b
Compare
Codecov Report
@@ Coverage Diff @@
## master #9984 +/- ##
=========================================
Coverage ? 52.06%
Complexity ? 25950
=========================================
Files ? 1646
Lines ? 95867
Branches ? 1290
=========================================
Hits ? 49910
Misses ? 45957
Partials ? 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.
I like it 👍
@MorrisJobke still some fixes to do :)
|
lib/private/Template/IconsCacher.php
Outdated
|
||
$data = ''; | ||
foreach ($icons as $icon => $url) { | ||
$data .= "--$icon: url('$url?v=1');"; |
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 reason that the v=1 is appended here and not at the css level? I think that could lead to icons not being reloaded if they are changed.
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 have no idea, they were always like that, so I didn't give it a lot of thought :)
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 mean usually we have it inside of the css file, which is fine, since then it can be bumped once the icon file is changed, and the browsers can detect that they should load the file again.
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.
We should probably remove all of those ?v=1 then
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.
Probably yes.
Okay, that's how I proceed: .icon-screen-off {
@include icon-color('screen-off', 'actions', $color-black, true);
} Basically you just need to add this to your css and the background-image will be automatically added to a variable. The Mixin works that way: /**
* SVG COLOR API
*
* @param string $icon the icon filename
* @param string $dir the icon folder within /core/img if $core or app name
* @param string $color the desired color in hexadecimal
* @param bool [$core] search icon in core
*
* @returns string the url to the svg api endpoint
*/
@mixin icon-color($icon, $dir, $color, $core: false) Then, every time the scss is compiled, the system will detect if an icon is used via this mixin and export it to a new css file called icons-vars.css (cached into the appdata) @nextcloud/designers what are your thoughts? Is this a good behavior? |
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
5a25b3d
to
bfc6fc8
Compare
@rullzer Rebased. |
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.
Unit tests fail:
1) Test\Template\SCSSCacherTest::testProcessUncachedFileNoAppDataFolder
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:127
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:245
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:142
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:143
2) Test\Template\SCSSCacherTest::testProcessUncachedFile
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:167
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:245
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:142
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:179
3) Test\Template\SCSSCacherTest::testProcessCachedFile
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:203
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:245
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:142
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:210
4) Test\Template\SCSSCacherTest::testProcessCachedFileMemcache
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:242
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:245
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:142
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:249
5) Test\Template\SCSSCacherTest::testGetCachedSCSS with data set #0 ('core', 'core/css/styles.scss', '/css/core/styles.css', '14.0.0 alpha')
Expectation failed for method name is equal to "linkToRoute" when invoked 1 time(s)
Parameter 1 for invocation OCP\IURLGenerator::linkToRoute('core.Css.getCss', Array (...)): string does not match expected value.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 'fileName' => '77d8-8422-styles.css'
+ 'fileName' => '77d8-0ab8-styles.css'
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:365
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:454
6) Test\Template\SCSSCacherTest::testGetCachedSCSS with data set #1 ('files', 'apps/files/css/styles.scss', '/css/files/styles.css', '1.9.0')
Expectation failed for method name is equal to "linkToRoute" when invoked 1 time(s)
Parameter 1 for invocation OCP\IURLGenerator::linkToRoute('core.Css.getCss', Array (...)): string does not match expected value.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 'fileName' => 'd16b-8422-styles.css'
+ 'fileName' => 'd16b-0ab8-styles.css'
/drone/src/github.com/nextcloud/server/lib/private/Template/SCSSCacher.php:365
/drone/src/github.com/nextcloud/server/tests/lib/Template/SCSSCacherTest.php:454
core/Controller/SvgController.php
Outdated
* @param string $folder | ||
* @param string $fileName | ||
* @param string $color | ||
* @return DataDisplayResponse|NotFoundException |
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.
You don't return an exception you throw it ;)
core/Controller/SvgController.php
Outdated
* @param string $color | ||
* @return DataDisplayResponse|NotFoundException | ||
*/ | ||
public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
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.
You can also declare return types ;)
core/Controller/SvgController.php
Outdated
* @param string $app | ||
* @param string $fileName | ||
* @param string $color | ||
* @return DataDisplayResponse|NotFoundException |
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.
NotFoundResponse it seems
core/Controller/SvgController.php
Outdated
return $this->getSvg($path, $color, $fileName); | ||
} | ||
|
||
$appPath = \OC_App::getAppWebPath($app); |
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.
Can't the appmanager do this?
lib/private/Template/IconsCacher.php
Outdated
@@ -0,0 +1,146 @@ | |||
<?php | |||
/** |
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.
strict
@@ -0,0 +1,126 @@ | |||
<?php | |||
/** |
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.
strict
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
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.
Lets do this. 🎸
protected $urlGenerator; | ||
|
||
/** @var string */ | ||
private $iconVarRE = '/--(icon-[a-z0-9-]+): url\(["\']([a-z0-9-_\~\/\?\&\=\.]+)[^;]+;/m'; |
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.
@juliushaertl some of the icons are broken because of your last edit.
We shoudl exclude the ?v= from the matches because otherwise it gets re-added on every compile and we get stuff like that: --icon-confirm-fade-000: url('/svg/core/actions/confirm-fade/000?v=2?v=1?v=1?v=1?v=1');
Was there a specific reason? Or can I remove the ?=& from the regex? :)
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, your right, we can remove those. The others might be needed depending on the base URL of the nextcloud installation.
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.
Weeee 🎈
background-image: url('../img/actions/video.svg?v=2'); | ||
filter: invert(100%) drop-shadow(1px 1px 4px var(--color-box-shadow)); | ||
@include icon-color('video', 'actions', $color-white, 1, true); | ||
filter: drop-shadow(1px 1px 4px var(--color-box-shadow)); |
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 bigger reason the invert(100%)
was removed? this breaks the icons on the Talk UI, because now the white icon has a white shadow on a white background while you are waiting for a participant to join the call
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 shadow? you mean @nickvergessen are you using the proper new css class? |
This causes high load on Safari: #11179 😢 |
This create a new endpoint to get one of our svg and change the colour.
This will allow us to:
Fix #8702
@nextcloud/designers do you see any issues with this?
@juliushaertl how do you think we should handle custom paths? Right now I implemented this for the actions folder only, but in the end we'll probably need this for the apps menu and other stuff.
Any example on where to use this?