-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
[Docs]: Is it possible to create a custom build; with custom defaults? #604
Labels
documentation
Improvements or additions to documentation
Comments
ceesvanegmond
changed the title
[Docs]: Is it possible to create a custom build; with other defaults?
[Docs]: Is it possible to create a custom build; with custom defaults?
Dec 1, 2023
@ceesvanegmond you can do it, but you need to create your own wrapper and a proper merge function to merge the 2 configs. Here is a proof of concept using v3: index.js import * as CookieConsent from "vanilla-cookieconsent"
import defaultConfig from "./defaultConfig";
const mergeConfigs = (defaultConfig, userConfig) => {
const mergedConfig = { ...defaultConfig };
for (const key in userConfig) {
if (userConfig.hasOwnProperty(key)) {
if (typeof userConfig[key] === 'object' && userConfig[key] !== null && defaultConfig[key]) {
mergedConfig[key] = mergeConfigs(defaultConfig[key], userConfig[key]);
} else {
mergedConfig[key] = userConfig[key];
}
}
}
return mergedConfig;
}
// Export your custom run method
export const run = async (userConfig = {}) => {
await CookieConsent.run(mergeConfigs(defaultConfig, userConfig));
};
export const acceptService = CookieConsent.acceptCategory;
export const acceptedCategory = CookieConsent.acceptedCategory;
export const acceptedService = CookieConsent.acceptedService;
// TODO: export the other methods |
@orestbida Thanks! Works! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the improvement/update you wish to see?
Hi all,
I first have to say! What a great library! It's so diverse and usable. Thank you!
I do have one question. At the moment; we can use the
run()
method. Therun
method expects an config json and this also inits the consent.My question; is it possible to set defaults before calling the
run()
method? Maybe already in the build (custom)?We create lots of website and for the cookiebar it's 80% the same except the type of cookies and colors; so I want to see if we can somehow create a build with defaults that match our config; and override the config that's specific to the client.
Is this possible?
Link the related docs page, if it exists.
No response
The text was updated successfully, but these errors were encountered: