Skip to content

Commit 118db3e

Browse files
committed
DOC-3329: Refactor creating-an-icon-pack and seperating the template-tool guide to clarify setup to support NPM package installations.
1 parent 18b4deb commit 118db3e

File tree

3 files changed

+235
-175
lines changed

3 files changed

+235
-175
lines changed

modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
*** xref:customize-ui.adoc[Customizing the UI]
105105
*** xref:creating-a-skin.adoc[Create a skin]
106106
*** xref:creating-an-icon-pack.adoc[Create an icon pack]
107+
*** xref:using-the-icon-pack-template.adoc[Using the icon pack template tool]
107108
** Images Guide
108109
*** xref:upload-images.adoc[Image uploads]
109110
*** xref:php-upload-handler.adoc[PHP image upload handler]
Lines changed: 50 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,231 +1,106 @@
11
= Create an icon pack for {productname}
22
:navtitle: Create an icon pack
33
:description_short: Introducing icon pack creation.
4-
:description: How to make your own icon pack.
4+
:description: How to create a custom icon pack.
55
:keywords: create, creator, icon
66

77
== Overview
88

9-
This guide provides comprehensive coverage of creating, building, and deploying custom icon packs, including solutions to common issues.
9+
This guide provides comprehensive coverage of creating, building, and deploying custom icon packs, including solutions to common issues. It details two approaches:
1010

11-
== Prerequisites
12-
13-
This guide assumes:
14-
15-
* Familiarity with the command line and running commands
16-
* https://nodejs.org/en/[Node.js] and https://www.npmjs.com/[NPM] are already installed
17-
* Optional: https://git-scm.com/[git] is already installed
11+
* The inline approach, for adding a small number of custom icons
12+
* The icon file approach, using the Icon Pack Template project to easily generate the required output file from a folder of SVGs.
1813

1914
== How Icons Work in {productname}
2015

21-
A {productname} icon pack is a `+.js+` file containing strings of link:https://developer.mozilla.org/en-US/docs/Web/SVG[SVG's]. An icon pack can be used: to include one or more custom icons; or to replace some or all of the default {productname} icons.
16+
A {productname} icon pack is a JavaScript construct containing strings of link:https://developer.mozilla.org/en-US/docs/Web/SVG[SVG's]. Icon packs are often kept in separate files, but can be inlined if needed. An icon pack can be used to add one or more custom icons or to replace some or all of the default {productname} icons.
2217

2318
An icon pack only **requires** the custom icons to be included; the default {productname} icons are used as a fallback for icons missing from the custom icon pack.
2419

25-
=== Icon Pack Structure and Loading
26-
27-
[IMPORTANT]
28-
====
29-
*Understanding Icon Pack Loading:*
30-
31-
{productname} loads icon packs from the path `+TINYMCE_BASE/icons/{iconPackName}/icons.js+`, where:
32-
33-
* `TINYMCE_BASE` is the {productname} root directory (the directory containing `tinymce.min.js`).
34-
* `+{iconPackName}+` is the name of the icon pack.
20+
== Registering an icon pack
3521

36-
**Example Directory Structure:**
37-
----
38-
js/tinymce/
39-
├── tinymce.min.js ← TINYMCE_BASE marker file
40-
├── icons/
41-
│ ├── default/
42-
│ │ └── icons.js ← Default TinyMCE icons
43-
│ └── my_icon_pack/ ← Your custom pack
44-
│ └── icons.js ← Must be exactly this filename
45-
└── ... (other TinyMCE files)
46-
----
47-
====
48-
49-
=== Icon Pack File Format
50-
51-
The generated `icons.js` file in the `+dist/icons/{iconPackName}/icons.js+` directory follows this exact format:
22+
Icon packs are registered with {productname} using the IconManager. Whether creating the icon pack manually or using the Icon Pack Template tool, the JavaScript required to setup an icon pack looks like:
5223

