sailfork / t3code-github / .repos/ alchemy-effect/ website/ src/ components/ marketing/ Button.astro

---
type Variant = "primary" | "secondary" | "ghost" | "accent";
type Icon = "github" | "arrow" | "book" | "discord";

interface Props {
  variant?: Variant;
  icon?: Icon;
  href?: string;
  class?: string;
}

const { variant = "primary", icon, href = "#", class: className } = Astro.props;
---

<a
  href={href}
  class:list={["alc-btn", `alc-btn--${variant}`, className]}
>
  {icon === "github" && (
    <svg aria-hidden width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
      <path
        d="M12 .5C5.73.5.5 5.73.5 12c0 5.08 3.29 9.39 7.86 10.91.58.1.79-.25.79-.56 0-.28-.01-1.02-.02-2-3.2.69-3.88-1.54-3.88-1.54-.52-1.33-1.28-1.69-1.28-1.69-1.05-.72.08-.71.08-.71 1.16.08 1.77 1.19 1.77 1.19 1.03 1.77 2.71 1.26 3.37.96.1-.75.4-1.26.73-1.55-2.55-.29-5.24-1.28-5.24-5.69 0-1.26.45-2.29 1.19-3.1-.12-.29-.52-1.46.11-3.05 0 0 .97-.31 3.18 1.18a11.04 11.04 0 0 1 5.79 0c2.21-1.49 3.18-1.18 3.18-1.18.63 1.59.23 2.76.11 3.05.74.81 1.19 1.84 1.19 3.1 0 4.42-2.69 5.39-5.25 5.68.41.36.78 1.07.78 2.16 0 1.56-.01 2.81-.01 3.19 0 .31.21.67.8.56C20.71 21.39 24 17.08 24 12 24 5.73 18.27.5 12 .5z"
      ></path>
    </svg>
  )}
  <slot />
  {icon === "arrow" && <span aria-hidden>→</span>}
  {icon === "book" && <span aria-hidden>❏</span>}
  {icon === "discord" && (
    <svg aria-hidden width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
      <path
        d="M20.317 4.369A19.79 19.79 0 0 0 16.558 3.2a.075.075 0 0 0-.079.037c-.34.6-.717 1.384-.98 2-1.797-.27-3.583-.27-5.342 0-.263-.63-.654-1.4-.997-2A.077.077 0 0 0 9.08 3.2a19.736 19.736 0 0 0-3.76 1.169.07.07 0 0 0-.032.027C1.533 9.046.6 13.58 1.057 18.058a.082.082 0 0 0 .031.056 19.9 19.9 0 0 0 5.993 3.029.077.077 0 0 0 .084-.027c.462-.63.873-1.295 1.226-1.994a.076.076 0 0 0-.041-.106 13.108 13.108 0 0 1-1.872-.892.077.077 0 0 1-.008-.128c.126-.094.252-.192.372-.291a.074.074 0 0 1 .077-.01c3.927 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.099.246.197.373.291a.077.077 0 0 1-.006.128 12.3 12.3 0 0 1-1.873.892.077.077 0 0 0-.04.106c.36.699.772 1.364 1.225 1.994a.076.076 0 0 0 .084.028 19.84 19.84 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.548-13.66a.061.061 0 0 0-.031-.029ZM8.02 15.331c-1.183 0-2.157-1.085-2.157-2.42 0-1.333.956-2.418 2.157-2.418 1.21 0 2.176 1.094 2.157 2.418 0 1.335-.956 2.42-2.157 2.42Zm7.974 0c-1.183 0-2.157-1.085-2.157-2.42 0-1.333.955-2.418 2.157-2.418 1.21 0 2.176 1.094 2.157 2.418 0 1.335-.946 2.42-2.157 2.42Z"
      ></path>
    </svg>
  )}
</a>

<style>
  .alc-btn {
    font-family: var(--alc-font-sans);
    font-size: 14px;
    font-weight: 500;
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition:
      background 120ms var(--alc-ease, cubic-bezier(0.2, 0, 0, 1)),
      border-color 120ms var(--alc-ease, cubic-bezier(0.2, 0, 0, 1)),
      color 120ms var(--alc-ease, cubic-bezier(0.2, 0, 0, 1));
  }
  /* Deep forest instead of var(--alc-accent): mid-green moss cannot reach
     the AAA 7:1 contrast ratio with any text color; #3f5a2a gives 7.2:1
     against --alc-fg-on-accent in both themes. */
  .alc-btn--primary {
    background: #3f5a2a;
    color: var(--alc-fg-on-accent);
  }
  .alc-btn--primary:hover {
    background: #324a1e;
  }
  /* Secondary: transparent surface with a hairline border. Slimmer
     padding than the primary so it doesn't feel oversized when sitting
     next to a borderless ghost button. */
  .alc-btn--secondary {
    background: transparent;
    border-color: var(--alc-hairline-3);
    color: var(--alc-fg-1);
    padding: 7px 14px;
  }
  .alc-btn--secondary:hover {
    border-color: var(--alc-accent);
    color: var(--alc-accent-deep);
  }
  .alc-btn--ghost {
    background: transparent;
    color: var(--alc-fg-2);
  }
  .alc-btn--ghost:hover {
    color: var(--alc-accent-deep);
  }
  .alc-btn--accent {
    background: var(--alc-terracotta);
    color: var(--alc-fg-on-accent);
  }
  /* MDX wraps the button's slot text in a <p>, which inherits the UA
     stylesheet's 1em block margin (~14px) and bloats the button
     vertically. Flatten any <p> inside the button. `display: inline`
     keeps the icon + label on one row inside the inline-flex anchor. */
  .alc-btn :global(p) {
    margin: 0;
    display: inline;
  }
</style>