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="container mx-auto py-3 lg:py-9 lg:max-w-5xl">
  
  <h1 class="block text-center text-2xl">Create account</h1>
  <p class="block text-center text-base opacity-50 font-light">TourGuide JS example</h>
  
  <div class="flex justify-center mt-9">
    <aside class="max-w-sm" id="aside">
      <div class="p-4 rounded-md bg-white border mb-4">
        <input class="border px-3 py-2 rounded-md w-full" placeholder="Email address" type="email" id="userEmailInput"/>
        <span id="emailErr" class="text-red-500 text-xs mt-2 text-center block"></span>
      <button id="tg-trigger" class="bg-indigo-600 mt-3 w-full text-white rounded-md px-6 py-2">Create account</button>
      </div><!-- end card -->
      
      <div class="p-4 rounded-md bg-white border mb-4">
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi aspernatur ipsam ex suscipit, deserunt tempora incidunt dicta error alias amet fugit quaerat sint ab magnam, provident vitae! Iusto, nobis dolorum.</p>
      </div><!-- end card -->
      
    </aside>
  
  
  <main id="appMain" class="max-w-4xl p-4 w-full rounded-md bg-white border" style="display:none">
    
<div class="flex items-center mb-6">
    <div id="profile" class="inline-flex items-center">
      <picture class="text-center mr-4 block" style="width:60px;height:60px;">
    <img src="https://avatars.dicebear.com/api/adventurer-neutral/bob.svg?r=33&scale=82" width="60" height="60">
  </picture>
  <div class="profile-meta">
    <p id="userName" class="font-bold">Jeff Jones</p>
    <p id="userEmail" class="text-gray-400 text-xs font-medium">jeff@mail.net</p>
  </div><!-- end profile meta: name/email -->
  </div>
  <span id="tag" class="rounded-md border border-red-200 text-xs ml-auto bg-red-50 text-red-800 px-2 font-medium">Onboarded</span><!-- end onboarded tag -->
</div><!-- end profile header -->

    
    <ul class="flex items-center gap-x-2 mb-4 justify-center border-b border-t py-4">
      <li class="inline-block"><button id="homeBtn" class="inline-block rounded-sm py-1 px-3 bg-indigo-100" data-tg-placement="top">Home</button></li>
      <li class="inline-block"><button id="listingsBtn" class="inline-block rounded-sm py-1 px-3 bg-gray-100 hover:bg-gray-50 hover:shadow-sm">Listings</button></li>
    
    </ul>
    
<section id="sectionHome">
  <p class="mb-3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis voluptatem consequuntur dolor eos praesentium accusamus voluptas nemo, magnam architecto fugit. Quam a assumenda blanditiis. Sapiente ea nulla rem quidem hic.</p>

<p class="mb-3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis voluptatem consequuntur dolor eos praesentium accusamus voluptas nemo, magnam architecto fugit. Quam a assumenda blanditiis. Sapiente ea nulla rem quidem hic.</p>
    </section>
    <section id="sectionListings" style="display:none;">
      <div class="flex gap-x-3 items-center mb-4">
      <input class="border px-3 py-2 rounded-md w-full h-10" placeholder="Search terms"/>
      <select class="border px-3 py-2 rounded-md w-auto h-10">
        <option>Example option 1</option>
        <option>Example option 2</option>
      </select>
            <button id="tg-trigger" class="bg-indigo-600 h-10 w-33 text-white rounded-md px-6 py-1 max-w-12">Find</button>
    </div>
    <div class="grid grid-cols-6 gap-3">
      <div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
      <div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
      <div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
      <div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
      <div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
      <div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
    </div>
    </section>
    
   
  </main>
    </div><!-- end grid wrapper -->
</div><!-- end container -->
              
            
!

CSS

              
                
body{ 
  background: #f1f1f1;
}
              
            
!

JS

              
                import TourGuideClient from "https://cdn.skypack.dev/@sjmc11/tourguidejs@0.0.7"; // Script

let userDisplayName = "test"

const tg = new TourGuideClient({
  progressBar: "#999",
  exitOnEscape: false,
  exitOnClickOutside: false,
  closeButton: false
});

tg.onFinish(()=>{
  if(tag){
    tag.innerHTML = "Tour complete"
    tag.classList = "rounded-md border border-green-200 text-xs ml-auto bg-green-50 text-green-800 px-2 font-medium"
  }
})

console.log("loaded");

