Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor buttons #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/lib/Banner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
/**
* @type {string|undefined|null}
*/
export let acceptLabel = 'Accept cookies'
export let rejectLabel = 'Reject cookies'
export let acceptLabel = 'Accept all'
export let rejectLabel = 'Reject all'
export let settingsLabel = 'Cookie settings'
export let closeLabel = 'Close settings'
export let editLabel = 'Edit cookie settings'
export let saveLabel = 'Accept selected'

/**
* Whether to show the cookie banner if the user has not yet accepted or rejected your choices.
Expand Down Expand Up @@ -108,6 +109,11 @@
return result
}, {})

$: allCookieChoices = choicesArr.reduce((result, item) => {
result[item.id] = true
return result
}, {})

export function show () {
shown = visible
}
Expand Down Expand Up @@ -179,6 +185,11 @@
setCookie(cookieChoices)
execute(cookieChoices)
}

function accept () {
setCookie(allCookieChoices)
execute(allCookieChoices)
}
</script>

{#if showEditIcon}
Expand Down Expand Up @@ -230,6 +241,15 @@
on:click={() => { settingsShown = true } }>
{settingsLabel}
</button>
<button
type="submit"
class="cookieConsent__Button"
part="button"
on:click={choose}
aria-label={saveLabel}
>
{saveLabel}
</button>
{#if canRejectCookies}
<button
type="submit"
Expand All @@ -245,7 +265,7 @@
type="submit"
class="cookieConsent__Button"
part="button"
on:click={choose}
on:click={accept}
aria-label={acceptLabel}
>
{acceptLabel}
Expand Down