@@ -5,7 +5,7 @@ Renders local and remote SVG icons in your Twig templates.
5
5
6
6
.. code-block :: html+twig
7
7
8
- {{ ux_icon('mdi:symfony ', {class: 'w-4 h-4'}) }}
8
+ {{ ux_icon('mdi:check ', {class: 'w-4 h-4'}) }}
9
9
{# or #}
10
10
<twig:UX: Icon name="mdi:check" class="w-4 h-4" />
11
11
@@ -19,10 +19,60 @@ Installation
19
19
20
20
$ composer require symfony/ux-icons
21
21
22
- Icons?
22
+ Icons
23
23
------
24
24
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
+ -------------
26
76
27
77
Local SVG Icons
28
78
~~~~~~~~~~~~~~~
@@ -31,6 +81,23 @@ Add your svg icons to the ``assets/icons/`` directory and commit them.
31
81
The name of the file is used as the _name_ of the icon (``name.svg `` will be named ``name ``).
32
82
If located in a subdirectory, the _name_ will be ``sub-dir:name ``.
33
83
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
+
34
101
Icons On-Demand
35
102
~~~~~~~~~~~~~~~
36
103
@@ -39,7 +106,7 @@ from many different sets. This package provides a way to include any icon found
39
106
40
107
1. Visit `ux.symfony.com/icons `_ and search for an icon
41
108
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).
43
110
3. That's it!
44
111
45
112
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
76
143
many _on-demand _ icons. You can think of importing the icon as *locking it * (similar to how
77
144
``composer.lock `` _locks_ your dependencies).
78
145
79
- Usage
80
- -----
146
+
147
+ Rendering Icons
148
+ ---------------
81
149
82
150
.. code-block :: html+twig
83
151
@@ -87,23 +155,74 @@ Usage
87
155
88
156
{{ ux_icon('flowbite:user-solid') }} <!-- renders "flowbite:user-solid" from ux.symfony.com -->
89
157
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
+
90
195
HTML Syntax
91
196
~~~~~~~~~~~
92
197
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
+
93
212
.. note ::
94
213
95
214
``symfony/ux-twig-component `` is required to use the HTML syntax.
96
215
97
- .. code-block :: html
98
-
99
- <twig:UX:Icon name =" user-profile" class =" w-4 h-4" /> <!-- renders "user-profile.svg" -->
100
216
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
+ ------------
102
219
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.
104
223
105
- Caching
106
- -------
224
+ Icon Caching
225
+ ~~~~~~~~~~~~
107
226
108
227
To avoid having to parse icon files on every request, icons are cached.
109
228
@@ -113,7 +232,7 @@ In production, you can pre-warm the cache by running the following command:
113
232
114
233
$ php bin/console ux:icons:warm-cache
115
234
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.
117
236
118
237
.. note ::
119
238
@@ -124,20 +243,55 @@ This command looks in all your twig templates for ``ux_icon`` calls and caches t
124
243
125
244
If using `symfony/asset-mapper `_, the cache is warmed automatically when running ``asset-map:compile ``.
126
245
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
+ -------------
129
271
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
+ ~~~~~~~~~~~~~~~~~~~~~~~
132
284
133
285
.. code-block :: terminal
134
286
135
- # displays the default config values defined by Symfony
287
+ # Displays the default config values
136
288
$ php bin/console config:dump-reference ux_icons
137
289
138
- # displays the actual config values used by your application
290
+ # Displays the actual config values used by your application
139
291
$ php bin/console debug:config ux_icons
140
292
293
+ Full Configuration
294
+ ~~~~~~~~~~~~~~~~~~
141
295
142
296
.. code-block :: yaml
143
297
@@ -157,6 +311,12 @@ options are configured under the ``ux_icons`` key in your application configurat
157
311
# The endpoint for the Iconify API.
158
312
endpoint : ' https://api.iconify.design'
159
313
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
+
160
320
.. _`ux.symfony.com/icons` : https://ux.symfony.com/icons
161
321
.. _`Iconify` : https://iconify.design
162
322
.. _`symfony/asset-mapper` : https://symfony.com/doc/current/frontend/asset_mapper.html
0 commit comments