Skip to content

Commit e78c980

Browse files
authored
Merge pull request #23 from Ortovoxx/main
Improved documentation for React
2 parents 9189a03 + 04e9bac commit e78c980

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

README.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
![Add-to-Calendar Button](https://github.com/jekuer/add-to-calendar-button/blob/main/repo_image.png?raw=true)
33

44
_A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars._
5-
5+
66

77
## Use case // Who this is for
88

99
This is for everybody, who wants to include a button at his/her website or app, which enables users to easily add a specific event to their calendars.
1010
It's main goal is to keep this process as easy as possible. Simply define your button configuration via JSON and everything else is automatically generated by the script.
1111
It is for this simple use case. No strings attached.
12-
12+
1313

1414
## Background // Why this repo exists
1515

@@ -23,12 +23,12 @@ The problems with AddEvent.com:
2323
* it brings some data privacy issues, since you basically send your users to their service.
2424
* the UX/UI is not ideal (imho).
2525
*Bottom line:* Pay for features, which I do not need - at additional privacy "cost" - that made me create this solution (for you).
26-
26+
2727

2828
## DEMO
2929

3030
See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-calendar-button/) for a live demo.
31-
31+
3232

3333
## Features
3434

@@ -45,12 +45,12 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
4545
* Well documented code, to easily understand the processes.
4646

4747
![Demo Screenshot](https://github.com/jekuer/add-to-calendar-button/blob/main/demo.gif?raw=true)
48-
48+
4949

5050
## Setup
51-
51+
5252
### Option 1: simple
53-
53+
5454
1. Simply **download** the code from GitHub **or clone** the git repository.
5555
2. Copy the css (atcb.min.css) and js (atcb.min.js) files from the assets (not the "npm_dist"!) folders into your project (the **.min.** files are required, but it is recommended to also copy the raw and map files).
5656
3. Include those files in your project. As usual, the css goes into the <head> (`<link rel="stylesheet" href="./assets/css/atcb.min.css">`), the js into the <body> footer (`<script src="./assets/js/atcb.min.js" defer></script>`). You can also combine them with other files, if you want to.
@@ -63,23 +63,23 @@ See [jekuer.github.io/add-to-calendar-button](https://jekuer.github.io/add-to-ca
6363
2. Run **`npm install add-to-calendar-button`**.
6464
3. Import the module into your project/component. For example with Angular/React: `import { atcb_init } from 'add-to-calendar-button';`.
6565
4. Init the js after the DOM has been loaded. To determine the right moment and execute, ...
66-
1. with Angular, you would use `ngAfterViewInit()` with `atcb_init();` (mind that, depending on your app, other hooks might be better);
67-
2. with React, you might want to include an event listener like `document.addEventListener('DOMContentLoaded', atcb_init, false);`.
66+
1. with Angular, you would use `ngAfterViewInit()` with `atcb_init();` (mind that, depending on your app, other hooks might be better);
67+
2. with React, you might want to include an event listener like `document.addEventListener('DOMContentLoaded', atcb_init, false);` or using hooks in a functional component like `useEffect(() => atcb_init());`
6868
5. Include the css. For example with Angular or React, add the following to the global style.css: `@import 'add-to-calendar-button/assets/css/atcb.min'`;
6969
6. Create your button as can be seen in the "Configuration" section below.
7070
7. That is it. The script takes care of all the rest. :)
71-
71+
7272

7373
## Configuration
7474

75-
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
75+
A button can be easily created by placing a respective placeholder, wherever you want the button to appear.
7676
(The `style="display:none;"` theoretically is not necessary, but should be used for better compatibility.)
7777
```html
7878
<div class="atcb" style="display:none;">
7979
(...)
8080
</div>
8181
```
82-
Within this placeholder, you can easily configure the button, by placing a respective JSON structure.
82+
Within this placeholder, you can easily configure the button, by placing a respective JSON structure.
8383
Mind that with Angular, you might need to escape the { with `{{ '{' }}` and } with `{{ '}' }}`; with React it would be `{ '{' }` and `{ '}' }`.
8484

8585
### Minimal structure (required)
@@ -160,7 +160,28 @@ You can use startTime and endTime in the event block, but it is recommended to r
160160
</script>
161161
</div>
162162
```
163-
163+
164+
### React example
165+
166+
A simpler method uses `JSON.stringify()` where you define your config in an external file or variable and then
167+
convert it to a string to be passed into the div.
168+
169+
```js
170+
const AddToCalendar = () => {
171+
172+
useEffect(() => atcb_init());
173+
174+
const event = { /* Event data */}
175+
176+
return (
177+
<div className='atcb'>
178+
<script type="application/ld+json">
179+
{JSON.stringify(event)}
180+
</script>
181+
</div>
182+
);
183+
}
184+
```
164185

165186
### Important information and hidden features
166187

@@ -181,7 +202,7 @@ You can use startTime and endTime in the event block, but it is recommended to r
181202
* If you want to define a specific name for any generated ics file (iCal), you can specify it via the "iCalFileName" option. The default would be "event-to-save-in-my-calendar".
182203
* You can use the option "inline":true in order to make the button appear with inline-block instead of block style.
183204
* If you require line breaks within the description, use `\n` or `<br>`.
184-
205+
185206

186207
## Contributing
187208

@@ -192,12 +213,12 @@ Anyone is welcome to contribute, but mind the [guidelines](.github/CONTRIBUTING.
192213
* [Pull requests](.github/CONTRIBUTING.md#pull-requests)
193214

194215
IMPORTANT NOTE: Run `npm install` and `npm run build` to create the minified js and css file, its sourcemap files as well as the npm_dist/ folder and content!
195-
216+
196217

197218
## License
198219

199220
The code is available under the [MIT license (with “Commons Clause” License Condition v1.0)](LICENSE.txt).
200-
221+
201222

202223
## Changelog (without bug fixes)
203224

@@ -206,7 +227,7 @@ The code is available under the [MIT license (with “Commons Clause” License
206227
* v1.2 : inline and line break support
207228
* v1.1 : npm functionality
208229
* v1.0 : initial release
209-
230+
210231

211232
## Kudos go to
212233
* [github.com/dudewheresmycode](https://github.com/dudewheresmycodee)

0 commit comments

Comments
 (0)