ツール管理へ戻る

v1 → v2 の差分

--- v1
+++ v2
@@ -1,257 +1,434 @@
-<!DOCTYPE html>
-<html lang="ja">
-<head>
-  <meta charset="UTF-8">
-  <meta name="viewport" content="width=device-width, initial-scale=1">
-  <title>総作業時間計算</title>
-  <style>
-    :root {
-      color-scheme: light;
-      font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
-      color: #1f2937;
-      background: #f3f4f6;
-    }
-
-    * {
-      box-sizing: border-box;
-    }
-
-    body {
-      margin: 0;
-      min-height: 100vh;
-      display: grid;
-      place-items: center;
-      padding: 24px;
-    }
-
-    main {
-      width: min(100%, 480px);
-      padding: 32px;
-      background: #fff;
-      border: 1px solid #e5e7eb;
-      border-radius: 16px;
-      box-shadow: 0 8px 24px rgb(31 41 55 / 8%);
-    }
-
-    h1 {
-      margin: 0 0 8px;
-      font-size: 1.6rem;
-    }
-
-    .description {
-      margin: 0 0 24px;
-      color: #4b5563;
-      line-height: 1.6;
-    }
-
-    .field {
-      margin-bottom: 18px;
-    }
-
-    label {
-      display: block;
-      margin-bottom: 8px;
-      font-weight: 700;
-    }
-
-    .input-row {
-      display: flex;
-      align-items: center;
-      gap: 10px;
-    }
-
-    input {
-      width: 100%;
-      min-width: 0;
-      padding: 12px;
-      border: 1px solid #9ca3af;
-      border-radius: 8px;
-      font: inherit;
-      font-size: 1rem;
-    }
-
-    input:focus {
-      outline: 3px solid #bfdbfe;
-      border-color: #2563eb;
-    }
-
-    .unit {
-      flex: 0 0 auto;
-      color: #4b5563;
-    }
-
-    button {
-      width: 100%;
-      margin-top: 4px;
-      padding: 13px 16px;
-      border: 0;
-      border-radius: 8px;
-      background: #1d4ed8;
-      color: #fff;
-      font: inherit;
-      font-weight: 700;
-      cursor: pointer;
-    }
-
-    button:hover {
-      background: #1e40af;
-    }
-
-    button:focus-visible {
-      outline: 3px solid #93c5fd;
-      outline-offset: 3px;
-    }
-
-    .result {
-      margin-top: 24px;
-      padding: 18px;
-      border-radius: 10px;
-      background: #eff6ff;
-    }
-
-    .result-label {
-      margin: 0 0 6px;
-      color: #1e3a8a;
-      font-weight: 700;
-    }
-
-    output {
-      display: block;
-      color: #1e3a8a;
-      font-size: 1.35rem;
-      font-weight: 700;
-      overflow-wrap: anywhere;
-    }
-
-    .message {
-      min-height: 1.5em;
-      margin: 12px 0 0;
-      color: #b91c1c;
-      font-size: 0.95rem;
-    }
-
-    @media (max-width: 420px) {
-      main {
-        padding: 24px 20px;
-      }
-    }
-  </style>
-</head>
-<body>
-  <main>
-    <h1>総作業時間計算</h1>
-    <p class="description">
-      作業件数と1件あたりの時間から、合計時間を計算します。
-    </p>
-
-    <form id="calculator">
-      <div class="field">
-        <label for="count">作業件数</label>
-        <div class="input-row">
-          <input
-            id="count"
-            name="count"
-            type="number"
-            min="0"
-            step="1"
-            inputmode="numeric"
-            placeholder="例:8"
-            required
-          >
-          <span class="unit">件</span>
-        </div>
-      </div>
-
-      <div class="field">
-        <label for="minutes">1件あたりの時間</label>
-        <div class="input-row">
-          <input
-            id="minutes"
-            name="minutes"
-            type="number"
-            min="0"
-            step="any"
-            inputmode="decimal"
-            placeholder="例:15"
-            required
-          >
-          <span class="unit">分</span>
-        </div>
-      </div>
-
-      <button type="submit">計算する</button>
-    </form>
-
-    <section class="result" aria-live="polite">
-      <p class="result-label">合計時間</p>
-      <output id="result">—</output>
-    </section>
-
-    <p id="message" class="message" role="alert"></p>
-  </main>
-
-  <script>
-    "use strict";
-
-    const form = document.getElementById("calculator");
-    const countInput = document.getElementById("count");
-    const minutesInput = document.getElementById("minutes");
-    const result = document.getElementById("result");
-    const message = document.getElementById("message");
-
-    function formatNumber(value) {
-      return new Intl.NumberFormat("ja-JP", {
-        maximumFractionDigits: 2
-      }).format(value);
-    }
-
-    form.addEventListener("submit", (event) => {
-      event.preventDefault();
-      message.textContent = "";
-      result.textContent = "—";
-
-      const count = countInput.valueAsNumber;
-      const minutesPerItem = minutesInput.valueAsNumber;
-
-      if (!Number.isFinite(count) || !Number.isFinite(minutesPerItem)) {
-        message.textContent = "件数と1件あたりの時間を入力してください。";
-        return;
-      }
-
-      if (count < 0 || !Number.isInteger(count)) {
-        message.textContent = "作業件数は0以上の整数で入力してください。";
-        countInput.focus();
-        return;
-      }
-
-      if (minutesPerItem < 0) {
-        message.textContent = "1件あたりの時間は0以上で入力してください。";
-        minutesInput.focus();
-        return;
-      }
-
-      const totalMinutes = count * minutesPerItem;
-
-      if (!Number.isFinite(totalMinutes)) {
-        message.textContent = "入力値が大きすぎるため計算できません。";
-        return;
-      }
-
-      const totalHours = Math.floor(totalMinutes / 60);
-      const remainingMinutes = totalMinutes - totalHours * 60;
-
-      let display = `${formatNumber(totalMinutes)}分`;
-
-      if (totalHours > 0) {
-        display += `(${formatNumber(totalHours)}時間`;
-        if (remainingMinutes > 0) {
-          display += `${formatNumber(remainingMinutes)}分`;
-        }
-        display += ")";
-      }
-
-      result.textContent = display;
-    });
-  </script>
-</body>
+<!DOCTYPE html>
+<html lang="ja">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <title>総作業時間計算</title>
+  <style>
+    :root {
+      color-scheme: light;
+      font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
+      color: #1f2937;
+      background: #f3f4f6;
+    }
+
+    * {
+      box-sizing: border-box;
+    }
+
+    body {
+      margin: 0;
+      min-height: 100vh;
+      display: grid;
+      place-items: center;
+      padding: 24px;
+    }
+
+    main {
+      width: min(100%, 640px);
+      padding: 32px;
+      background: #fff;
+      border: 1px solid #e5e7eb;
+      border-radius: 16px;
+      box-shadow: 0 8px 24px rgb(31 41 55 / 8%);
+    }
+
+    h1 {
+      margin: 0 0 8px;
+      font-size: 1.6rem;
+    }
+
+    .description {
+      margin: 0 0 24px;
+      color: #4b5563;
+      line-height: 1.6;
+    }
+
+    .work-list {
+      display: grid;
+      gap: 16px;
+    }
+
+    .work-item {
+      padding: 16px;
+      border: 1px solid #d1d5db;
+      border-radius: 10px;
+      background: #fff;
+    }
+
+    .work-item-header {
+      display: flex;
+      align-items: center;
+      justify-content: space-between;
+      gap: 12px;
+      margin-bottom: 14px;
+    }
+
+    .work-item-title {
+      margin: 0;
+      font-size: 1rem;
+    }
+
+    .remove-button {
+      padding: 6px 10px;
+      border: 1px solid #b42318;
+      border-radius: 6px;
+      background: #fff;
+      color: #b42318;
+      font: inherit;
+      cursor: pointer;
+    }
+
+    .remove-button:hover {
+      background: #fef3f2;
+    }
+
+    .field {
+      margin-bottom: 14px;
+    }
+
+    .field:last-child {
+      margin-bottom: 0;
+    }
+
+    label {
+      display: block;
+      margin-bottom: 7px;
+      font-weight: 700;
+    }
+
+    .input-row {
+      display: flex;
+      align-items: center;
+      gap: 10px;
+    }
+
+    input {
+      width: 100%;
+      min-width: 0;
+      padding: 11px;
+      border: 1px solid #9ca3af;
+      border-radius: 8px;
+      font: inherit;
+      font-size: 1rem;
+    }
+
+    input:focus {
+      outline: 3px solid #bfdbfe;
+      border-color: #2563eb;
+    }
+
+    .unit {
+      flex: 0 0 auto;
+      color: #4b5563;
+    }
+
+    .actions {
+      display: grid;
+      grid-template-columns: 1fr 1fr;
+      gap: 12px;
+      margin-top: 20px;
+    }
+
+    button.primary-button,
+    button.secondary-button {
+      padding: 12px 16px;
+      border-radius: 8px;
+      font: inherit;
+      font-weight: 700;
+      cursor: pointer;
+    }
+
+    .primary-button {
+      border: 0;
+      background: #1d4ed8;
+      color: #fff;
+    }
+
+    .primary-button:hover {
+      background: #1e40af;
+    }
+
+    .secondary-button {
+      border: 1px solid #1d4ed8;
+      background: #fff;
+      color: #1d4ed8;
+    }
+
+    .secondary-button:hover {
+      background: #eff6ff;
+    }
+
+    button:focus-visible {
+      outline: 3px solid #93c5fd;
+      outline-offset: 3px;
+    }
+
+    .result {
+      margin-top: 24px;
+      padding: 18px;
+      border-radius: 10px;
+      background: #eff6ff;
+    }
+
+    .result-label {
+      margin: 0 0 6px;
+      color: #1e3a8a;
+      font-weight: 700;
+    }
+
+    output {
+      display: block;
+      color: #1e3a8a;
+      font-size: 1.35rem;
+      font-weight: 700;
+      overflow-wrap: anywhere;
+    }
+
+    .message {
+      min-height: 1.5em;
+      margin: 12px 0 0;
+      color: #b91c1c;
+      font-size: 0.95rem;
+    }
+
+    @media (max-width: 520px) {
+      main {
+        padding: 24px 20px;
+      }
+
+      .actions {
+        grid-template-columns: 1fr;
+      }
+    }
+  </style>
+</head>
+<body>
+  <main>
+    <h1>総作業時間計算</h1>
+    <p class="description">
+      作業ごとに件数と1件あたりの時間を入力し、全作業の合計時間を計算します。
+    </p>
+
+    <form id="calculator" novalidate>
+      <div id="work-list" class="work-list"></div>
+
+      <div class="actions">
+        <button id="add-work" class="secondary-button" type="button">
+          新規登録
+        </button>
+        <button class="primary-button" type="submit">
+          合計を計算
+        </button>
+      </div>
+    </form>
+
+    <section class="result" aria-live="polite">
+      <p class="result-label">合計時間</p>
+      <output id="result">—</output>
+    </section>
+
+    <p id="message" class="message" role="alert"></p>
+  </main>
+
+  <script>
+    "use strict";
+
+    const form = document.getElementById("calculator");
+    const workList = document.getElementById("work-list");
+    const addWorkButton = document.getElementById("add-work");
+    const result = document.getElementById("result");
+    const message = document.getElementById("message");
+
+    let nextWorkNumber = 1;
+
+    function createWorkItem() {
+      const itemNumber = nextWorkNumber++;
+
+      const item = document.createElement("section");
+      item.className = "work-item";
+      item.dataset.workNumber = String(itemNumber);
+      item.setAttribute("aria-labelledby", `work-title-${itemNumber}`);
+
+      const header = document.createElement("div");
+      header.className = "work-item-header";
+
+      const title = document.createElement("h2");
+      title.className = "work-item-title";
+      title.id = `work-title-${itemNumber}`;
+      title.textContent = `作業 ${itemNumber}`;
+
+      const removeButton = document.createElement("button");
+      removeButton.className = "remove-button";
+      removeButton.type = "button";
+      removeButton.textContent = "削除";
+      removeButton.setAttribute("aria-label", `作業 ${itemNumber} を削除`);
+
+      removeButton.addEventListener("click", () => {
+        item.remove();
+        renumberWorkItems();
+        clearResult();
+      });
+
+      header.append(title, removeButton);
+
+      const countField = document.createElement("div");
+      countField.className = "field";
+
+      const countLabel = document.createElement("label");
+      countLabel.htmlFor = `count-${itemNumber}`;
+      countLabel.textContent = "作業件数";
+
+      const countRow = document.createElement("div");
+      countRow.className = "input-row";
+
+      const countInput = document.createElement("input");
+      countInput.id = `count-${itemNumber}`;
+      countInput.name = "count";
+      countInput.type = "number";
+      countInput.min = "0";
+      countInput.step = "1";
+      countInput.inputMode = "numeric";
+      countInput.placeholder = "例:8";
+      countInput.required = true;
+
+      const countUnit = document.createElement("span");
+      countUnit.className = "unit";
+      countUnit.textContent = "件";
+
+      countRow.append(countInput, countUnit);
+      countField.append(countLabel, countRow);
+
+      const timeField = document.createElement("div");
+      timeField.className = "field";
+
+      const timeLabel = document.createElement("label");
+      timeLabel.htmlFor = `minutes-${itemNumber}`;
+      timeLabel.textContent = "1件あたりの時間";
+
+      const timeRow = document.createElement("div");
+      timeRow.className = "input-row";
+
+      const timeInput = document.createElement("input");
+      timeInput.id = `minutes-${itemNumber}`;
+      timeInput.name = "minutes";
+      timeInput.type = "number";
+      timeInput.min = "0";
+      timeInput.step = "any";
+      timeInput.inputMode = "decimal";
+      timeInput.placeholder = "例:15";
+      timeInput.required = true;
+
+      const timeUnit = document.createElement("span");
+      timeUnit.className = "unit";
+      timeUnit.textContent = "分";
+
+      timeRow.append(timeInput, timeUnit);
+      timeField.append(timeLabel, timeRow);
+
+      item.append(header, countField, timeField);
+      workList.append(item);
+
+      countInput.focus();
+      clearResult();
+    }
+
+    function renumberWorkItems() {
+      const items = workList.querySelectorAll(".work-item");
+
+      items.forEach((item, index) => {
+        const number = index + 1;
+        const title = item.querySelector(".work-item-title");
+        const removeButton = item.querySelector(".remove-button");
+
+        title.textContent = `作業 ${number}`;
+        removeButton.setAttribute("aria-label", `作業 ${number} を削除`);
+      });
+    }
+
+    function clearResult() {
+      result.textContent = "—";
+      message.textContent = "";
+    }
+
+    function formatNumber(value) {
+      return new Intl.NumberFormat("ja-JP", {
+        maximumFractionDigits: 2
+      }).format(value);
+    }
+
+    function formatDuration(totalMinutes) {
+      const totalHours = Math.floor(totalMinutes / 60);
+      const remainingMinutes = totalMinutes - totalHours * 60;
+
+      if (totalHours === 0) {
+        return `${formatNumber(totalMinutes)}分`;
+      }
+
+      if (remainingMinutes === 0) {
+        return `${formatNumber(totalHours)}時間`;
+      }
+
+      return `${formatNumber(totalHours)}時間${formatNumber(remainingMinutes)}分`;
+    }
+
+    addWorkButton.addEventListener("click", createWorkItem);
+
+    form.addEventListener("submit", (event) => {
+      event.preventDefault();
+      clearResult();
+
+      const items = workList.querySelectorAll(".work-item");
+
+      if (items.length === 0) {
+        message.textContent = "作業を1件以上登録してください。";
+        addWorkButton.focus();
+        return;
+      }
+
+      let totalMinutes = 0;
+
+      for (const item of items) {
+        const countInput = item.querySelector('input[name="count"]');
+        const timeInput = item.querySelector('input[name="minutes"]');
+        const count = countInput.valueAsNumber;
+        const minutesPerItem = timeInput.valueAsNumber;
+
+        if (!Number.isFinite(count) || !Number.isFinite(minutesPerItem)) {
+          message.textContent = "すべての作業について、件数と時間を入力してください。";
+          if (!Number.isFinite(count)) {
+            countInput.focus();
+          } else {
+            timeInput.focus();
+          }
+          return;
+        }
+
+        if (count < 0 || !Number.isInteger(count)) {
+          message.textContent = "作業件数は0以上の整数で入力してください。";
+          countInput.focus();
+          return;
+        }
+
+        if (minutesPerItem < 0) {
+          message.textContent = "1件あたりの時間は0以上で入力してください。";
+          timeInput.focus();
+          return;
+        }
+
+        totalMinutes += count * minutesPerItem;
+
+        if (!Number.isFinite(totalMinutes)) {
+          message.textContent = "入力値が大きすぎるため計算できません。";
+          return;
+        }
+      }
+
+      result.textContent =
+        `${formatNumber(totalMinutes)}分(${formatDuration(totalMinutes)})`;
+    });
+
+    createWorkItem();
+  </script>
+</body>
 </html>