mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-01-20 18:41:44 +01:00
Added custom attribute props for content and container
This commit is contained in:
parent
8c86599f24
commit
eaaf6f8797
@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [[7.1.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.1.0)]
|
||||||
|
|
||||||
|
- Added custom attribute props for content and container
|
||||||
|
|
||||||
## [[7.0.1](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.0.1)]
|
## [[7.0.1](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.0.1)]
|
||||||
|
|
||||||
- Configured webpack to remove self from build artefact. Should now work in Nextjs and Gatsby (only tested those..)
|
- Configured webpack to remove self from build artefact. Should now work in Nextjs and Gatsby (only tested those..)
|
||||||
|
@ -180,6 +180,10 @@ That option would be interesting if you want to allow user to change their conse
|
|||||||
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) |
|
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) |
|
||||||
| acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled |
|
| acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled |
|
||||||
|
|
||||||
|
| customContentAttributes
|
||||||
|
| object | {} | Allows you to set custom (data) attributes on the content div |
|
||||||
|
| customContainerAttributes | object | {} | Allows you to set custom (data) attributes on the container div |
|
||||||
|
|
||||||
## Debugging it
|
## Debugging it
|
||||||
|
|
||||||
Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes:
|
Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes:
|
||||||
|
2
src/index.d.ts
vendored
2
src/index.d.ts
vendored
@ -42,6 +42,8 @@ export interface CookieConsentProps {
|
|||||||
ariaDeclineLabel?: string;
|
ariaDeclineLabel?: string;
|
||||||
acceptOnScroll?: boolean;
|
acceptOnScroll?: boolean;
|
||||||
acceptOnScrollPercentage?: number;
|
acceptOnScrollPercentage?: number;
|
||||||
|
customContentAttributes: object;
|
||||||
|
customContainerAttributes: object;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
||||||
|
18
src/index.js
18
src/index.js
@ -15,10 +15,10 @@ export const SAME_SITE_OPTIONS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const VISIBLE_OPTIONS = {
|
export const VISIBLE_OPTIONS = {
|
||||||
HIDDEN: 'hidden',
|
HIDDEN: "hidden",
|
||||||
SHOW: 'show',
|
SHOW: "show",
|
||||||
BY_COOKIE_VALUE: 'byCookieValue'
|
BY_COOKIE_VALUE: "byCookieValue",
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the consent cookie
|
* Returns the value of the consent cookie
|
||||||
@ -279,6 +279,8 @@ class CookieConsent extends Component {
|
|||||||
overlayStyle,
|
overlayStyle,
|
||||||
ariaAcceptLabel,
|
ariaAcceptLabel,
|
||||||
ariaDeclineLabel,
|
ariaDeclineLabel,
|
||||||
|
customContainerAttributes,
|
||||||
|
customContentAttributes,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
let myStyle = {};
|
let myStyle = {};
|
||||||
@ -372,8 +374,8 @@ class CookieConsent extends Component {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className={`${containerClasses}`} style={myStyle}>
|
<div className={`${containerClasses}`} style={myStyle} {...customContainerAttributes}>
|
||||||
<div style={myContentStyle} className={contentClasses}>
|
<div style={myContentStyle} className={contentClasses} {...customContentAttributes}>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
<div className={`${buttonWrapperClasses}`}>
|
<div className={`${buttonWrapperClasses}`}>
|
||||||
@ -429,6 +431,8 @@ CookieConsent.propTypes = {
|
|||||||
ariaDeclineLabel: PropTypes.string,
|
ariaDeclineLabel: PropTypes.string,
|
||||||
acceptOnScroll: PropTypes.bool,
|
acceptOnScroll: PropTypes.bool,
|
||||||
acceptOnScrollPercentage: PropTypes.number,
|
acceptOnScrollPercentage: PropTypes.number,
|
||||||
|
customContentAttributes: PropTypes.object,
|
||||||
|
customContainerAttributes: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
CookieConsent.defaultProps = {
|
CookieConsent.defaultProps = {
|
||||||
@ -466,6 +470,8 @@ CookieConsent.defaultProps = {
|
|||||||
ariaDeclineLabel: "Decline cookies",
|
ariaDeclineLabel: "Decline cookies",
|
||||||
acceptOnScroll: false,
|
acceptOnScroll: false,
|
||||||
acceptOnScrollPercentage: 25,
|
acceptOnScrollPercentage: 25,
|
||||||
|
customContentAttributes: {},
|
||||||
|
customContainerAttributes: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CookieConsent;
|
export default CookieConsent;
|
||||||
|
Loading…
Reference in New Issue
Block a user