Skip to content
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

Merged
merged 19 commits into from
Jul 19, 2018
Merged

Svg color api #9984

merged 19 commits into from
Jul 19, 2018

Conversation

skjnldsv
Copy link
Member

@skjnldsv skjnldsv commented Jun 25, 2018

This create a new endpoint to get one of our svg and change the colour.
This will allow us to:

  • Only maintain black svg
  • Only maintain one set of icon
  • Allow us not to use any filter to invert icons: ie11 compatibility and better handling of background images

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?

@skjnldsv skjnldsv added enhancement design Design, UI, UX, etc. 3. to review Waiting for reviews labels Jun 25, 2018
@skjnldsv skjnldsv added this to the Nextcloud 14 milestone Jun 25, 2018
@skjnldsv skjnldsv self-assigned this Jun 25, 2018
@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jun 25, 2018
@skjnldsv skjnldsv mentioned this pull request Jun 25, 2018
14 tasks
* @return DataDisplayResponse|NotFoundException
*/
public function getSvg(string $fileName, $color = 'ffffff') {
$path = $this->serverRoot . "/core/img/actions/$fileName.svg";
Copy link
Member

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 :/

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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 🚀

@@ -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');
Copy link
Member

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)?

Copy link
Member Author

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 :)

@juliusknorr
Copy link
Member

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.

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

@skjnldsv
Copy link
Member Author

I've added a new /svg/app/icon/color path :)


// Set cache control
$ttl = 31536000;
$response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juliusknorr
Copy link
Member

I've added a new /svg/app/icon/color path :)

@skjnldsv I cannot find it, maybe you forgot to push? 😉

@skjnldsv
Copy link
Member Author

@skjnldsv I cannot find it, maybe you forgot to push? wink

😅😅

@codecov
Copy link

codecov bot commented Jun 29, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@a788f49). Click here to learn what that means.
The diff coverage is 3.57%.

@@            Coverage Diff            @@
##             master    #9984   +/-   ##
=========================================
  Coverage          ?   52.06%           
  Complexity        ?    25950           
=========================================
  Files             ?     1646           
  Lines             ?    95867           
  Branches          ?     1290           
=========================================
  Hits              ?    49910           
  Misses            ?    45957           
  Partials          ?        0
Impacted Files Coverage Δ Complexity Δ
core/routes.php 0% <ø> (ø) 0 <0> (?)
core/Controller/JsController.php 93.54% <ø> (ø) 7 <0> (?)
core/Controller/SvgController.php 0% <0%> (ø) 4 <4> (?)
lib/private/Template/SCSSCacher.php 72.48% <100%> (ø) 39 <0> (?)

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍

@skjnldsv
Copy link
Member Author

skjnldsv commented Jun 29, 2018

@MorrisJobke still some fixes to do :)

  • Find a way to recompile the icons on accessibility theme update
  • Fix tests


$data = '';
foreach ($icons as $icon => $url) {
$data .= "--$icon: url('$url?v=1');";
Copy link
Member

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.

Copy link
Member Author

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 :)

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes.

@skjnldsv
Copy link
Member Author

skjnldsv commented Jul 4, 2018

Okay, that's how I proceed:
I added a mixin for our scss which automatically handle the svg colour api

.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)
The accessibility on dark theme automatically parse the icons-vars file and invert the proper colors from fff->000 and 000->fff (we don't reverse any other colours)

@nextcloud/designers what are your thoughts? Is this a good behavior?
@MorrisJobke @jancborchardt @juliushaertl @rullzer

@skjnldsv skjnldsv added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 4, 2018
skjnldsv and others added 7 commits July 19, 2018 08:16
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>
@juliusknorr
Copy link
Member

@rullzer Rebased.

Copy link
Member

@MorrisJobke MorrisJobke left a 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

* @param string $folder
* @param string $fileName
* @param string $color
* @return DataDisplayResponse|NotFoundException
Copy link
Member

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 ;)

* @param string $color
* @return DataDisplayResponse|NotFoundException
*/
public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') {
Copy link
Member

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 ;)

* @param string $app
* @param string $fileName
* @param string $color
* @return DataDisplayResponse|NotFoundException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotFoundResponse it seems

return $this->getSvg($path, $color, $fileName);
}

$appPath = \OC_App::getAppWebPath($app);
Copy link
Member

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?

@@ -0,0 +1,146 @@
<?php
/**
Copy link
Member

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
/**
Copy link
Member

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>
Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do this. 🎸

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jul 19, 2018
protected $urlGenerator;

/** @var string */
private $iconVarRE = '/--(icon-[a-z0-9-]+): url\(["\']([a-z0-9-_\~\/\?\&\=\.]+)[^;]+;/m';
Copy link
Member Author

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? :)

Copy link
Member

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.

Copy link
Member Author

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));
Copy link
Member

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

Copy link
Member

@juliusknorr juliusknorr Jul 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert is not available in IE11 (see #8702)

@skjnldsv Do you have an idea why the shadow would be white? The drop shadow should not be changed to white, right?

@skjnldsv
Copy link
Member Author

skjnldsv commented Jul 30, 2018

The shadow? you mean drop-shadow?
It should not be touched. and is set to black on variables.scss

@nickvergessen are you using the proper new css class? icon-video

@MorrisJobke
Copy link
Member

This causes high load on Safari: #11179

😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish design Design, UI, UX, etc. enhancement feature: accessibility standardisation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants