Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
CountNick committed Jun 18, 2024
1 parent c9eafb5 commit 5e8a4ca
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
4 changes: 2 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Dialog from "./src/dialog.mjs";
import CookieConsent from "./src/cookie-consent.mjs";

export default Dialog;
export default CookieConsent;
1 change: 0 additions & 1 deletion src/config-defaults.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const DEFAULTS = {
type: "checkbox",
prefix: "cookie-consent",
append: true,
appendDelay: 500,
Expand Down
29 changes: 0 additions & 29 deletions src/dialog.mjs → src/cookie-consent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,6 @@ export default class Dialog extends HTMLElement {
}

composeValues(values) {
/**
* Compose values based on input type, the `acceptAllButton` configuration,
* any stored preferences and the state of the input options.
*
* When an option is checked, the form will just submit. When nothing is checked,
* it depends on the type and the `acceptAllButton` config setting.
*
* - Radio + option checked: success
* - Radio + nothing checked + has `acceptAllButton`: select first + success
* - Radio + nothing checked + no `acceptAllButton`: fail
*
* - Checkbox + option(s) checked: success
* - Checkbox + nothing checked + has `acceptAllButton`: select all + success
* - Checkbox + nothing checked + no `acceptAllButton`: success
*/

// Radio when no option is selected.
if (this.config.type === "radio" && !values.find((v) => v.accepted)) {
// If the `acceptAllButton` option is configured, select the first option and
// let the form submit as if the user had selected it.
if (this.data.acceptAllButton) {
values[0].accepted = true;
return values;
}
// Do not submit if no option is selected and `acceptAllButton` is not configured.
return [];
}

// Checkbox with `acceptAllButton` and no user-choosable option is checked.
// We compare amount of required options against checked options.

Expand All @@ -224,7 +196,6 @@ export default class Dialog extends HTMLElement {
}

// Return the values untouched. Happens for:
// - Radio when an option has been selected.
// - Checkbox with or without checked option, except the `acceptAllButton` case above.
return values;
}
Expand Down
5 changes: 2 additions & 3 deletions src/dialog-tablist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Preferences from "./preferences.mjs";
const DialogTabList = (cookieInformation) => {
const events = EventDispatcher();

const TYPE = Config().get("type");
const PREFIX = Config().get("prefix");

/**
Expand Down Expand Up @@ -49,10 +48,10 @@ const DialogTabList = (cookieInformation) => {
<label part="${PREFIX}__option" class="${PREFIX}__option" data-required="${required}">
<input
part="${PREFIX}__input"
type="${TYPE === "radio" ? "radio" : "checkbox"}"
type="checkbox"
name="${PREFIX}-input" value="${id}"
${shouldBeChecked ? "checked" : ""}
${required && TYPE !== "radio" ? "disabled" : ""}>
${required && "disabled"}>
<span>${label}</span>
</label>
<a
Expand Down

0 comments on commit 5e8a4ca

Please sign in to comment.