diff --git a/README.md b/README.md index 05c8f22..bd41ae1 100755 --- a/README.md +++ b/README.md @@ -104,7 +104,9 @@ Vue.use(VueCompositionAPI); [![Demo](https://img.shields.io/badge/demo-🚀-yellow.svg)](https://microcipcip.github.io/vue-use-kit/?path=/story/animations-usetimeoutfn--demo) - Side Effects - [`useBeforeUnload`](./src/components/useBeforeUnload/stories/useBeforeUnload.md) — shows browser alert when user try to reload or close the page. - [![Demo](https://img.shields.io/badge/demo-🚀-yellow.svg)](https://microcipcip.github.io/vue-use-kit/?path=/story/ui-usebeforeunload--demo) + [![Demo](https://img.shields.io/badge/demo-🚀-yellow.svg)](https://microcipcip.github.io/vue-use-kit/?path=/story/side-effects-usebeforeunload--demo) + - [`useCookie`](./src/components/useCookie/stories/useCookie.md) — provides way to read, update and delete a cookie. + [![Demo](https://img.shields.io/badge/demo-🚀-yellow.svg)](https://microcipcip.github.io/vue-use-kit/?path=/story/side-effects-usecookie--demo) - UI - [`useClickAway`](./src/components/useClickAway/stories/useClickAway.md) — triggers callback when user clicks outside target area. [![Demo](https://img.shields.io/badge/demo-🚀-yellow.svg)](https://microcipcip.github.io/vue-use-kit/?path=/story/ui-useclickaway--demo) diff --git a/package-lock.json b/package-lock.json index 6735421..984c754 100755 --- a/package-lock.json +++ b/package-lock.json @@ -3690,6 +3690,11 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/cookie": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.3.tgz", + "integrity": "sha512-LKVP3cgXBT9RYj+t+9FDKwS5tdI+rPBXaNSkma7hvqy35lc7mAokC2zsqWJH0LaqIt3B962nuYI77hsJoT1gow==" + }, "@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", @@ -6658,8 +6663,7 @@ "cookie": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", - "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==", - "dev": true + "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" }, "cookie-signature": { "version": "1.0.6", @@ -6667,6 +6671,15 @@ "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=", "dev": true }, + "cookie-universal": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/cookie-universal/-/cookie-universal-2.1.1.tgz", + "integrity": "sha512-WolLEtABR5E6NLIgpgP0LT53C85iJmxqTF3YAx4tCIWl0mkwivzjQaVbXDQbUxKz4HRwiYLW1D8vh1SJIAkl8A==", + "requires": { + "@types/cookie": "^0.3.3", + "cookie": "^0.4.0" + } + }, "copy-concurrently": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz", diff --git a/package.json b/package.json index 3d69244..3d2955d 100755 --- a/package.json +++ b/package.json @@ -138,6 +138,7 @@ "vue-template-compiler": "^2.6.11" }, "dependencies": { + "cookie-universal": "^2.1.1", "throttle-debounce": "^2.1.0" } } diff --git a/src/api.ts b/src/api.ts new file mode 100755 index 0000000..9787866 --- /dev/null +++ b/src/api.ts @@ -0,0 +1,2 @@ +export * from '@vue/composition-api' +export { default } from '@vue/composition-api' diff --git a/src/components/useBeforeUnload/stories/UseBeforeUnloadDemo.vue b/src/components/useBeforeUnload/stories/UseBeforeUnloadDemo.vue index ada7bbe..7ce2394 100755 --- a/src/components/useBeforeUnload/stories/UseBeforeUnloadDemo.vue +++ b/src/components/useBeforeUnload/stories/UseBeforeUnloadDemo.vue @@ -31,7 +31,7 @@ diff --git a/src/components/useCookie/stories/useCookie.md b/src/components/useCookie/stories/useCookie.md new file mode 100755 index 0000000..86ec705 --- /dev/null +++ b/src/components/useCookie/stories/useCookie.md @@ -0,0 +1,68 @@ +# useCookie + +Vue function that provides way to read, set and remove a cookie. + +## Reference + +```typescript +function useCookie( + cookieName: string, + enableParseJSON?: boolean, + runOnMount?: boolean +): { + cookie: Ref + getCookie: () => void + setCookie: (newVal: any, options?: CookieSerializeOptions | undefined) => void + removeCookie: (options?: CookieSerializeOptions | undefined) => void +} +``` + +### Parameters + +- `cookieName: string` the cookie name you wish to get/set/remove +- `enableParseJSON: boolean` whether to enable JSON parsing or not, `false` by default +- `runOnMount: boolean` whether to get the cookie on mount or not, `true` by default + +### Returns + +- `cookie: Ref` the cookie value, it can be null, a string or a JSON object/array +- `getCookie: Function` get the cookie value +- `setCookie: Function` set the cookie value + - `newVal: any`: the value to set, can be a string or an object/array + - `options?: CookieSerializeOptions`: a [cookie](https://github.com/jshttp/cookie#options-1) options object +- `removeCookie: Function` delete the cookie + - `options?: CookieSerializeOptions`: a [cookie](https://github.com/jshttp/cookie#options-1) options object + +## Usage + +```html + + +