--- import DefaultLayout from '@shared/layouts/DefaultLayout.astro' import CaptureScript from '@shared/components/CaptureScript.astro' import Card from '@ui/Card.astro' import CardBody from '@ui/CardBody.astro' import CardTitle from '@ui/CardTitle.astro' import CardSubtitle from '@ui/CardSubtitle.astro' import DocsLink from '@ui/DocsLink.astro' import SwitchIcon from '@ui/SwitchIcon.astro' import ButtonList from '@ui/ButtonList.astro' const icons = [ { icon: 'heart', color: 'red', label: 'Like' }, { icon: 'star', color: 'yellow', label: 'Add to favorites' }, { icon: 'bookmark', color: 'primary', label: 'Bookmark' }, { icon: 'bell', color: 'orange', label: 'Notify me' }, { icon: 'thumb-up', color: 'blue', label: 'Vote up' }, ] /** core/scss/ui/_switch-icon.scss `.switch-icon-{variant}` */ const variants = ['fade', 'scale', 'flip', 'slide-up', 'slide-down', 'slide-start', 'slide-end'] as const const pairs = [ { a: 'check', b: 'x', color: 'red', label: 'Toggle' }, { a: 'player-play', b: 'player-pause', color: 'primary', label: 'Play' }, { a: 'volume', b: 'volume-off', color: 'secondary', label: 'Mute' }, { a: 'eye', b: 'eye-off', color: 'secondary', label: 'Hide' }, { a: 'lock-open', b: 'lock', color: 'green', label: 'Lock' }, ] const repos = [ { name: 'tabler/tabler', description: 'Dashboard UI kit', starred: true }, { name: 'tabler/tabler-icons', description: '5900+ free SVG icons', starred: true }, { name: 'tabler/tabler-react', description: 'React components', starred: false }, { name: 'tabler/tabler-emails', description: 'Responsive email templates', starred: false }, ] ---
Basic A SwitchIcon swaps the outline icon for the filled one in activeColor. {icons.map((item) => )}
Animations Pick a transition with variant: fade, scale, flip or one of the slides. {variants.map((variant) => )}
Two icons Set activeIcon to switch to a different icon instead of the filled variant. {pairs.map((pair) => )}
In an action button Add action to wrap the switch in a btn-action, which then carries the toggle, hover and focus.
{icons.map((item) => )}
Loading Add loading to show a spinner in place of the icons; clicks are ignored.
Wait for a request Pass a promise to event.wait() and the switch waits for it. The last one fails and stays as it was.
In a list The event bubbles, so one listener on the list keeps the count in sync.
{ repos.map((repo) => (
{repo.name}
{repo.description}
)) }
{repos.filter((repo) => repo.starred).length} starred