Browse Source

Base: Replace bespoke input switch with native element

Turns out we support <input type=checkbox switch>, so let's use it!
Timothy Flynn 1 week ago
parent
commit
49dae536a7
2 changed files with 23 additions and 70 deletions
  1. 13 20
      Base/res/ladybird/about-pages/settings.html
  2. 10 50
      Base/res/ladybird/ladybird.css

+ 13 - 20
Base/res/ladybird/about-pages/settings.html

@@ -90,6 +90,12 @@
                 margin-bottom: 0;
             }
 
+            .toggle-container {
+                display: flex;
+                align-items: center;
+                justify-content: space-between;
+            }
+
             .permission-container {
                 display: flex;
                 align-items: center;
@@ -287,14 +293,9 @@
         <div class="card">
             <div class="card-header">Search</div>
             <div class="card-body">
-                <div class="card-group">
-                    <div class="toggle-container">
-                        <label for="search-toggle">Enable Search</label>
-                        <label class="toggle">
-                            <input id="search-toggle" type="checkbox" />
-                            <span class="toggle-button"></span>
-                        </label>
-                    </div>
+                <div class="card-group toggle-container">
+                    <label for="search-toggle">Enable Search</label>
+                    <input id="search-toggle" type="checkbox" switch />
                 </div>
                 <div class="card-group hidden">
                     <label for="search-engine">Default Search Engine</label>
@@ -306,14 +307,9 @@
 
                 <hr />
 
-                <div class="card-group">
-                    <div class="toggle-container">
-                        <label for="autocomplete-toggle">Enable Autocomplete</label>
-                        <label class="toggle">
-                            <input id="autocomplete-toggle" type="checkbox" />
-                            <span class="toggle-button"></span>
-                        </label>
-                    </div>
+                <div class="card-group toggle-container">
+                    <label for="autocomplete-toggle">Enable Autocomplete</label>
+                    <input id="autocomplete-toggle" type="checkbox" switch />
                 </div>
                 <div class="card-group hidden">
                     <label for="autocomplete-engine">Default Autocomplete Engine</label>
@@ -350,10 +346,7 @@
             <div class="dialog-body">
                 <div class="toggle-container">
                     <label for="site-settings-global">Enable on all sites</label>
-                    <label class="toggle">
-                        <input id="site-settings-global" type="checkbox" />
-                        <span class="toggle-button"></span>
-                    </label>
+                    <input id="site-settings-global" type="checkbox" switch />
                 </div>
                 <hr />
                 <label>Allowlist</label>

+ 10 - 50
Base/res/ladybird/ladybird.css

@@ -146,67 +146,27 @@ select:focus {
     outline: none;
 }
 
-/**
- * Create a toggle switch as a checkbox alternative:
- *
- * <div class="toggle-container">
- *     <label for="your-toggle">Toggle Label</label>
- *     <label class="toggle">
- *         <input id="your-toggle" type="checkbox" checked />
- *         <span class="toggle-button"></span>
- *     </label>
- * </div>
- */
-
-.toggle-container {
-    display: flex;
-    align-items: center;
-    justify-content: space-between;
-}
-
-.toggle-container .toggle {
+input[type="checkbox"][switch] {
     width: 50px;
     height: 24px;
 
-    display: inline-block;
-    position: relative;
-}
-
-.toggle-container .toggle input {
-    display: none;
-}
-
-.toggle-container .toggle-button {
     background-color: var(--toggle-background-color);
-    border-radius: 24px;
+    cursor: pointer;
 
-    position: absolute;
-    top: 0;
-    right: 0;
-    bottom: 0;
-    left: 0;
+    outline: none;
+}
 
-    cursor: pointer;
+input[type="checkbox"][switch]:checked {
+    background-color: var(--violet-100);
 }
 
-.toggle-container .toggle-button:before {
+input[type="checkbox"][switch]::before {
     background-color: white;
-    border-radius: 50%;
+    border: 0.6em solid white;
 
-    content: "";
-
-    width: 18px;
-    height: 18px;
-
-    position: absolute;
-    bottom: 3px;
     left: 3px;
 }
 
-.toggle-container input:checked + .toggle-button {
-    background-color: var(--violet-100);
-}
-
-.toggle-container input:checked + .toggle-button:before {
-    transform: translateX(26px);
+input[type="checkbox"][switch]:checked::before {
+    left: calc(100% - 1.3em);
 }