Icons

3 min read · Edit this page on GitHub(opens in new tab)
Every control icon in Tomato Player has a name, such as play, settings or fullscreen. You can replace any of them by name, from plain SVG markup or from React components. That includes animated icon libraries such as @animateicons/react.

Icon names

NameShown on
play, pause, replayplay button, big play button
volumeHigh, volumeLow, volumeMutedmute button
fullscreen, fullscreenExitfullscreen button
pippicture-in-picture button
captionscaptions button
settingssettings menu trigger
forward, backwardseek ±10 s buttons
next, previousplaylist and "next episode" buttons
castcast button
chapterschapters button
theatertheater mode (Tube)
check, chevronsettings menu marks

Where icons come from

The player looks an icon up in three places, in this order:
  1. The icons option of createPlayer, which is yours.
  2. The skin's own icon set.
  3. The built-in Tomato icons.
Each official skin ships its own set, drawn from a different open-source library:
SkinIconsLicense
MinimalTomato (built in)MIT
CinemaPhosphor, light weightMIT
StudioTabler, outlineMIT
CreatorLucideISC
LearnHeroicons, outlineMIT
CampusPhosphor, bold, with filled play and pauseMIT
StreamTabler, filledMIT
TubeMaterial Symbols RoundedApache 2.0
FeedHeroicons, solidMIT
Each skin package includes the license in THIRD_PARTY_NOTICES.md. The sets are generated by scripts/gen-icon-sets.py.

Replace icons with SVG markup

Pass trusted SVG markup by name. Names you leave out keep the skin's icons.
js
import { createPlayer } from '@tomato-player/core';
import { cinema } from '@tomato-player/skin-cinema';
​
createPlayer('#player', {
src: 'movie.mp4',
skin: cinema(),
icons: {
play: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>',
pause: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 5h4v14H7zM13 5h4v14h-4z"/></svg>',
},
});
The markup is inserted as-is, so only pass markup you control. Never pass user input. The player adds class="tp-icon", data-tp-icon="<name>" and aria-hidden="true". The button around the icon carries the accessible label.
A value can also be a function that returns an element. The player calls it each time a control shows that icon:
js
icons: {
settings: () => {
const el = document.createElement('span');
el.className = 'my-gear';
return el;
},
}

Give a skin its own icons

Pass icons to createSkin:
ts
import { createSkin } from '@tomato-player/ui';
​
export const aurora = createSkin({
name: 'aurora',
css,
icons: { play: '<svg ...>', settings: '<svg ...>' },
build(player, root) { /* ... */ },
});
Users of the skin can still override single icons, either with aurora({ icons: { ... } }) or with createPlayer({ icons }). In your own controls, render icons through icon(player, name) from @tomato-player/ui, not svg(icons.x), so these overrides apply.

Animated icons in React

<TomatoPlayer> from @tomato-player/react accepts React nodes in icons. Each node renders into its control through a portal, so animated components keep their motion and state:
tsx
'use client';
import { TomatoPlayer } from '@tomato-player/react';
import { minimal } from '@tomato-player/skin-minimal';
import { PauseIcon, PlayIcon, SettingsIcon, Volume2Icon, VolumeXIcon, MaximizeIcon, MinimizeIcon } from '@animateicons/react/lucide';
​
export function Video() {
return (
<TomatoPlayer
src="movie.mp4"
skin={minimal()}
icons={{
play: <PlayIcon size={24} />,
pause: <PauseIcon size={24} />,
settings: <SettingsIcon size={24} />,
volumeHigh: <Volume2Icon size={24} />,
volumeMuted: <VolumeXIcon size={24} />,
fullscreen: <MaximizeIcon size={24} />,
fullscreenExit: <MinimizeIcon size={24} />,
}}
/>
);
}
@animateicons/react icons animate when the pointer is over the glyph. To start the animation when the pointer enters the whole button, call the icon's startAnimation() from the button's pointerenter event. The website's apps/website/src/components/animated-icons.tsx shows how.
If you create the player yourself, useIconPortals(set) returns icons for createPlayer and portals to render:
tsx
const { icons, portals } = useIconPortals({ play: <PlayIcon />, pause: <PauseIcon /> });
useEffect(() => {
const player = createPlayer(ref.current!, { src, skin, icons });
return () => player.destroy();
}, [icons]);
return <>{portals}<div ref={ref} /></>;

Styling

Icons are sized by --tp-icon-size (22px by default) and use currentColor. Component icons render inside a <span class="tp-icon"> host, and the base CSS sizes the SVG inside it. Target one icon with [data-tp-icon='play']:
css
.tp[data-skin='aurora'] [data-tp-icon='play'] { fill: currentColor; }
PreviousCDN (jsDelivr)
NextAccessibility