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

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Fireproof Example</title>
  <script src="https://cdn.jsdelivr.net/npm/@fireproof/core@0.17.8/dist/browser/fireproof.global.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fireproof/partykit@0.17.9/dist/browser/index.iife.js"></script>
</head>

<body ondblclick="reset(event)">
  <div class="container">
    <form>
      <input type="text" />
      <button onclick="addItem(event)">Add Item</button>
    </form>
    <ul></ul>
  </div>
</body>

</html>
              
            
!

CSS

              
                /* General styles for dark mode */
body {
  background-color: #121212; /* Dark background */
  color: #e0e0e0; /* Light text */
  font-family: Arial, sans-serif; /* Change to your preferred font */
}

/* Container Styles */
.container {
  display: flex; /* Use flexbox for alignment */
  flex-direction: column; /* Stack form and list vertically */
  align-items: center; /* Center items horizontally */
  max-width: 600px; /* Limit the maximum width */
  margin: 0 auto; /* Center the container horizontally */
}

/* Unordered List Styles */
ul {
  list-style-type: none; /* Remove default bullets */
  padding: 0;
  margin: 0;
  width: 100%; /* Make the list take the full width of the container */
}

/* List Item Styles */
ul > li {
  display: flex; /* Use flexbox for alignment */
  align-items: center; /* Center items vertically */
  background-color: #1e1e1e; /* Slightly lighter background for list items */
  border: 1px solid #333; /* Border to separate items */
  border-radius: 5px; /* Rounded corners */
  padding: 10px; /* Spacing inside list items */
  margin: 5px 0; /* Space between list items */
  transition: background-color 0.3s; /* Smooth background change on hover */
}

/* Hover effect */
ul > li:hover {
  background-color: #333; /* Darker background on hover */
  cursor: pointer; /* Pointer cursor on hover */
}

/* Optional: Add a subtle shadow */
ul > li {
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Subtle shadow */
}

/* Optional: Active or selected item */
ul > li.active {
  background-color: #444; /* Different color for active/selected item */
  border-color: #555; /* Slightly different border for active/selected item */
}

/* Checkbox Styles */
ul > li input[type="checkbox"] {
  appearance: none; /* Remove default checkbox style */
  background-color: #2a2a2a; /* Dark background */
  border: 2px solid #444; /* Border color */
  border-radius: 4px; /* Rounded corners */
  width: 20px;
  height: 20px;
  cursor: pointer; /* Pointer cursor */
  position: relative; /* Position relative for checkmark */
  transition: background-color 0.3s, border-color 0.3s; /* Smooth transition */
  margin-right: 10px; /* Space between checkbox and text */
}

ul > li input[type="checkbox"]:checked {
  background-color: #f58709; /* Green background when checked */
  border-color: #f58709; /* Green border when checked */
}

ul > li input[type="checkbox"]:checked::after {
  content: "✔"; /* Checkmark */
  color: #fff; /* White checkmark color */
  font-size: 14px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* Center the checkmark */
}

ul > li input[type="checkbox"]:hover {
  background-color: #3a3a3a; /* Slightly lighter background on hover */
  border-color: #555; /* Slightly different border on hover */
}

/* Text Styles inside List Items */
ul > li span {
  flex-grow: 1; /* Take up remaining space */
  margin-left: 10px; /* Space between checkbox and text */
}

/* Form Styles */
form {
  display: flex; /* Use flexbox for alignment */
  align-items: center; /* Center items vertically */
  margin-bottom: 14px; /* Space below the form */
  margin-top: 10px;
  width: 100%; /* Make the form take the full width of the container */
  padding: 0 10px; /* Add padding to left and right */
  box-sizing: border-box; /* Include padding in width calculation */
}

/* Input Styles */
form input[type="text"] {
  background-color: #2a2a2a; /* Dark background */
  color: #e0e0e0; /* Light text */
  border: 1px solid #444; /* Border color */
  border-radius: 4px; /* Rounded corners */
  padding: 8px; /* Padding inside the input */
  margin-right: 10px; /* Space between input and button */
  flex-grow: 1; /* Take up remaining space */
  box-sizing: border-box; /* Include padding in width calculation */
}

/* Button Styles */
form button {
  background-color: #f58709; /* Green background */
  color: #fff; /* White text */
  font-weight: bold;
  font-size: 0.8em;
  border: none; /* Remove default border */
  border-radius: 4px; /* Rounded corners */
  padding: 8px 12px; /* Padding inside the button */
  cursor: pointer; /* Pointer cursor */
  transition: background-color 0.3s; /* Smooth background change on hover */
  white-space: nowrap; /* Prevent text wrap */
  box-sizing: border-box; /* Include padding in width calculation */
}

form button:hover {
  background-color: #f16c12; /* Darker green on hover */
}

              
            
!

JS

              
                db = connect("fireproof");

function addItemDb(text) {
  db.put({
    text,
    done: false,
    created: Date.now()
  });
}

function addItem(e) {
  e.preventDefault();
  const input = document.querySelector("form input");
  if (!input.value) return;
  addItemDb(input.value);
  input.value = "";
}
window.addItem = addItem;

function toggleDone(doc) {
  doc.done = !doc.done;
  doc.updated = Date.now();
  db.put(doc);
}

async function redraw() {
  const result = await db.query("created", {
    includeDocs: true,
    descending: true,
    limit: 10
  });

  document.querySelector("ul").innerHTML = "";

  for (const row of result.rows) {
    const textSpan = document.createElement("span");
    textSpan.innerText = row.doc.text;

    const checkbox = document.createElement("input");
    checkbox.onchange = () => {
      toggleDone(row.doc);
    };
    if (row.doc.done) {
      checkbox.setAttribute("checked", true);
    }
    checkbox.setAttribute("type", "checkbox");

    const deleteSpan = document.createElement("span");
    deleteSpan.innerText = "x";
    deleteSpan.style = "text-align:right; color:#999";
    deleteSpan.onclick = function (e) {
      e.preventDefault();
      db.del(row.id);
      if (result.rows.length <= 1) reset();
    };

    const li = document.createElement("li");
    li.appendChild(checkbox);
    li.appendChild(textSpan);
    li.appendChild(deleteSpan);

    document.querySelector("ul").appendChild(li);
  }
}

const fixtures = [
  "Merkle integrity",
  "Runs in any cloud",
  "End-to-end encryption",
  "JSON documents",
  "Open-source connectors",
  "Commodity storage",
  "Serverless architecture",
  "Immutable history",
  "Self-sovereign auth",
  "Cloudless operation",
  "Event-driven architecture",
  "React state management"
];

function getRandomThree(arr) {
  let result = ["Multi-writer CRDT"];
  let clonedArray = [...arr];

  for (let i = 1; i < 3; i++) {
    let randomIndex = Math.floor(Math.random() * clonedArray.length);
    result.push(clonedArray[randomIndex]);
    clonedArray.splice(randomIndex, 1);
  }

  return result;
}

async function reset(e) {
  if (e) e.preventDefault();
  const allDocs = await db.allDocs();
  for (const row of allDocs.rows) {
    db.del(row.key);
  }

  const puts = getRandomThree(fixtures).map((text) => {
    db.put({
      created: Date.now(),
      text,
      done: true
    });
  });
  await Promise.all(puts);

  db.compact();
}
window.reset = reset;

window.onload = function initialize() {
  db.subscribe(redraw);
  redraw();
  // reset() // remove when connected
};

function connect(name) {
  const db = Fireproof.fireproof(name + 6);
  // placeholder until Fireproof Cloud ships
  FireproofConnect.connect.partykitS3(
    db,
    "https://firehouse-chat.jchris.partykit.dev"
  );
  return db;
}

// for another app that syncs live with the same dataset see
// https://replit.com/@jchris5/HTML-CSS-JS-Auto-Refresh#script.js

              
            
!
999px

Console