Skip to content

Commit 03e2ad7

Browse files
author
Nikolaev Tomov
authored
Merge pull request #353 from dabapps/cookie-banner-max-age
Set optional max age for cookie banner
2 parents 245a011 + b173157 commit 03e2ad7

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dabapps/roe",
3-
"version": "0.13.0",
3+
"version": "0.13.1",
44
"description": "A collection of React components, styles, mixins, and atomic CSS classes to aid with the development of web applications.",
55
"main": "dist/js/index.js",
66
"types": "dist/js/index.d.ts",

src/ts/components/banners/cookie-banner.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,30 @@ export type CookieBannerProps = {
2323
* @default 'bottom'
2424
*/
2525
position?: 'top' | 'bottom';
26+
/**
27+
* Sets maximum age for the cookie in seconds
28+
* @default 60 * 60 * 24 * 365
29+
*/
30+
maxAge?: number;
2631
} & OptionalComponentPropAndHTMLAttributes;
2732

2833
/**
2934
* A [Banner](#banner) component that is permanently dismissed after setting a cookie.
3035
* This component takes a render prop, which can be a component or function, that is passed a dismiss prop
3136
* which you can then apply as an onClick prop to an element of your choice.
3237
*/
38+
39+
const A_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
40+
3341
const CookieBanner = (props: CookieBannerProps) => {
3442
const [dismissed, setDismissed] = React.useState(
3543
Boolean(cookie.parse(document.cookie)['cookies-accepted'])
3644
);
3745

3846
const setCookie = () => {
39-
document.cookie = cookie.serialize('cookies-accepted', 'true');
47+
document.cookie = cookie.serialize('cookies-accepted', 'true', {
48+
maxAge: props.maxAge || A_YEAR_IN_SECONDS,
49+
});
4050
setDismissed(true);
4151
};
4252

0 commit comments

Comments
 (0)