Buttons buttonpremium

Animated Icon Button

A premium button generated dynamically from codebase.

Preview

Usage

Copy the full block below to use this component with its imports.

astro
---
import { AnimatedIconButton } from 'astro-component-kit';
---

<AnimatedIconButton href="#" type="button" variant="primary" size="md">Click Me</AnimatedIconButton>
--- import { AnimatedIconButton } from 'astro-component-kit'; --- <AnimatedIconButton href="#" type="button" variant="primary" size="md">Click Me</AnimatedIconButton>

Manual Installation

If you are not using the npm package, create a new file src/components/lib/AnimatedIconButton.astro and paste the following code:

astro
---
/**
 * AnimatedIconButton — A button that elegantly slides an icon into view on hover.
 * 
 * @param {string} href - Optional. If provided, renders an <a> tag instead of <button>.
 * @param {'button'|'submit'|'reset'} type - Optional. The HTML button type. Default is 'button'.
 * @param {'primary'|'secondary'|'ghost'} variant - Optional. The visual style variant. Default is 'primary'.
 * @param {'sm'|'md'|'lg'} size - Optional. The size variant of the button. Default is 'md'.
 * @param {'left'|'right'} iconPos - Optional. Side where the icon slides in. Default is 'right'.
 * @param {boolean} disabled - Optional. Whether the button is disabled. Default is false.
 */
interface Props {
  href?: string;
  type?: 'button' | 'submit' | 'reset';
  variant?: 'primary' | 'secondary' | 'ghost';
  size?: 'sm' | 'md' | 'lg';
  iconPos?: 'left' | 'right';
  disabled?: boolean;
}

const { 
  href, 
  type = 'button', 
  variant = 'primary', 
  size = 'md',
  iconPos = 'right',
  disabled = false 
} = Astro.props;

const Tag = href ? 'a' : 'button';
---

<Tag 
  href={href} 
  type={href ? undefined : type}
  disabled={disabled}
  class:list={[
    "icon-anim-btn",
    `icon-anim-btn--${variant}`,
    `icon-anim-btn--${size}`,
    `icon-anim-btn--${iconPos}`
  ]}
>
  <span class="icon-anim-btn__inner">
    {iconPos === 'left' && (
      <span class="icon-anim-btn__icon">
        <slot name="icon">
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
            <polyline points="15 18 9 12 15 6"></polyline>
          </svg>
        </slot>
      </span>
    )}
    <span class="icon-anim-btn__text"><slot /></span>
    {iconPos === 'right' && (
      <span class="icon-anim-btn__icon">
        <slot name="icon">
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
            <polyline points="9 18 15 12 9 6"></polyline>
          </svg>
        </slot>
      </span>
    )}
  </span>
</Tag>

