-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[4.0] [RFC] SVG icons #28351
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
[4.0] [RFC] SVG icons #28351
Changes from all commits
0beb7bf
58978d0
b0d8979
605ce93
8567e8f
58937b5
2ee3bfb
658e492
84a53ff
c202864
371be8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Document\Renderer\Html; | ||
|
|
||
| \defined('JPATH_PLATFORM') or die; | ||
|
|
||
| use Joomla\CMS\Document\Document; | ||
| use Joomla\CMS\Document\DocumentRenderer; | ||
| use Joomla\CMS\HTML\HTMLHelper; | ||
|
|
||
| /** | ||
| * HTML document renderer for the inline svg icons output | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| class IconsRenderer extends DocumentRenderer | ||
| { | ||
| /** | ||
| * Renders the inline svg icons and returns the results as a string | ||
| * | ||
| * @param string $name Not used. | ||
| * @param array $params Associative array of values | ||
| * @param string $content Not used. | ||
| * | ||
| * @return string The output of the script | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function render($name, $params = array(), $content = null) | ||
| { | ||
| $files = []; | ||
|
|
||
| // Generate the file and load the stylesheet link | ||
| foreach ($this->_doc->getIcons() as $key => $icon) | ||
| { | ||
| $file = HTMLHelper::image('vendor/' . $icon['provider'] . '/' . $icon['group'] . '/' . $icon['icon'] . '.svg', '', null, true, 1); | ||
|
|
||
| if ($file) | ||
| { | ||
| $content = @file_get_contents(JPATH_ROOT . substr($file, strpos($file, '/media'))); | ||
| $content = str_replace( | ||
| '<svg', | ||
| '<svg id="' . $icon['provider'] . '-' . $icon['group'] . '-' . $icon['icon'] . '"' | ||
| . ' title="' . $icon['text'] . '"' | ||
| . ' role="img"', | ||
| $content | ||
| ); | ||
|
|
||
| $files[] = $content; | ||
| } | ||
| } | ||
|
|
||
| if (!empty($files)) | ||
| { | ||
| // Reset the icons registry | ||
| $this->_doc->setIcons([]); | ||
|
|
||
| return '<div style="display:none">' . implode('', $files) . '</div>'; | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Component\ComponentHelper; | ||
| use Joomla\CMS\Factory; | ||
| use Joomla\CMS\HTML\HTMLHelper; | ||
| use Joomla\CMS\Language\Text; | ||
| use Joomla\CMS\Plugin\PluginHelper; | ||
|
|
@@ -21,6 +22,19 @@ | |
|
|
||
| Text::script('JSHOWPASSWORD'); | ||
| Text::script('JHIDEPASSWORD'); | ||
|
|
||
| Factory::getDocument()->addStyleDeclaration( | ||
| <<<CSS | ||
| .demo-class { | ||
| height: 1.2rem; | ||
| width: 1.2rem; | ||
| -webkit-text-stroke-color: currentColor; | ||
| stroke: currentColor; | ||
| -webkit-text-stroke-width: 16px; | ||
| stroke-width: 16px; | ||
| } | ||
| CSS | ||
| ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ciar4n I've added this css for demo purposes I guess you will come up with something better in the template level
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The majority of SVG icons would be displayed inline so might be an idea to apply the styling for that by default... svg {
display: inline-block;
font-size: inherit;
max-height: 1em;
} |
||
| ?> | ||
| <form id="login-form-<?php echo $module->id; ?>" class="mod-login" action="<?php echo Route::_('index.php', true); ?>" method="post"> | ||
|
|
||
|
|
@@ -37,9 +51,20 @@ | |
| <input id="modlgn-username-<?php echo $module->id; ?>" type="text" name="username" class="form-control" autocomplete="username" placeholder="<?php echo Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>"> | ||
| <span class="input-group-append"> | ||
| <label for="modlgn-username-<?php echo $module->id; ?>" class="sr-only"><?php echo Text::_('MOD_LOGIN_VALUE_USERNAME'); ?></label> | ||
| <span class="input-group-text" title="<?php echo Text::_('MOD_LOGIN_VALUE_USERNAME'); ?>"> | ||
| <span class="fas fa-user" aria-hidden="true"></span> | ||
| </span> | ||
| <span class="input-group-text"><?php echo Factory::getDocument()->setIcon( | ||
| [ | ||
| 'provider' => 'fontawesome-free', | ||
| 'group' => 'solid', | ||
| 'icon' => 'user', | ||
| 'classes' => 'demo-class', | ||
| 'text' => Text::_('MOD_LOGIN_VALUE_USERNAME'), | ||
| 'attributes' => [ | ||
| 'data-foo' => 'bar', | ||
| 'id' => 'foobar' | ||
| ] | ||
| ] | ||
| ); | ||
| ?></span> | ||
| </span> | ||
| </div> | ||
| <?php else : ?> | ||
|
|
||
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.
Why the option to state a provider? Is this really needed?
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 guess we want 3pd to roll their own icon sets. Hardcoding this to Font Awesome (by the way it's the fallback, meaning for the core you could ignore this or the group option below, if the icon is in the group solid) is rather limiting
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 I'm missing something but most custom SVGs would not require any of the following...
Even with FA these are mostly covered by the
classoption.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.
These options actually resolve the path to the icon... The icons are not stored in the same directory
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.
Does that mean that these are required?