Skip to content

Commit b974e3b

Browse files
committed
Add some documentation
(not against some help) The ideal would be to iterate some small merges every days.. as soon it becomes "bigger" i'm lost in those mad RST files
1 parent 83b89a0 commit b974e3b

File tree

1 file changed

+180
-20
lines changed

1 file changed

+180
-20
lines changed

src/Icons/doc/index.rst

Lines changed: 180 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Renders local and remote SVG icons in your Twig templates.
55

66
.. code-block:: html+twig
77

8-
{{ ux_icon('mdi:symfony', {class: 'w-4 h-4'}) }}
8+
{{ ux_icon('mdi:check', {class: 'w-4 h-4'}) }}
99
{# or #}
1010
<twig:UX:Icon name="mdi:check" class="w-4 h-4" />
1111

@@ -19,10 +19,60 @@ Installation
1919
2020
$ composer require symfony/ux-icons
2121
22-
Icons?
22+
Icons
2323
------
2424

25-
No icons are provided by this package but there are several ways to include and render icons.
25+
The ``symfony/ux-icons`` package aspires to offer simple and easy-to-use ways to
26+
handle SVG icons in your Symfony application.
27+
28+
SVG Icons
29+
~~~~~~~~~
30+
31+
[SVG](https://en.wikipedia.org/wiki/SVG) (Scalable Vector Graphics) is an XML-based
32+
vector image format. SVGs are a great way to add scalable, resolution-independent
33+
graphics to your website. They can be styled with CSS, combined, animated, reused..
34+
for a fraction of the file size of bitmap images.
35+
36+
Making them the perfect choice for icons.
37+
38+
39+
Icon Sets
40+
~~~~~~~~~
41+
42+
There are many icon sets available, each with their own unique style and set of icons.
43+
44+
45+
Icon identifiers
46+
~~~~~~~~~~~~~~~~
47+
48+
In the UX Icons component, icons are referenced using an unique identifier that
49+
follows one of the following syntaxes:
50+
51+
* ``prefix``:``name`` (e.g. ``mdi:check``, ``bi:check``, ``editor:align-left``)
52+
* ``name`` only (e.g. ``check``, ``close``, ``menu``)
53+
54+
Icon Name
55+
^^^^^^^^^
56+
57+
The ``name`` is the... name of the icon, without the file extension (e.g. ``check``).
58+
59+
.. caution::
60+
61+
The name must match a standard ``slug`` format: ``[a-z0-9-]+(-[0-9a-z])+``.
62+
63+
Icon Prefix
64+
^^^^^^^^^^^
65+
66+
Depending on your configuration, the ``prefix`` can be the name of an icon set, a directory
67+
where the icon is located, or a combination of both.
68+
69+
70+
For example, the `bi` prefix refers to the Bootstrap Icons set, while the `header` prefix
71+
refers to the icons located in the `header` directory.
72+
73+
74+
Loading Icons
75+
-------------
2676

2777
Local SVG Icons
2878
~~~~~~~~~~~~~~~
@@ -31,6 +81,23 @@ Add your svg icons to the ``assets/icons/`` directory and commit them.
3181
The name of the file is used as the _name_ of the icon (``name.svg`` will be named ``name``).
3282
If located in a subdirectory, the _name_ will be ``sub-dir:name``.
3383

84+
.. code-block:: text
85+
86+
your-project/
87+
├─ assets/
88+
│ └─ icons/
89+
│ ├─ bi/
90+
│ │ └─ pause-circle.svg
91+
│ │ └─ play-circle.svg
92+
│ ├─ header/
93+
│ │ ├─ logo.svg
94+
│ │ └─ menu.svg
95+
│ ├─ close.svg
96+
│ ├─ menu.svg
97+
│ └─ ...
98+
└─ ...
99+
100+
34101
Icons On-Demand
35102
~~~~~~~~~~~~~~~
36103

@@ -39,7 +106,7 @@ from many different sets. This package provides a way to include any icon found
39106

40107
1. Visit `ux.symfony.com/icons`_ and search for an icon
41108
you'd like to use. Once you find one you like, copy one of the code snippets provided.
42-
2. Paste the snippet into your twig template and the icon will be automatically fetched (and cached).
109+
2. Paste the snippet into your Twig template and the icon will be automatically fetched (and cached).
43110
3. That's it!
44111

45112
This works by using the `Iconify`_ API (to which `ux.symfony.com/icons`_
@@ -76,8 +143,9 @@ in the future. Additionally, the cache warming process will take significantly l
76143
many _on-demand_ icons. You can think of importing the icon as *locking it* (similar to how
77144
``composer.lock`` _locks_ your dependencies).
78145

79-
Usage
80-
-----
146+
147+
Rendering Icons
148+
---------------
81149

82150
.. code-block:: html+twig
83151

@@ -87,23 +155,74 @@ Usage
87155

88156
{{ ux_icon('flowbite:user-solid') }} <!-- renders "flowbite:user-solid" from ux.symfony.com -->
89157

158+
HTML Attributes
159+
~~~~~~~~~~~~~~~
160+
161+
The second argument of the ``ux_icon`` function is an array of attributes to add to the icon.
162+
163+
.. code-block:: twig
164+
165+
{# renders "user-profile.svg" with class="w-4 h-4" #}
166+
{{ ux_icon('user-profile', {class: 'w-4 h-4'}) }}
167+
168+
{# renders "user-profile.svg" with class="w-4 h-4" and aria-hidden="true" #}
169+
{{ ux_icon('user-profile', {class: 'w-4 h-4', 'aria-hidden': true}) }}
170+
171+
Default Attributes
172+
~~~~~~~~~~~~~~~~~~
173+
174+
You can set default attributes for all icons in your configuration. These attributes will be
175+
added to all icons unless overridden by the second argument of the ``ux_icon`` function.
176+
177+
.. code-block:: yaml
178+
179+
# config/packages/ux_icons.yaml
180+
ux_icons:
181+
default_icon_attributes:
182+
fill: currentColor
183+
184+
Now, all icons will have the ``fill`` attribute set to ``currentColor`` by default.
185+
186+
.. code-block:: twig
187+
188+
# renders "user-profile.svg" with fill="currentColor"
189+
{{ ux_icon('user-profile') }}
190+
191+
# renders "user-profile.svg" with fill="red"
192+
{{ ux_icon('user-profile', {fill: 'red'}) }}
193+
194+
90195
HTML Syntax
91196
~~~~~~~~~~~
92197

198+
.. code-block:: html+twig
199+
200+
<twig:UX:Icon name="user-profile" />
201+
202+
{# Renders "user-profile.svg" #}
203+
<twig:UX:Icon name="user-profile" class="w-4 h-4" />
204+
205+
{# Renders "sub-dir/user-profile.svg" (sub-directory) #}
206+
<twig:UX:Icon name="sub-dir:user-profile" class="w-4 h-4" />
207+
208+
{# Renders "flowbite:user-solid" from ux.symfony.com #}
209+
<twig:UX:Icon name="flowbite:user-solid" />
210+
211+
93212
.. note::
94213

95214
``symfony/ux-twig-component`` is required to use the HTML syntax.
96215

97-
.. code-block:: html
98-
99-
<twig:UX:Icon name="user-profile" class="w-4 h-4" /> <!-- renders "user-profile.svg" -->
100216

101-
<twig:UX:Icon name="sub-dir:user-profile" class="w-4 h-4" /> <!-- renders "sub-dir/user-profile.svg" (sub-directory) -->
217+
Performances
218+
------------
102219

103-
<twig:UX:Icon name="flowbite:user-solid" /> <!-- renders "flowbite:user-solid" from ux.symfony.com -->
220+
The UXIcon component is designed to be as fast as possible, while offering a
221+
great deal of flexibility. The following are some of the optimizations made to
222+
ensure the best performance possible.
104223

105-
Caching
106-
-------
224+
Icon Caching
225+
~~~~~~~~~~~~
107226

108227
To avoid having to parse icon files on every request, icons are cached.
109228

@@ -113,7 +232,7 @@ In production, you can pre-warm the cache by running the following command:
113232
114233
$ php bin/console ux:icons:warm-cache
115234
116-
This command looks in all your twig templates for ``ux_icon`` calls and caches the icons it finds.
235+
This command looks in all your Twig templates for ``ux_icon`` calls and caches the icons it finds.
117236

118237
.. note::
119238

@@ -124,20 +243,55 @@ This command looks in all your twig templates for ``ux_icon`` calls and caches t
124243

125244
If using `symfony/asset-mapper`_, the cache is warmed automatically when running ``asset-map:compile``.
126245

127-
Full Configuration Reference (UxIconsBundle)
128-
--------------------------------------------
246+
TwigComponent
247+
~~~~~~~~~~~~~
248+
249+
The ``ux_icon`` function is optimized to be as fast as possible. To deliver the same level
250+
of performance with the TwigComponent (``<twig:UX:Icon name="..." />``), the TwigComponent
251+
usual overhead is reduced to the bare minimum, immediately calling the IconRenderer and
252+
returning the HTML output.
253+
254+
.. warning::
255+
256+
The <twig:UX:Icon> component does not support embedded content.
257+
258+
.. code-block:: twig+html
259+
260+
{# The 🧸 will be ignore in the HTML output #}
261+
<twig:UX:Icon name="user-profile" class="w-4 h-4">🧸</twig:UX:Icon>
262+
263+
{# Renders "user-profile.svg" #}
264+
<svg viewBox="0 0 24 24" class="w-4 h-4">
265+
<path fill="currentColor" d="M21 7L9 19l-5.5-5.5l1.41-1.41L9 16.17L19.59 5.59z"/>
266+
</svg>
267+
268+
269+
Configuration
270+
-------------
129271

130-
The UXIconsBundle integrates seamlessly in Symfony applications. All these
131-
options are configured under the ``ux_icons`` key in your application configuration.
272+
The UXIcon integrates seamlessly in Symfony applications. All these options are configured under
273+
the ``ux_icons`` key in your application configuration.
274+
275+
.. code-block:: yaml
276+
277+
# config/packages/ux_icons.yaml
278+
ux_icons:
279+
{# ... #}
280+
281+
282+
Debugging Configuration
283+
~~~~~~~~~~~~~~~~~~~~~~~
132284

133285
.. code-block:: terminal
134286
135-
# displays the default config values defined by Symfony
287+
# Displays the default config values
136288
$ php bin/console config:dump-reference ux_icons
137289
138-
# displays the actual config values used by your application
290+
# Displays the actual config values used by your application
139291
$ php bin/console debug:config ux_icons
140292
293+
Full Configuration
294+
~~~~~~~~~~~~~~~~~~
141295

142296
.. code-block:: yaml
143297
@@ -157,6 +311,12 @@ options are configured under the ``ux_icons`` key in your application configurat
157311
# The endpoint for the Iconify API.
158312
endpoint: 'https://api.iconify.design'
159313
314+
Learn more
315+
----------
316+
317+
* :doc:`Creating and Using Templates </templates>`
318+
* :doc:`How to manage CSS and JavaScript assets in Symfony applications </frontend>`
319+
160320
.. _`ux.symfony.com/icons`: https://ux.symfony.com/icons
161321
.. _`Iconify`: https://iconify.design
162322
.. _`symfony/asset-mapper`: https://symfony.com/doc/current/frontend/asset_mapper.html

0 commit comments

Comments
 (0)