<style>
  .icon-anim-btn {
    --btn-bg: var(--c-primary, #6366f1);
    --btn-color: #fff;
    --btn-hover-bg: var(--c-primary-light, #818cf8);
    
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--btn-bg);
    color: var(--btn-color);
    border: none;
    border-radius: var(--r-md, 12px);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    font-family: var(--font-sans, inherit);
  }

  .icon-anim-btn__inner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: transform 0.3s ease;
  }

  .icon-anim-btn__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25em;
    height: 1.25em;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .icon-anim-btn__icon svg {
    width: 100%;
    height: 100%;
  }

  /* Hover Animations */
  .icon-anim-btn--right:hover:not(:disabled) .icon-anim-btn__icon {
    transform: translateX(4px) scale(1.1);
  }

  .icon-anim-btn--left:hover:not(:disabled) .icon-anim-btn__icon {
    transform: translateX(-4px) scale(1.1);
  }

  .icon-anim-btn:hover:not(:disabled) {
    background: var(--btn-hover-bg);
    box-shadow: 0 4px 20px -5px color-mix(in srgb, var(--btn-bg), transparent 40%);
  }

  .icon-anim-btn:active:not(:disabled) {
    transform: scale(0.97);
  }

  .icon-anim-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
  }

  /* Variants */
  .icon-anim-btn--secondary {
    --btn-bg: rgba(255, 255, 255, 0.05);
    --btn-color: var(--c-text-1, #f8fafc);
    --btn-hover-bg: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .icon-anim-btn--ghost {
    --btn-bg: transparent;
    --btn-color: var(--c-primary-light, #818cf8);
    --btn-hover-bg: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
  }

  /* Sizes */
  .icon-anim-btn--sm { padding: 0.45rem 1.2rem; font-size: 0.85rem; }
  .icon-anim-btn--md { padding: 0.75rem 1.8rem; font-size: 1rem; }
  .icon-anim-btn--lg { padding: 1rem 2.5rem; font-size: 1.15rem; }
</style>
--- /** * AnimatedIconButton — A button that elegantly slides an icon into view on hover. * * @param {string} href - Optional. If provided, renders an <a> tag instead of <button>. * @param {'button'|'submit'|'reset'} type - Optional. The HTML button type. Default is 'button'. * @param {'primary'|'secondary'|'ghost'} variant - Optional. The visual style variant. Default is 'primary'. * @param {'sm'|'md'|'lg'} size - Optional. The size variant of the button. Default is 'md'. * @param {'left'|'right'} iconPos - Optional. Side where the icon slides in. Default is 'right'. * @param {boolean} disabled - Optional. Whether the button is disabled. Default is false. */ interface Props { href?: string; type?: 'button' | 'submit' | 'reset'; variant?: 'primary' | 'secondary' | 'ghost'; size?: 'sm' | 'md' | 'lg'; iconPos?: 'left' | 'right'; disabled?: boolean; } const { href, type = 'button', variant = 'primary', size = 'md', iconPos = 'right', disabled = false } = Astro.props; const Tag = href ? 'a' : 'button'; --- <Tag href={href} type={href ? undefined : type} disabled={disabled} class:list={[ "icon-anim-btn", `icon-anim-btn--${variant}`, `icon-anim-btn--${size}`, `icon-anim-btn--${iconPos}` ]} > <span class="icon-anim-btn__inner"> {iconPos === 'left' && ( <span class="icon-anim-btn__icon"> <slot name="icon"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"> <polyline points="15 18 9 12 15 6"></polyline> </svg> </slot> </span> )} <span class="icon-anim-btn__text"><slot /></span> {iconPos === 'right' && ( <span class="icon-anim-btn__icon"> <slot name="icon"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"> <polyline points="9 18 15 12 9 6"></polyline> </svg> </slot> </span> )} </span> </Tag> <style> .icon-anim-btn { --btn-bg: var(--c-primary, #6366f1); --btn-color: #fff; --btn-hover-bg: var(--c-primary-light, #818cf8); position: relative; display: inline-flex; align-items: center; justify-content: center; background: var(--btn-bg); color: var(--btn-color); border: none; border-radius: var(--r-md, 12px); cursor: pointer; text-decoration: none; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); font-weight: 600; user-select: none; white-space: nowrap; overflow: hidden; font-family: var(--font-sans, inherit); } .icon-anim-btn__inner { display: flex; align-items: center; gap: 0.6rem; transition: transform 0.3s ease; } .icon-anim-btn__icon { display: flex; align-items: center; justify-content: center; width: 1.25em; height: 1.25em; transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); } .icon-anim-btn__icon svg { width: 100%; height: 100%; } /* Hover Animations */ .icon-anim-btn--right:hover:not(:disabled) .icon-anim-btn__icon { transform: translateX(4px) scale(1.1); } .icon-anim-btn--left:hover:not(:disabled) .icon-anim-btn__icon { transform: translateX(-4px) scale(1.1); } .icon-anim-btn:hover:not(:disabled) { background: var(--btn-hover-bg); box-shadow: 0 4px 20px -5px color-mix(in srgb, var(--btn-bg), transparent 40%); } .icon-anim-btn:active:not(:disabled) { transform: scale(0.97); } .icon-anim-btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(1); } /* Variants */ .icon-anim-btn--secondary { --btn-bg: rgba(255, 255, 255, 0.05); --btn-color: var(--c-text-1, #f8fafc); --btn-hover-bg: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.1); } .icon-anim-btn--ghost { --btn-bg: transparent; --btn-color: var(--c-primary-light, #818cf8); --btn-hover-bg: rgba(99, 102, 241, 0.08); border: 1px solid rgba(99, 102, 241, 0.2); } /* Sizes */ .icon-anim-btn--sm { padding: 0.45rem 1.2rem; font-size: 0.85rem; } .icon-anim-btn--md { padding: 0.75rem 1.8rem; font-size: 1rem; } .icon-anim-btn--lg { padding: 1rem 2.5rem; font-size: 1.15rem; } </style>

Quick Info

Category
Buttons
Filename
AnimatedIconButton.astro
Dependencies
None — pure Astro + CSS
Tags
buttonpremium