Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class='Wrapper'>
  <github-repo name="yzw7489757/single-spa-demo"></github-repo>
  <github-repo name="yzw7489757/react-middleware"></github-repo>
  <github-repo name="yzw7489757/like-hooks"></github-repo>
  <github-repo name="yzw7489757/tms-editor"></github-repo>
  <github-repo name="yzw7489757/react-interactive-paycard"></github-repo>
</div>
              
            
!

CSS

              
                .Wrapper {
  margin: 1rem auto;
  max-width: 600px;
}
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui;
}

              
            
!

JS

              
                var getRandomColor = function(){
    return '#'+(Math.random()*0xffffff<<0).toString(16); 
}
class Repository extends HTMLElement {
  constructor() {
    super();
    this.color = getRandomColor()
    this.repoDetails = null;
    this.name = this.getAttribute("name");
    this.endpoint = `https://api.github.com/repos/${this.name}`;
    this.innerHTML = `<h1>Loading</h1>`;
  }

  async connectedCallback() {
    this.repoDetails = await this.getDetails();
    this.initShadowDom();
  }

  initShadowDom() {
    let shadowRoot = this.attachShadow({ mode: "open" });
    shadowRoot.innerHTML = this.template;
  }

  get style() {
    return `
      <style>
        .Card {
          margin: 0 0 8px;
          padding: 16px;
          border: 2px solid ${this.color};
        }

        .Card::after {
          content: "";
          clear: both;
          display: table;
        }

        .Card aside {
          float: left;
        }

        .Card header {
          float: left;
        }

        .Card__title {
          margin-bottom: 4px;
          font-weight: 400;
          font-size: 16px;
        }

        .Card__meta {
          color: #4F4F4F;
          font-size: 12px;
        }

        .Card--error {
          background: #D23923;
          color: white;
          font-weight: 700;
          border: 0;
        }

        .Avatar {
          display: block;
          margin-right: 16px;
          border-radius: 50%;
        }
      </style>
    `;
  }

  get template() {
    let repo = this.repoDetails;

    if (repo.message) {
      return this.style + this.cardError(repo);
    } else {
      return this.style + this.cardTemplate(repo);
    }
  }

  getDetails = async () => {
    return await fetch(this.endpoint, { mode: "cors" }).then(res => res.json());
  }

  cardError({ message }) {
    return `<div class="Card Card--error">Error: ${message}</div>`;
  }

  cardTemplate({ owner, full_name, description }) {
    return `
      <div class="Card">
        <aside>
          <img width="48" height="48" class="Avatar" src="${
            owner.avatar_url
          }" alt="Profile picture for ${owner.login}" />
        </aside>
        <header>
          <h2 class="Card__title">${full_name}</h2>
          <span class="Card__meta">${description}</span>
        </header>
      </div>
    `;
  }
}

window.customElements.define("github-repo", Repository);

              
            
!
999px

Console