Skip to content

Commit

Permalink
Merge pull request mostafizurhimself#149 from tech-masih/feat/check-all
Browse files Browse the repository at this point in the history
Add check all functionality
  • Loading branch information
mostafizurhimself authored Apr 30, 2023
2 parents f124124 + 7be64ab commit 30b6b53
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/badge.html
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ <h4 class="card-title">Badge With Icon</h4>
<!-- Page Content Ends -->
</div>
<!-- Wrapper Ends -->

<!-- Search Modal Start -->
<div class="modal" id="search-modal">
<div class="modal-dialog">
Expand Down
27 changes: 16 additions & 11 deletions src/customer-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,12 @@ <h2 class="my-1 text-sm font-medium">Status</h2>
<thead>
<tr>
<th class="w-[5%]">
<input class="checkbox" type="checkbox" />
<input
class="checkbox"
type="checkbox"
data-check-all
data-check-all-target=".customer-checkbox"
/>
</th>
<th class="w-[45%] uppercase">Customer</th>
<th class="w-[15%] uppercase">Phone</th>
Expand All @@ -844,7 +849,7 @@ <h2 class="my-1 text-sm font-medium">Status</h2>
<tbody>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -899,7 +904,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -954,7 +959,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1009,7 +1014,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1063,7 +1068,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1117,7 +1122,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1171,7 +1176,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1226,7 +1231,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1281,7 +1286,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down Expand Up @@ -1336,7 +1341,7 @@ <h6 class="whitespace-nowrap text-sm font-medium text-slate-700 dark:text-slate-
</tr>
<tr>
<td>
<input class="checkbox" type="checkbox" />
<input class="checkbox customer-checkbox" type="checkbox" />
</td>
<td>
<div class="flex items-center gap-3">
Expand Down
22 changes: 11 additions & 11 deletions src/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
<!-- Email Toolbar Starts -->
<div class="flex items-center justify-between px-4 py-3">
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input id="email-check-all" type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox" data-check-all data-check-all-target=".email-checkbox" />
<button
id="email-reload-all"
type="button"
Expand Down Expand Up @@ -1057,7 +1057,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-personal="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1128,7 +1128,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-company="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1199,7 +1199,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-important="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1273,7 +1273,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-promotions="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1346,7 +1346,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-personal="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1417,7 +1417,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-company="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1488,7 +1488,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-important="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1559,7 +1559,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-promotions="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1632,7 +1632,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-personal="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down Expand Up @@ -1706,7 +1706,7 @@ <h6 class="text-sm font-normal">Your order has been shipped</h6>
data-filter-by-company="true"
>
<div class="flex items-center gap-x-3 sm:gap-x-6">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox email-checkbox" />
<button
type="button"
class="hidden text-slate-500 focus:text-slate-700 group-[.mark-as-starred]:text-warning-500 dark:text-slate-400 dark:focus:text-slate-300 sm:block"
Expand Down
10 changes: 7 additions & 3 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'simplebar';
import accordion from './components/accordion';
import alert from './components/alert';
import carousel from './components/carousel';
import checkAll from './components/check-all';
import codeViewer from './components/code-viewer';
import datepicker from './components/datepicker';
import drawer from './components/drawer';
Expand All @@ -22,12 +23,12 @@ import themeSwitcher from './components/theme-switcher';
import tooltip from './components/tooltip';
import uploader from './components/uploader';

// Initialize themeSwitcher
themeSwitcher.init();

// Initialize searchModal
searchModal.init();

// Initialize themeSwitcher
themeSwitcher.init();

// Initialize codeViewer
codeViewer.init();

Expand Down Expand Up @@ -70,6 +71,9 @@ datepicker.init();
// Initialize drawer
drawer.init();

// Initialize checkAll
checkAll.init();

// Initialize feather-icons. Must be Initialize at the end.
feather.replace();

Expand Down
64 changes: 64 additions & 0 deletions src/js/components/check-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export class CheckAll {
constructor(trigger) {
if (typeof trigger === 'string') {
this.trigger = document.querySelector(trigger);
}

if (trigger instanceof HTMLElement) {
this.trigger = trigger;
}

if (!this.trigger) {
throw new Error('No target element found');
}

this.targets = document.querySelectorAll(this.trigger.dataset.checkAllTarget);

if (!this.targets) {
throw new Error('No target element found');
}

this.init();
}

handleCheck() {
this.targets.forEach((target) => {
target.checked = true;
});
}

handleUncheck() {
this.targets.forEach((target) => {
target.checked = false;
});
}

init() {
this.trigger.addEventListener('click', () => {
if (this.trigger.checked) {
this.handleCheck();
} else {
this.handleUncheck();
}
});

this.targets.forEach((target) => {
target.addEventListener('click', () => {
const isAllChecked = Array.from(this.targets).every((target) => target.checked);
this.trigger.checked = isAllChecked;
});
});
}
}

const checkAll = {
init: function () {
const triggers = document.querySelectorAll('[data-check-all');

triggers.forEach((trigger) => {
new CheckAll(trigger);
});
},
};

export default checkAll;
Loading

0 comments on commit 30b6b53

Please sign in to comment.