Skip to content

Commit 8f4ff4d

Browse files
Update index.rst
1 parent 1460cd2 commit 8f4ff4d

File tree

1 file changed

+23
-82
lines changed

1 file changed

+23
-82
lines changed

src/Icons/doc/index.rst

Lines changed: 23 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,37 @@ refers to the icons located in the ``header`` directory.
5959
Loading Icons
6060
-------------
6161

62+
To include an icon in your template, two syntaxes are available.
63+
64+
.. tip::
65+
66+
To use the HTML syntax, you need the ``symfony/ux-twig-component`` package:
67+
68+
.. code-block:: terminal
69+
70+
$ composer require symfony/ux-twig-component
71+
72+
6273
.. code-block:: twig
6374
64-
{# includes the contents of the 'assets/icons/user-profile.svg' file in the template #}
75+
{# Includes the contents of 'assets/icons/user-profile.svg' in the template: #}
6576
{{ ux_icon('user-profile') }}
77+
{# Same in alternative HTML syntax: #}
78+
<twig:ux:icon name="user-profile" />
6679
67-
{# icons stored in subdirectories must use the 'subdirectory_name:file_name' syntax
68-
(e.g. this includes 'assets/icons/admin/user-profile.svg') #}
80+
{# Includes 'assets/icons/admin/user-profile.svg': #}
6981
{{ ux_icon('admin:user-profile') }}
82+
<twig:ux:icon name="admin:user-profile" />
7083
71-
{# this downloads the 'user-solid.svg' icon from the 'Flowbite' icon set via ux.symfony.com
72-
and embeds the downloaded SVG contents in the template #}
73-
{{ ux_icon('flowbite:user-solid') }}
74-
75-
The ``ux_icon()`` function defines a second optional argument where you can
76-
define the HTML attributes added to the ``<svg>`` element:
77-
78-
.. code-block:: html+twig
84+
{# Adding a CSS class or other attribute to the `<svg>` element: #}
85+
{{ ux_icon('user-profile', {class: 'w-4', 'aria-hidden': 'true' }) }}
86+
<twig:ux:icon name="user-profile" class="w-4" aria-hidden="true" />
7987
80-
{{ ux_icon('user-profile', {class: 'w-4 h-4'}) }}
81-
{# renders <svg class="w-4 h-4"> ... </svg> #}
88+
{# Download the 'user-solid.svg' icon from the 'Flowbite' icon set via ux.symfony.com: #}
89+
{{ ux_icon('flowbite:user-solid') }}
90+
<twig:ux:icon name="flowbite:user-solid" />
8291
83-
{{ ux_icon('user-profile', {height: '16px', width: '16px', 'aria-hidden': true}) }}
84-
{# renders <svg height="16" width="16" aria-hidden="true"> ... </svg> #}
92+
You can set default attributes for all icons in your `Configuration`_.
8593

8694

8795
Icon Sets
@@ -170,34 +178,6 @@ icons in the "Tabler Icons" set, use the following command:
170178
Page 1/3. Continue? (yes/no) [yes]:
171179
>
172180
173-
HTML Syntax
174-
~~~~~~~~~~~
175-
176-
In addition to the ``ux_icon()`` function explained in the previous sections,
177-
this package also supports an alternative HTML syntax based on the ``<twig:ux:icon>``
178-
tag:
179-
180-
.. code-block:: html
181-
182-
<!-- renders "user-profile.svg" -->
183-
<twig:ux:icon name="user-profile" class="w-4 h-4" />
184-
<!-- renders "admin/user-profile.svg" -->
185-
<twig:ux:icon name="admin:user-profile" class="w-4 h-4" />
186-
<!-- renders 'user-solid.svg' icon from 'Flowbite' icon set via ux.symfony.com -->
187-
<twig:ux:icon name="flowbite:user-solid" />
188-
189-
<!-- you can also add any HTML attributes -->
190-
<twig:ux:icon name="user-profile" height="16" width="16" aria-hidden="true" />
191-
192-
.. tip::
193-
194-
To use the HTML syntax, the ``symfony/ux-twig-component`` package must be
195-
installed in your project:
196-
197-
.. code-block:: terminal
198-
199-
$ composer require symfony/ux-twig-component
200-
201181
Downloading Icons
202182
-----------------
203183

@@ -318,45 +298,6 @@ Rendering Icons
318298
and embeds the downloaded SVG contents in the template #}
319299
{{ ux_icon('flowbite:user-solid') }}
320300
321-
HTML Syntax
322-
~~~~~~~~~~~
323-
324-
.. code-block:: html+twig
325-
326-
<twig:ux:icon name="user-profile" />
327-
328-
{# Renders "user-profile.svg" #}
329-
<twig:ux:icon name="user-profile" class="w-4 h-4" />
330-
331-
{# Renders "sub-dir/user-profile.svg" (sub-directory) #}
332-
<twig:ux:icon name="sub-dir:user-profile" class="w-4 h-4" />
333-
334-
{# Renders "flowbite:user-solid" from ux.symfony.com #}
335-
<twig:ux:icon name="flowbite:user-solid" />
336-
337-
Default Attributes
338-
~~~~~~~~~~~~~~~~~~
339-
340-
You can set default attributes for all icons in your configuration. These attributes will be
341-
added to all icons unless overridden by the second argument of the ``ux_icon`` function.
342-
343-
.. code-block:: yaml
344-
345-
# config/packages/ux_icons.yaml
346-
ux_icons:
347-
default_icon_attributes:
348-
fill: currentColor
349-
350-
Now, all icons will have the ``fill`` attribute set to ``currentColor`` by default.
351-
352-
.. code-block:: twig
353-
354-
# renders "user-profile.svg" with fill="currentColor"
355-
{{ ux_icon('user-profile') }}
356-
357-
# renders "user-profile.svg" with fill="red"
358-
{{ ux_icon('user-profile', {fill: 'red'}) }}
359-
360301
Icon Aliases
361302
~~~~~~~~~~~~
362303

0 commit comments

Comments
 (0)