Adding Icons
Using our API, you can register your own icon sets for usage within the CE.SDK editor. The API is as follows:
Add new Icon Set#
cesdk.ui.addIconSet(id: string, svgSprite: string)
The icon set is a string containing a SVG
sprite with symbols. The id of each symbol is used to reference the icon
in the editor. These ids need to start with a @
to be recognized in the
editor.
Please Note: The SVG sprite will be injected into the (shadow) DOM without any sanitization. Make sure to only use trusted sources to prevent e.g. XSS attacks. If you are unsure about the source of the sprite, consider using libraries like DOMPurify to sanitize the SVG string before adding it.
Examples#
Register an Icon Set#
Registering an SVG string with a single symbol might look like this:
cesdk.ui.addIconSet('@imgly/custom',`<svg><symbolfill="none"xmlns="http://www.w3.org/2000/svg"viewBox="0 0 16 16"id="@some/icon/ZoomIn"><pathfillRule="evenodd"clipRule="evenodd"d="M3 7.5C3 5.01472 5.01472 3 7.5 3C9.98528 3 12 5.01472 12 7.5C12 9.98528 9.98528 12 7.5 12C5.01472 12 3 9.98528 3 7.5ZM7.5 2C4.46243 2 2 4.46243 2 7.5C2 10.5376 4.46243 13 7.5 13C8.74835 13 9.89957 12.5841 10.8226 11.8833L10.9697 12.0303L12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L12.0303 10.9697L11.8833 10.8226C12.5841 9.89957 13 8.74835 13 7.5C13 4.46243 10.5376 2 7.5 2ZM7 7V5H8V7H10V8H8V10H7V8H5V7H7Z"fill="currentColor"fillOpacity="0.9"/></symbol></svg>`);
Replace a Dock Icon#
You could use your custom icon set to replace the "Image" icon of the default Dock:
cesdk.ui.setDockOrder( cesdk.ui.getDockOrder().map((entry) => {if (entry.key === 'ly.img.image') return ({...entry,"icon": "@some/icon/ZoomIn", // Note the ID referencing the SVG symbol})else return entry;}))
Use within a custom Component#
Using your new symbol in a custom component is then done by referencing the symbol ID directly:
cesdk.ui.registerComponent('CustomIcon',({ builder: { Button } }) => {Button('customIcon', {label: 'Custom Icon',icon: '@some/icon/ZoomIn', // Note the ID referencing the SVG symbolonClick: () => {console.log('Custom Icon clicked');}});});
Built-In Icons#
These built-in icons can be referenced by their name string directly:
Name | Icon |
---|---|
Name '@imgly/Template' | Icon |
Name '@imgly/Image' | Icon |
Name '@imgly/Video' | Icon |
Name '@imgly/Audio' | Icon |
Name '@imgly/Text' | Icon |
Name '@imgly/Shapes' | Icon |
Name '@imgly/Sticker' | Icon |
Name '@imgly/Upload' | Icon |
Name '@imgly/Library' | Icon |
Name '@imgly/CustomLibrary' | Icon |