npm package: @sabbirshaawon/easy-cookie-consent
Description: A simple and customizable cookie consent package
Author: Sabbir Ahmed
Latest version: 1.0.2

# Easy Cookie Consent

A lightweight, customizable cookie consent banner package for modern web applications. Easy to implement, highly customizable, and feature-rich.

[![npm](https://img.shields.io/npm/v/@sabbirshaawon/easy-cookie-consent)](https://www.npmjs.com/package/@sabbirshaawon/easy-cookie-consent)
[![License](https://img.shields.io/npm/l/@sabbirshaawon/easy-cookie-consent)](https://github.com/sabbirshawon/easy-cookie-consent/blob/main/LICENSE)
[![GitHub Issues](https://img.shields.io/github/issues/sabbirshawon/easy-cookie-consent)](https://github.com/sabbirshawon/easy-cookie-consent/issues)
[![GitHub Stars](https://img.shields.io/github/stars/sabbirshawon/easy-cookie-consent)](https://github.com/sabbirshawon/easy-cookie-consent/stargazers)

## Features

- 🚀 Easy to implement
- 🎨 Fully customizable design
- 📱 Responsive and mobile-friendly
- 🔧 Configurable options
- 🌐 GDPR compliant
- ⚡ Lightweight
- 🎉 No dependencies except js-cookie

## Installation

```bash
npm install @sabbirshaawon/easy-cookie-consent
```

## Quick Start

```javascript
import EasyCookieConsent from '@sabbirshaawon/easy-cookie-consent';

// Initialize with default options
const cookieConsent = new EasyCookieConsent();
```

## Usage Examples

### Basic Usage

```javascript
import EasyCookieConsent from '@sabbirshaawon/easy-cookie-consent';

const cookieConsent = new EasyCookieConsent({
  message: 'We use cookies to enhance your experience.',
  acceptText: 'Accept All',
  declineText: 'Decline'
});
```

### Advanced Usage

```javascript
const cookieConsent = new EasyCookieConsent({
  cookieName: 'my_cookie_consent',
  expiryDays: 30,
  message: 'We use cookies to improve your experience.',
  acceptText: 'Got it!',
  declineText: 'No thanks',
  customClass: 'my-custom-banner',
  position: 'top',
  onAccept: () => {
    console.log('Cookies accepted');
    // Your custom code here
  },
  onDecline: () => {
    console.log('Cookies declined');
    // Your custom code here
  }
});
```

## Customization

### Custom Styling

Add your own CSS classes to customize the appearance:

```css
/* Custom banner style */
.my-custom-banner {
  background: #2c3e50;
  color: white;
}

/* Custom button style */
.my-custom-banner .cookie-consent-button {
  background: #3498db;
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
}

.my-custom-banner .cookie-consent-accept {
  background: #2ecc71;
}

.my-custom-banner .cookie-consent-decline {
  background: #e74c3c;
}
```

## Configuration Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| cookieName | string | 'cookie_consent' | Name of the cookie to store consent |
| expiryDays | number | 365 | Days until the cookie expires |
| message | string | 'This website uses cookies...' | Consent message to display |
| acceptText | string | 'Accept' | Text for accept button |
| declineText | string | 'Decline' | Text for decline button |
| customClass | string | '' | Custom CSS class for styling |
| position | string | 'bottom' | Banner position ('top' or 'bottom') |
| onAccept | function | () => {} | Callback when cookies are accepted |
| onDecline | function | () => {} | Callback when cookies are declined |

## Methods

### getCookieConsent()

Returns the current cookie consent status.

```javascript
const status = cookieConsent.getCookieConsent();
```

### setCookieConsent(value)

Manually set the cookie consent status.

```javascript
cookieConsent.setCookieConsent('accepted');
```

## Events

The package provides two callback events:

```javascript
const cookieConsent = new EasyCookieConsent({
  onAccept: () => {
    // Triggered when user accepts cookies
    console.log('Cookies accepted');
  },
  onDecline: () => {
    // Triggered when user declines cookies
    console.log('Cookies declined');
  }
});
```

## Browser Support

- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Opera (latest)
- Mobile browsers (latest)

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Check out our [GitHub repository](https://github.com/sabbirshawon/easy-cookie-consent).

1. Fork the [project](https://github.com/sabbirshawon/easy-cookie-consent/fork)
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Author

Sabbir Ahmed

## Support

If you have any questions or need help with implementation, please [create an issue](https://github.com/sabbirshawon/easy-cookie-consent/issues) in the GitHub repository.