Giter Club home page Giter Club logo

giscus-component's Introduction

giscus-component

A wrapper component for giscus ๐Ÿ’Ž, a comments system powered by GitHub Discussions. Currently available for React, Vue, Svelte, and as a Web Component.

Documentation

Using the React, Vue, or Svelte component

To use the React, Vue, or Svelte component, install the corresponding package.

npm i @giscus/react   # for React/Preact
npm i @giscus/vue     # for Vue
npm i @giscus/svelte  # for Svelte
# Change npm with the package manager you use

Then, import the default export from the package. Example for React:

import Giscus from '@giscus/react';

export default function MyApp() {
  return (
    <Giscus
      id="comments"
      repo="giscus/giscus-component"
      repoId="MDEwOlJlcG9zaXRvcnkzOTEzMTMwMjA="
      category="Announcements"
      categoryId="DIC_kwDOF1L2fM4B-hVS"
      mapping="specific"
      term="Welcome to @giscus/react component!"
      reactionsEnabled="1"
      emitMetadata="0"
      inputPosition="top"
      theme="light"
      lang="en"
      loading="lazy"
    />
  );
}

The prop names are the same as the data- attributes shown on the giscus website, but written in camelCase with the data- prefix and dashes removed.

Using the web component

To use the Web component, install the giscus package.

npm i giscus

Then import it in your code.

import 'giscus';

Alternatively, you can also use unpkg or Skypack.

<!-- unpkg -->
<script type="module" src="https://unpkg.com/giscus?module"></script>

<!-- Skypack -->
<script type="module" src="https://cdn.skypack.dev/giscus"></script>

Then use it in your HTML.

<giscus-widget
  id="comments"
  repo="giscus/giscus"
  repoid="MDEwOlJlcG9zaXRvcnkzNTE5NTgwNTM="
  category="General"
  categoryid="MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyNzk2NTc1"
  mapping="specific"
  term="Welcome to giscus!"
  reactionsenabled="1"
  emitmetadata="0"
  inputposition="top"
  theme="light"
  lang="en"
  loading="lazy"
></giscus-widget>

The attribute names are the same as the data- attributes shown on the giscus website, but written in lowercase with the data- prefix and dashes removed.

Changing the <iframe> styles

You can style the <iframe> in your CSS by selecting the web component, or the iframe part specifically. For example:

giscus-widget {
  display: flex;
  margin: auto;
  max-width: 640px;
}
/* or... */
#comments {
  /* ... */
}
/* or... */
#comments::part(iframe) {
  /* ... */
}
/* etc. */

You can also make the widget scrollable by creating a parent container with a limited height and overflow: scroll, for example:

<div class="comments-container">
  <giscus-widget
    ...
  >
  </giscus-widget>
</div>
.comments-container {
  max-height: 640px;
  overflow-y: scroll;
}

Note that this only allows you to style the <iframe> element and not the iframe's contents. If you want to style the contents, you need to use a custom theme.

Notes

When you change the props/attributes of the React, Vue, and web components, they will automatically update the giscus configuration using postMessage() to the underlying <iframe> element without reloading the comments. Unfortunately, this doesn't work for Svelte as it always reloads the web component for some reason. If you know how to fix this, please let me know.

Further information

See the demo and its code example. For more information, read the documentation on the giscus website and its advanced usage guide.

Packages

This is a monorepo. The base component is written using Lit as a web component. The other components are built as a wrapper around the web component for convenience.

Environment Name Version Downloads
Web Component (Lit) giscus npm version npm downloads
React & Preact @giscus/react npm version npm downloads
Vue @giscus/vue npm version npm downloads
Svelte @giscus/svelte npm version npm downloads

Related Article

Introducing giscus

License

Copyright ยฉ 2021-2022 laymonage.

Released under the MIT license.

giscus-component's People

Contributors

laymonage avatar dependabot[bot] avatar danestves avatar dergoogler avatar dipakparmar avatar misode avatar mister-hope avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.