Repository: buildo/react-cookie-banner Branch: master Commit: 79eb5aca6629 Files: 27 Total size: 45.0 KB Directory structure: gitextract_jyj6cf0v/ ├── .gitignore ├── .hophoprc ├── .smooth-releaserc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── ci/ │ ├── pipeline.yml │ ├── test.sh │ └── test.yml ├── examples/ │ ├── Examples.md │ └── examples.scss ├── package.json ├── src/ │ ├── BannerContent.tsx │ ├── CookieBanner.tsx │ ├── CookieBannerUniversal.tsx │ ├── README.md │ ├── index.ts │ └── styleUtils.ts ├── styleguide/ │ ├── index.html │ └── setup.ts ├── styleguide.config.js ├── test/ │ ├── setup.js │ └── tests/ │ ├── CookieBanner.test.tsx │ └── __snapshots__/ │ └── CookieBanner.test.tsx.snap ├── tsconfig.json ├── typings/ │ └── react-cookie.d.ts └── webpack.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ node_modules coverage npm-debug.log lib .vscode ================================================ FILE: .hophoprc ================================================ toggl: n branchPrefix: n branchSuffix: y ================================================ FILE: .smooth-releaserc ================================================ { "github": { "dataType": "pullRequests" }, "tasks": { "npm-publish": true, "npm-version": true, "gh-release": true, "changelog": true } } ================================================ FILE: CHANGELOG.md ================================================ # Change Log ## [v4.1.0](https://github.com/buildo/react-cookie-banner/tree/v4.1.0) (2019-12-11) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v4.0.0...v4.1.0) #### New features: - Leverage componentDidUpdate hook instead of componentWillReceiveProps [#67](https://github.com/buildo/react-cookie-banner/pull/67) - Fixing build after migration to Concourse [#64](https://github.com/buildo/react-cookie-banner/pull/64) - Migrating from drone to concourse [#63](https://github.com/buildo/react-cookie-banner/pull/63) - Updated link prop documentation [#57](https://github.com/buildo/react-cookie-banner/pull/57) ## [v4.0.0](https://github.com/buildo/react-cookie-banner/tree/v4.0.0) (2018-05-04) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v3.0.0...v4.0.0) #### New features: - Clarify usage of onAccept-callback in documentation [#53](https://github.com/buildo/react-cookie-banner/pull/53) - #35: support `Link` from react-router-dom (button-close not rendered anymore when using custom children) (closes #35) [#52](https://github.com/buildo/react-cookie-banner/pull/52) - Add Click To Dismiss [#51](https://github.com/buildo/react-cookie-banner/pull/51) ## [v3.0.0](https://github.com/buildo/react-cookie-banner/tree/v3.0.0) (2017-12-12) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v2.0.0...v3.0.0) #### Breaking: - Accessibility improvements: Button elements & a rel attributes [#43](https://github.com/buildo/react-cookie-banner/pull/43) ## [v2.0.0](https://github.com/buildo/react-cookie-banner/tree/v2.0.0) (2017-12-12) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v1.0.1...v2.0.0) #### New features: - #41: Server side rendering issues (closes #41) [#42](https://github.com/buildo/react-cookie-banner/pull/42) ## [v1.0.1](https://github.com/buildo/react-cookie-banner/tree/v1.0.1) (2017-12-04) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v1.0.0...v1.0.1) #### Fixes (bugs & defects): - #39: import in v1.0.0 is broken (closes #39) [#40](https://github.com/buildo/react-cookie-banner/pull/40) ## [v1.0.0](https://github.com/buildo/react-cookie-banner/tree/v1.0.0) (2017-12-03) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.18...v1.0.0) #### Breaking: - #37: Refactor in TypeScript! (closes #37) [#38](https://github.com/buildo/react-cookie-banner/pull/38) #### New features: - Adding import to react-components showroom example [#36](https://github.com/buildo/react-cookie-banner/pull/36) ## [v0.0.18](https://github.com/buildo/react-cookie-banner/tree/v0.0.18) (2017-05-03) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.17...v0.0.18) #### New features: - Add a 'cookiePath' property [#34](https://github.com/buildo/react-cookie-banner/pull/34) - #29: Template and cookie logic should live in different components (closes #29) [#30](https://github.com/buildo/react-cookie-banner/pull/30) #### Fixes (bugs & defects): - #31: React15 throws warning for unknown prop (closes #31) [#32](https://github.com/buildo/react-cookie-banner/pull/32) ## [v0.0.17](https://github.com/buildo/react-cookie-banner/tree/v0.0.17) (2016-10-13) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.16...v0.0.17) #### New features: - #26: Use eslint-config-buildo (closes #26) [#27](https://github.com/buildo/react-cookie-banner/pull/27) - Custom component can receive onAccept prop using a children function [#25](https://github.com/buildo/react-cookie-banner/pull/25) ## [v0.0.16](https://github.com/buildo/react-cookie-banner/tree/v0.0.16) (2016-10-05) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.15...v0.0.16) #### New features: - #23: Cookie expiration date (closes #23) [#24](https://github.com/buildo/react-cookie-banner/pull/24) - #21: Renew example (closes #21) [#22](https://github.com/buildo/react-cookie-banner/pull/22) ## [v0.0.15](https://github.com/buildo/react-cookie-banner/tree/v0.0.15) (2016-09-14) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.14...v0.0.15) ## [v0.0.14](https://github.com/buildo/react-cookie-banner/tree/v0.0.14) (2016-08-10) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.13...v0.0.14) ## [v0.0.13](https://github.com/buildo/react-cookie-banner/tree/v0.0.13) (2016-08-10) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.12...v0.0.13) #### Fixes (bugs & defects): - Replace `mousewheel` event with `scroll` [#20](https://github.com/buildo/react-cookie-banner/pull/20) #### New features: - #16: if dismissOnScroll at false, the click on the close button do not close the banner (closes #16) [#17](https://github.com/buildo/react-cookie-banner/pull/17) ## [v0.0.12](https://github.com/buildo/react-cookie-banner/tree/v0.0.12) (2016-05-31) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.11...v0.0.12) #### New features: - add target to the cookie-link [#14](https://github.com/buildo/react-cookie-banner/pull/14) ## [v0.0.11](https://github.com/buildo/react-cookie-banner/tree/v0.0.11) (2015-12-11) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.10...v0.0.11) ## [v0.0.10](https://github.com/buildo/react-cookie-banner/tree/v0.0.10) (2015-10-14) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.9...v0.0.10) #### New features: - #9: code clean (closes #9) [#10](https://github.com/buildo/react-cookie-banner/pull/10) - Allow custom styles [#8](https://github.com/buildo/react-cookie-banner/pull/8) - #3: Remove .gitkeep from src and tests (closes #3) [#7](https://github.com/buildo/react-cookie-banner/pull/7) ## [v0.0.9](https://github.com/buildo/react-cookie-banner/tree/v0.0.9) (2015-07-14) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.8...v0.0.9) #### Fixes (bugs & defects): - #5: Is not safe for universal rendering [#6](https://github.com/buildo/react-cookie-banner/pull/6) ## [v0.0.8](https://github.com/buildo/react-cookie-banner/tree/v0.0.8) (2015-07-03) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.7...v0.0.8) #### New features: - dismissOnScroll should take an optional Y threshold (default: 0) [#4](https://github.com/buildo/react-cookie-banner/pull/4) ## [v0.0.7](https://github.com/buildo/react-cookie-banner/tree/v0.0.7) (2015-06-30) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.6...v0.0.7) ## [v0.0.6](https://github.com/buildo/react-cookie-banner/tree/v0.0.6) (2015-06-29) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.5...v0.0.6) ## [v0.0.5](https://github.com/buildo/react-cookie-banner/tree/v0.0.5) (2015-06-25) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.4...v0.0.5) ## [v0.0.4](https://github.com/buildo/react-cookie-banner/tree/v0.0.4) (2015-06-19) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.3...v0.0.4) ## [v0.0.3](https://github.com/buildo/react-cookie-banner/tree/v0.0.3) (2015-06-14) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.2...v0.0.3) ## [v0.0.2](https://github.com/buildo/react-cookie-banner/tree/v0.0.2) (2015-06-12) [Full Changelog](https://github.com/buildo/react-cookie-banner/compare/v0.0.1...v0.0.2) ## [v0.0.1](https://github.com/buildo/react-cookie-banner/tree/v0.0.1) (2015-06-12) ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2015 buildo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ [](https://drone.our.buildo.io/buildo/react-cookie-banner)  # React Cookie Banner A cookie banner for React that can be dismissed with a simple scroll. Because [fuck the Cookie Law](http://nocookielaw.com/) that's why. (If you *really* want to annoy your users you can disable this feature but this is strongly discouraged!). ```jsx import CookieBanner from 'react-cookie-banner'; React.renderComponent(
accepts-cookies: {cookies.get('accepts-cookies') || 'false'}
union(ReactChildren | Function) | | *optional*. Custom component rendered if user has not accepted cookies |
| **message** | String | | *optional*. Message written inside default cookie banner |
| **onAccept** | Function | "onAccept" | *optional*. Called when user accepts cookies |
| **link** | JSX.Element | | *optional*. JSX element to link to your cookie-policy page |
| **buttonMessage** | String | "Got it" | *optional*. Message written inside the button of the default cookie banner |
| **cookie** | String | "accepts-cookies" | *optional*. Cookie-key used to save user's decision about you cookie-policy |
| **cookieExpiration** | union(Integer | {years: ?Number, days: ?Number, hours: ?Number}) | { "years": 1 } | *optional*. Used to set the cookie expiration |
| **cookiePath** | String | | *optional*. Used to set the cookie path |
| **dismissOnScroll** | Boolean | true | *optional*. Whether the cookie banner should be dismissed on scroll or not |
| **dismissOnScrollThreshold** | Number | 0 | *optional*. amount of pixel the user need to scroll to dismiss the cookie banner |
| **closeIcon** | String | | *optional*. ClassName passed to close-icon |
| **disableStyle** | Boolean | | *optional*. Pass `true` if you want to disable default style |
| **styles** | Object | {} | *optional*. Object with custom styles used to overwrite default ones |
| **className** | String | | *optional*. Additional `className` for wrapper element |
================================================
FILE: src/index.ts
================================================
import CookieBanner from './CookieBanner';
import CookieBannerUniversal from './CookieBannerUniversal';
import BannerContent from './BannerContent';
export default CookieBanner;
export { Cookies, CookiesProvider } from 'react-cookie';
export { BannerContent, CookieBannerUniversal }
================================================
FILE: src/styleUtils.ts
================================================
const styles = {
icon: {
background: 'none',
border: 'none',
boxShadow: 'none',
padding: '0',
position: 'absolute',
fontSize: '1em',
top: '50%',
marginTop: '-0.5em',
right: '1em',
color: 'white',
cursor: 'pointer'
},
link: {
color: '#F0F0F0',
textDecoration: 'underline',
marginLeft: '10px'
},
button: {
position: 'absolute',
top: '50%',
right: '35px',
lineHeight: '24px',
marginTop: '-12px',
padding: '0 8px',
backgroundColor: 'rgba(255, 255, 255, 0.6)',
border: 'none',
borderRadius: '3px',
boxShadow: 'none',
fontSize: '12px',
fontWeight: '500',
color: '#242424',
cursor: 'pointer'
},
message: {
lineHeight: '45px',
fontWeight: 500,
color: '#F0F0F0'
},
banner: {
position: 'relative',
textAlign: 'center',
backgroundColor: '#484848',
width: '100%',
height: '45px',
zIndex: '10000'
}
};
const getStyle = (style: 'message' | 'banner' | 'link' | 'button' | 'icon') => styles[style];
export { getStyle };
================================================
FILE: styleguide/index.html
================================================
================================================
FILE: styleguide/setup.ts
================================================
import { Cookies, CookiesProvider } from 'react-cookie';
import { CookieBannerUniversal } from '../src';
import '../examples/examples.scss';
import '../examples/cookie.png';
(global as any).cookies = new Cookies();
(global as any).CookiesProvider = CookiesProvider;
(global as any).Cookies = Cookies;
(global as any).CookieBannerUniversal = CookieBannerUniversal;
================================================
FILE: styleguide.config.js
================================================
const path = require('path');
module.exports = {
// build
serverPort: 8080,
require: [
// "global" setup + sass imports
path.resolve(__dirname, 'styleguide/setup.ts')
],
// content
title: 'react-cookie-banner',
// assetsDir: 'styleguide/assets',
template: 'styleguide/index.html',
propsParser: require('react-docgen-typescript').parse, // detect docs using TS information
sections: [{
name: 'CookieBanner',
components: () => [path.resolve(__dirname, 'src/CookieBanner.tsx')]
}],
showCode: true,
showUsage: false, // show props by default
getExampleFilename() {
return path.resolve(__dirname, 'examples/Examples.md');
}
};
================================================
FILE: test/setup.js
================================================
global.requestAnimationFrame = (callback) => {
setTimeout(callback, 0);
};
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
Enzyme.configure({ adapter: new Adapter() });
================================================
FILE: test/tests/CookieBanner.test.tsx
================================================
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as React from 'react';
import { shallow, mount } from 'enzyme';
import CookieBanner from '../../src';
import { getStyle } from '../../src/styleUtils';
function resetCookies() {
const cookies = document.cookie.split(';');
cookies.forEach(cookie => {
const eqPos = cookie.indexOf('=');
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;
});
};
beforeEach(resetCookies);
describe('secondsSinceExpiration', () => {
const { getSecondsSinceExpiration } = new CookieBanner({ onAccept: () => {} });
it('should return "cookieExpiration" if it is an integer', () => {
expect(getSecondsSinceExpiration(12345)).toBe(12345);
});
it('should transform "years", "days" and "hours" into seconds', () => {
expect(getSecondsSinceExpiration({ years: 1, days: 10, hours: 5 })).toBe(32418000);
});
it('should handle missing "years", "days" or "hours"', () => {
expect(getSecondsSinceExpiration({ days: 10 })).toBe(864000);
expect(getSecondsSinceExpiration({})).toBe(0);
});
});
describe('CookieBanner', () => {
it('should be displayed if no cookies are set', () => {
const component = shallow(