Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

3.3 KB
Raw Blame
---
import ThumbsDown from '@lucide/astro/icons/thumbs-down';
import ThumbsUp from '@lucide/astro/icons/thumbs-up';

import { getReportIssueUrl } from '../report-issue';
import Trans from './Trans.astro';

type Props = {
  /** Distinguishes the element ids of the copies in the right rail and the footer. */
  instance: string;
};

const labelId = `docs-feedback-label-${Astro.props.instance}`;

const { entry } = Astro.locals.starlightRoute;
const { t } = Astro.locals;
const reportIssueUrl = getReportIssueUrl(entry.data.title, new URL(Astro.url.pathname, Astro.site).href);
---

<docs-page-feedback class="feedback">
  <div class="question" role="group" aria-labelledby={labelId}>
    <p id={labelId}>{t('pageFeedback.question')}</p>
    <div class="answers">
      <button type="button" class="docs-button docs-button--secondary" data-helpful="yes">
        <ThumbsUp size={14} />
        {t('pageFeedback.answerYes')}
      </button>
      <button type="button" class="docs-button docs-button--secondary" data-helpful="no">
        <ThumbsDown size={14} />
        {t('pageFeedback.answerNo')}
      </button>
    </div>
  </div>
  <div class="thanks" tabindex="-1" hidden>
    <p>{t('pageFeedback.thanks')}</p>
    <p data-unhelpful hidden>
      <Trans message={t('pageFeedback.reportPrompt')}>
        {(text: string) => <a href={reportIssueUrl}>{text}</a>}
      </Trans>
    </p>
  </div>
</docs-page-feedback>

<script>
  type Plausible = (event: string, options: { props: Record<string, string> }) => void;

  class DocsPageFeedback extends HTMLElement {
    connectedCallback() {
      const question = this.querySelector<HTMLElement>('.question')!;
      const thanks = this.querySelector<HTMLElement>('.thanks')!;
      for (const button of this.querySelectorAll<HTMLButtonElement>('button[data-helpful]')) {
        button.addEventListener('click', () => {
          const helpful = button.dataset.helpful!;
          // Plausible loads only when the site is built with analytics enabled.
          const { plausible } = window as Window & { plausible?: Plausible };
          if (typeof plausible === 'function') {
            plausible('Docs feedback', { props: { page: location.pathname, helpful } });
          }
          question.hidden = true;
          thanks.hidden = false;
          thanks.querySelector<HTMLElement>('[data-unhelpful]')!.hidden = helpful !== 'no';
          // The answer buttons are gone, so move focus to the reply rather than letting it drop to the page.
          thanks.focus();
        });
      }
    }
  }
  customElements.define('docs-page-feedback', DocsPageFeedback);
</script>

<style>
  .feedback {
    display: block;
    padding-top: 1rem;
    border-top: 1px solid var(--docs-border);
    font-size: var(--sl-text-xs);
  }

  p {
    margin: 0;
  }

  .question {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;

    &[hidden] {
      display: none;
    }

    > p {
      color: var(--docs-text-muted);
      font-size: var(--sl-text-2xs);
      font-weight: 600;
    }
  }

  .answers {
    display: flex;
    gap: 0.375rem;
  }

  button {
    flex: 1;
  }

  .thanks {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    color: var(--docs-text-muted);

    &[hidden] {
      display: none;
    }
  }

  a {
    color: var(--docs-accent);
  }
</style>