porscheofficial / cookie-consent-banner

The lightweight and flexible Cookie Consent Banner
MIT License
149 stars 6 forks source link

Typescript error triggerCookieConsentBanner #8

Closed zeitvertrieb closed 2 years ago

zeitvertrieb commented 2 years ago

Node/npm version(s): 8.3.1

Package(s) version(s):

    @porscheofficial/cookie-consent-banner-react@<2.1.3>

Browser(s) version(s): lastest Chrome

Description of the issue/feature: Getting an TS error: Module '"@porscheofficial/cookie-consent-banner-react"' has no exported member 'triggerCookieConsentBanner'.

Some example to reproduce the issue: based on demo code

Use cases:

pboeder commented 2 years ago

Hi @zeitvertrieb !

Sorry for the inconvenience. The documentation already includes features of the upcoming release. Takes a bit longer than anticipated. Will notify you, once this function is available.

ghost commented 2 years ago

Hello @ppuritscher! I was wondering if you have an idea to when this issue will be fixed?

pboeder commented 2 years ago

Hi @learsson !

Will release next version in the upcoming week.

Workaround. The Cookie Consent Banner listens to an event to reveal itself. triggerCookieConsentBanner is just a convenience function.

<button
   onClick={() => { document.dispatchEvent(new Event("cookie_consent_details_show")) }}
   onKeyPress={() => { document.dispatchEvent(new Event("cookie_consent_details_show")) }}
   type="button"
>
  Here
</button>
// Or create convenience function on your own
// TypeScript
export function triggerCookieConsentBanner(options?: {
  showDetails: boolean;
}): void {
  if (options?.showDetails) {
    document.dispatchEvent(new Event("cookie_consent_details_show"));
  } else {
    document.dispatchEvent(new Event("cookie_consent_show"));
  }
}
ghost commented 2 years ago

Thank you for the update, @ppuritscher! Ok, seems straight forward. I must be honest, I did just find this project and it seems like the best CC library out there and I have yet to study the implementation. I will start with a custom method and look for your update later

pboeder commented 2 years ago

Glad to hear that. Always open for feedback :)

pboeder commented 2 years ago

Hi @zeitvertrieb and @learsson!

I just released v3.0.0. triggerCookieConsentBanner is now available. See: https://github.com/porscheofficial/cookie-consent-banner/tree/main/packages/cookie-consent-banner-react#-real-world-example-with-tag-manager-and-custom-error-tracking

Please reopen this issue or create a new one if the issue still persists.