5324
[source,javascript]
5425
----
55-
tinymce.IconManager.add('your-pack-name', {
26+
tinymce.IconManager.add('custom-pack-name', {
5627
icons: {
57-
'bold': '<svg width="24" height="24">...</svg>', // this is automatically generated from the 'bold.svg' file in the 'src/svg' directory
28+
'bold': '<svg width="24" height="24">...</svg>',
5829
'italic': '<svg width="24" height="24">...</svg>',
5930
'custom-icon': '<svg width="24" height="24">...</svg>',
6031
// ... more icons
6132
}
6233
});
6334
----
6435

65-
== Creating a TinyMCE Icon Pack
66-
67-
To create a custom icon pack:
68-
69-
* xref:download-and-setup-the-icon-pack-template[Download and setup the icon pack template]
70-
* xref:add-the-svg-files[Add the SVG files]
71-
* xref:build-the-icon-pack[Build the icon pack]
36+
== Creating an icon pack manually
7237

73-
=== Download and Setup the Icon Pack Template
38+
When adding only a few icons, it may be easier to manually configure the new icon pack than to use the Icon Pack Template tool. To do this:
7439

75-
To use the {productname} icon pack template project:
40+
. Gather the SVG files for the new icons. Extract their content string, e.g. `+<svg width="24" height="24">...</svg>+`
41+
. Call `+tinymce.IconManager.add()+`
42+
. Specify the icon pack name as the first argument
43+
. The second argument is an object, with key `+icons+` and a nested object containing the new icons with their names and SVG strings as their keys and values.
7644

77-
. Download the link:https://github.com/tinymce/oxide-icon-pack-template[TinyMCE Oxide Icon Pack Template] by either:
78-
* Downloading the `.zip` file from the link:https://github.com/tinymce/oxide-icon-pack-template[Oxide Icon Pack Template GitHub page] and extract the contents.
79-
* From a terminal or command prompt, use git to clone the GitHub repository:
80-
+
81-
[source,bash]
82-
----
83-
git clone https://github.com/tinymce/oxide-icon-pack-template.git
84-
----
85-
+
86-
. Open a terminal or command prompt, navigate to the `oxide-icon-pack-template` directory.
87-
. Install the project dependencies by executing:
88-
+
89-
[source,bash]
90-
----
91-
npm install
92-
----
93-
+
94-
. When prompted, enter a name for the icon pack. The icon pack name should only contain:
95-
* Numbers
96-
* Letters
97-
* Hyphens (`-`)
98-
* Underscores (`_`)
99-
+
100-
. Verify that the `iconPackName` field has been added to your `package.json` file:
101-
+
102-
[source,json]
103-
----
104-
{
105-
"iconPackName": "my_icon_pack",
106-
}
107-
----
108-
109-
The icon pack name will be used with the link:https://www.tiny.cloud/docs/tinymce/latest/editor-icons/#icons[icons] option to apply the icons in {productname}.
45+
The new icons can then be used by name within {productname}.
11046

11147
[IMPORTANT]
11248
====
113-
The `iconPackName` field in `package.json` is essential for the build process. This field:
114-
115-
* Defines the name that will be used in the generated `icons.js` file
116-
* Must match the name you use in the `icons` option when initializing {productname}
117-
* Is used by the build system to create the proper directory structure
118-
* If missing or incorrect, the icon pack will not work properly
119-
120-
*Example:*
121-
122-
* `package.json` contains: `"iconPackName": "my_icon_pack"`
123-
* {productname} config uses: `icons: 'my_icon_pack'`
124-
* Generated file: `tinymce.IconManager.add('my_icon_pack', {...})`
49+
*Icon Override:* If custom icons have the same name as a default {productname} icon, they will override the default icon.
12550
====
12651

127-
=== Add the SVG Files
52+
This JavaScript can be included as a separate icon file or inlined beside the application's `+tinymce.init()+` call. Configure {productname} to load the icon pack and possibly where from.
12853

129-
Each SVG files placed in `+/src/svg+` will be converted to an icon. The file names of the SVG files are used to set the icon identifier used by {productname}.
54+
[NOTE]
55+
====
56+
*Naming Icon Pack Files:* When loading icon packs from a separate file, it is safest to name the file `+icons.js+`. This ensures that, if placed in the default location, {productname} will recognize the file as an icon pack.
57+
====
13058

131-
For example: `+bold.svg+` will have the identifier `bold`. Such as:
59+
=== Example: using a custom icon pack inline
13260

13361
[source,js]
13462
----
63+
tinymce.IconManager.add('customIcons', { // icon pack name
64+
icons: { // list icons as name-SVG pairs
65+
'my-custom-icon': '<svg width="24" height="24">...</svg>',
66+
}
67+
});
68+
13569
tinymce.init({
136-
selector: '#tiny_custom_button', // change this value according to your HTML
137-
toolbar: 'myButton',
138-
icons: 'my_icon_pack',
139-
setup: (editor) => {
140-
editor.ui.registry.addButton('myButton', {
141-
icon: 'bold', // the 'bold' icon created from 'bold.svg'
142-
onAction: (_) => {
143-
editor.insertContent('&nbsp;<strong>It\'s my icon button!</strong>&nbsp;');
144-
}
70+
selector: '#editor',
71+
icons: 'customIcons', // tell {productname} to load the custom icon pack
72+
toolbar: 'myCustomButton',
73+
setup: function(editor) {
74+
editor.ui.registry.addToolbarButton('myCustomButton', {
75+
icon: 'my-custom-icon' // use the custom icon for a custom toolbar button
14576
});
14677
}
14778
});
14879
----
14980

150-
For a list of default icon identifiers, see: link:https://www.tiny.cloud/docs/tinymce/latest/editor-icon-identifiers/[Available icons]. If using a custom icon pack, the icon identifiers will be the file names of the SVG files.
151-
152-
[NOTE]
153-
====
154-
* {productname} does **not** resize the SVGs provided, relying on the size defined in the SVG. This allows icons of different sizes to be used in the editor. The Toolbar button sizes are independent of the icon sizes. To change button sizes, a link:https://www.tiny.cloud/docs/tinymce/latest/creating-a-skin/[custom skin] is required.
155-
* *SVG Requirements:* Input SVGs must be shapes, not strokes. SVG files containing strokes will not render correctly. If the input files contain strokes, use a graphics program to convert the strokes into shapes.
156-
====
157-
158-
==== SVG File Organization
159-
160-
Organize your SVG files in the `src/svg/` directory:
161-
162-
[source]
163-
----
164-
src/svg/
165-
├── bold.svg ← Overrides default bold icon
166-
├── italic.svg ← Overrides default italic icon
167-
├── underline.svg ← Overrides default underline icon
168-
├── my-custom-icon.svg ← Creates new 'my-custom-icon' identifier
169-
├── company-logo.svg ← Creates new 'company-logo' identifier
170-
└── save-action.svg ← Creates new 'save-action' identifier
171-
----
172-
173-
*Icon Identifier Rules:*
174-
175-
* Filename becomes the identifier: `+bold.svg+` → `+'bold'+`
176-
* Hyphens are preserved: `+my-custom-icon.svg+` → `+'my-custom-icon'+`
177-
178-
=== Build the Icon Pack
81+
== Using the Icon Pack Template tool
17982

180-
To build the icon pack using Gulp:
83+
For large custom icon packs, use the xref:using-the-icon-pack-template.adoc[Icon Pack Template tool], which can take a folder of SVGs and generate the required output file. This approach is ideal when creating icon packs with many icons or when automating the build process.
18184

182-
. Open a terminal or command prompt and navigate to the root directory of the icon pack (such as: `+oxide-icon-pack-template/+`).
183-
. Build the icon pack by executing the `npx gulp` command:
184-
+
185-
[source,bash]
186-
----
187-
npx gulp
188-
----
189-
+
190-
A `+dist/+` directory containing the icon pack will be automatically created.
191-
+
192-
.Example: `+dist/icons/my-icon-pack/icons.js+` automatically generated from the SVG files in the `+src/svg+` directory.
193-
[source,js]
194-
----
195-
tinymce.IconManager.add('my-icon-pack', {
196-
icons: {
197-
'audio': '<svg width="24" height="24"><path d="M10.8 19q.9 0 1.5-.7t.7-1.5V13h3v-2h-4v3.9l-.6-.3-.6-.1q-1 0-1.7.7t-.6 1.6q0 .9.7 1.5t1.6.7ZM6 22q-.8 0-1.4-.6T4 20V4q0-.8.6-1.4T6 2h8l6 6v12q0 .8-.6 1.4T18 22H6Zm7-13h5l-5-5v5Z"/></svg>',
198-
'bold': '<svg width="24" height="24"><path fill-rule="evenodd" d="M3.6 2.3a1.4 1.4 0 0 0-1.4 1.3v16.8c0 .7.7 1.4 1.4 1.4h16.8a1.4 1.4 0 0 0 1.4-1.4V3.6a1.4 1.4 0 0 0-1.4-1.3H3.6Zm6 4a1.4 1.4 0 0 0-1.3 1.3v9.3c0 .7.6 1.4 1.3 1.4H12v-.8.8a2.5 2.5 0 0 0 .2 0 4.6 4.6 0 0 0 1.6-.5c.5-.2 1-.5 1.3-1 .4-.5.7-1.2.7-2 0-.9-.3-1.6-.7-2a3.2 3.2 0 0 0-.8-.9 2.8 2.8 0 0 0 .4-.5c.4-.5.5-1.1.5-1.9s-.1-1.4-.5-1.9a3 3 0 0 0-1.1-1 3.9 3.9 0 0 0-1.6-.3H9.6Zm.1 6.5H12a3.2 3.2 0 0 1 1.2.2l.7.6c.2.2.4.6.4 1.1s-.2 1-.4 1.2a1.8 1.8 0 0 1-.7.6 3.2 3.2 0 0 1-1.1.2H9.7v-4Zm2.3 4Zm0-5.6H9.7V7.8H12l1 .2.5.5c.1.2.3.5.3 1s-.2.8-.3 1a1.4 1.4 0 0 1-.6.5 2.3 2.3 0 0 1-.9.2Z" clip-rule="evenodd"/></svg>',
199-
'italic': '<svg width="24" height="24"><path fill-rule="evenodd" d="M3.6 2.3a1.4 1.4 0 0 0-1.4 1.3v16.8c0 .7.7 1.4 1.4 1.4h16.8a1.4 1.4 0 0 0 1.4-1.4V3.6a1.4 1.4 0 0 0-1.4-1.3H3.6ZM16 6.8h-1.5L11 17.1h1a.8.8 0 0 1 0 1.6H8a.8.8 0 0 1 0-1.6h1.5L13 6.8h-1a.8.8 0 0 1 0-1.5h4a.8.8 0 0 1 0 1.5Z" clip-rule="evenodd"/></svg>',
200-
}
201-
});
202-
----
203-
+
204-
. Using a web browser, open `+dist/html/icons.html+` to preview the icons.
85+
For step-by-step instructions, see: xref:using-the-icon-pack-template.adoc[Using the Icon Pack Template tool].
20586

206-
==== Troubleshooting Information for Building Icon Packs
87+
== Deploying an Icon Pack file
20788

208-
The SVG files are optimized during the build process with link:https://github.com/svg/svgo[SVGO]. The optimization can result in distorted graphics due to rounding errors. The graphics may be fixed by providing new SVGO options. To change the SVGO options used:
89+
An icon pack file can be served either:
20990

210-
. Using a text editor, open `+gulpfile.js+`.
211-
. Add the `+svgo+` option to the `+iconPackager+` function, such as:
212-
+
213-
[source,javascript]
214-
----
215-
iconPackager({
216-
name: 'my-icon-pack',
217-
svgo: { floatPrecision: 3 } //Increase the rounding precision
218-
})
219-
----
91+
* With {productname}
92+
* Separate from {productname}
22093

221-
All user defined options, including SVGO options, will merge with the default options. For information on SVGO options, see: link:https://github.com/svg/svgo[SVGO on GitHub].
94+
Use the xref:editor-icons.adoc#icons[`+icons+`] and xref:editor-icons.adoc#icons_url[`+icons_url+`] options to configure {productname} appropriately.
22295

223-
== Deploying an Icon Pack
96+
[NOTE]
97+
====
98+
*Default Icon Pack Location:*
22499
225-
An icon pack can be served either:
100+
The `+icons+` option will only recognize icon files located at `+TINYMCE_BASE/icons/${iconPackName}/icons.js+`; where:
226101
227-
* xref:deploy-the-icon-pack-with-tinymce[With {productname}]
228-
* xref:deploy-the-icon-pack-and-tinymce-separately[Separate from {productname}]
102+
* `+TINYMCE_BASE+` is the {productname} root directory (the directory containing `+tinymce.min.js+`).
103+
====
229104

230105
[[deploy-the-icon-pack-with-tinymce]]
231106
=== Deploy the Icon Pack with {productname}
@@ -241,6 +116,6 @@ include::partial$configuration/icons_url.adoc[]
241116

242117
== Interactive Demo
243118

244-
See the custom icon pack in action with our interactive demo:
119+
See the custom icon pack in action with the interactive demo:
245120

246121
liveDemo::custom-icon-pack[]

0 commit comments

Comments
 (0)