function handleTourStart() {
  emailErr.innerHTML = "";

  // Validate email
  if (!emailInput.value) {
    console.log("emailErr", emailErr);
    emailErr.innerHTML = "Enter email";
    return;
  }

  // Create welcome step
  tg.addSteps([
    {
      title: "First things first",
      content:
        `<p class="mb-3">Nice to have to you here ` +
        emailInput.value +
        `<p><p class="mb-3">Before we complete your registration we require your name.<p><input type="text" class="border px-3 py-2 rounded-md w-full" id="userNameInput" placeholder="Display name"/><span id="userNameErr" class="text-red-500 block"></span>`,
      beforeLeave: ()=>{
        return new Promise((resolve, reject)=>{
          const nameInput = document.getElementById("userNameInput");
          const nameErr = document.getElementById("userNameErr");
          if(nameErr) nameErr.innerHTML = ""
          if(nameInput && !nameInput.value) {
            if(nameErr) nameErr.innerHTML = "Enter name"
            return reject(false)
          }
          if(nameInput) userDisplayName = nameInput.value
          return resolve(true)
        })
      }
    },
    {
      title: "Welcome aboard 👋",
      content: `<p class="mb-3">Awesome, you're officially registered.</p><p class="mb-3">Here's a tour of our application to get you started.</p><p class="text-xs opacity-50">Use the arrow keys or click next to continue.</p>`,
      target: "#profile",
      beforeEnter: () => {
        return new Promise((resolve) => {
          if(aside) aside.style.display = 'none'
          if(appMain) appMain.style.display = 'block'
          if(userEmail) userEmail.innerHTML = emailInput.value
          if(userName) userName.innerHTML = userDisplayName
          return resolve(true)
        });
      },
    },
    {
      title: "View your home screen 🏠",
      content: `<p class="mb-3">The home screen is an overview of the application information that is relevant to you.</p><p class="text-xs opacity-50">Use the arrow keys or click next to continue.</p>`,
      target: "#homeBtn",
      beforeEnter: () => {
        return new Promise((resolve) => {
          handleHomeClick()
          return resolve(true)
        });
      },
    },
    {
      title: "View the latest listings 🔍",
      content: `<p class="mb-3">View the latest listings on the website and choose ones that suit you.</p><p class="text-xs opacity-50">Use the arrow keys or click next to continue.</p>`,
      target: "#listingsBtn",
      beforeEnter: () => {
        return new Promise((resolve) => {
          handleListingsClick()
          return resolve(true)
        });
      },
    },
    {
      title: "Looks like you're all set ✅",
      content: `<p class="mb-3">Enjoy using our app.</p>`,
      order: 99999999 // Enforce this as the final step
    }
  ]);

  console.log(emailInput.value);

  tg.start();
}

const trigger = document.getElementById("tg-trigger");
const emailInput = document.getElementById("userEmailInput");
const emailErr = document.getElementById("emailErr");
const appMain = document.getElementById("appMain");
const aside = document.getElementById("aside");
const userName = document.getElementById("userName");
const userEmail = document.getElementById("userEmail");
const homeBtn = document.getElementById("homeBtn");
const sectionHome = document.getElementById("sectionHome");
const listingsBtn = document.getElementById("listingsBtn");
const sectionListings = document.getElementById("sectionListings");
const tag = document.getElementById("tag");

if (trigger) trigger.addEventListener("click", handleTourStart);

const handleHomeClick = ()=>{
  homeBtn.classList = "inline-block rounded-sm py-1 px-3 bg-indigo-100"
  listingsBtn.classList = "inline-block rounded-sm py-1 px-3 bg-gray-100 hover:bg-gray-50 hover:shadow-sm"
  if(sectionHome) sectionHome.style.display = "block"
  if(sectionListings) sectionListings.style.display = "none"
}

if (homeBtn) homeBtn.addEventListener("click", handleHomeClick);

const handleListingsClick = ()=>{
  homeBtn.classList = "inline-block rounded-sm py-1 px-3 bg-gray-100 hover:bg-gray-50 hover:shadow-sm"
  listingsBtn.classList = "inline-block rounded-sm py-1 px-3 bg-indigo-100"
  if(sectionHome) sectionHome.style.display = "none"
  if(sectionListings) sectionListings.style.display = "block"
}

if (listingsBtn) listingsBtn.addEventListener("click", handleListingsClick);

              
            
!
999px

Console