Skip to content

Commit 162d729

Browse files
committed
feat: defaultOptions
1 parent d617d32 commit 162d729

File tree

6 files changed

+96
-19
lines changed

6 files changed

+96
-19
lines changed

README.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88

99
A Vue wrapper for [RoughNotation](https://roughnotation.com/), a small JavaScript library to create and animate annotations on a web page.
1010

11-
[Visit website to see it in action](https://roughnotation.com/)
11+
- [Visit website to see it in action](https://roughnotation.com/)
12+
- [Rough Notation Github](https://github.com/pshihn/rough-notation)
13+
14+
## Table of Contents
15+
16+
- [Installation](#installation)
17+
- [Usage](#usage)
18+
- [Global options](#global-options)
19+
- [Props](#props)
20+
- [Events](#events)
21+
- [TODO](#todo)
22+
- [License](#license)
1223

1324
## Installation
1425

@@ -45,6 +56,35 @@ template:
4556
</RoughNotation>
4657
```
4758

59+
## Global options
60+
61+
The default global options are:
62+
63+
```js
64+
{
65+
// Turn on/off animation when annotating.
66+
animate: true,
67+
// Duration of the animation in milliseconds.
68+
animationDuration: 800,
69+
// Delay in animation in milliseconds.
70+
animationDelay: 0,
71+
// Representing the color of the annotation sketch.
72+
color: 'currentColor',
73+
// Width of the annotation strokes.
74+
strokeWidth: 1,
75+
// (in pixels) Padding between the element and roughly where the annotation is drawn.
76+
padding: 5,
77+
}
78+
```
79+
80+
You can change the options when install:
81+
82+
```js
83+
import VueRoughNotation from 'vue-rough-notation';
84+
85+
Vue.use(VueRoughNotation, options);
86+
```
87+
4888
## Props
4989

5090
### type
@@ -78,7 +118,7 @@ Whether draws the annotation.
78118

79119
**Required**: `false`
80120

81-
**Default**: `true`
121+
**Default**: `true` - You can change it when install _(see above)_.
82122

83123
Turn on/off animation when annotating.
84124

@@ -88,7 +128,7 @@ Turn on/off animation when annotating.
88128

89129
**Required**: `false`
90130

91-
**Default**: `800`
131+
**Default**: `800` - You can change it when install _(see above)_.
92132

93133
Duration of the animation in milliseconds.
94134

@@ -98,7 +138,7 @@ Duration of the animation in milliseconds.
98138

99139
**Required**: `false`
100140

101-
**Default**: `0`
141+
**Default**: `0` - You can change it when install _(see above)_.
102142

103143
Delay in animation in milliseconds.
104144

@@ -108,7 +148,7 @@ Delay in animation in milliseconds.
108148

109149
**Required**: `false`
110150

111-
**Default**: `currentColor`
151+
**Default**: `currentColor` - You can change it when install _(see above)_.
112152

113153
Representing the color of the annotation sketch.
114154

@@ -118,7 +158,7 @@ Representing the color of the annotation sketch.
118158

119159
**Required**: `false`
120160

121-
**Default**: `1`
161+
**Default**: `1` - You can change it when install _(see above)_.
122162

123163
Width of the annotation strokes.
124164

@@ -128,7 +168,7 @@ Width of the annotation strokes.
128168

129169
**Required**: `false`
130170

131-
**Default**: `5`(in pixels)
171+
**Default**: `5`(in pixels) - You can change it when install _(see above)_
132172

133173
Padding between the element and roughly where the annotation is drawn.
134174

src/component.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const AVAILABLE_TYPES = [
99
'crossed-off',
1010
];
1111

12-
export default {
12+
export default (options) => ({
1313
name: 'RoughNotation',
1414

1515
props: {
@@ -33,32 +33,32 @@ export default {
3333

3434
animate: {
3535
type: Boolean,
36-
default: true,
36+
default: () => options.animate,
3737
},
3838

3939
animationDuration: {
4040
type: Number,
41-
default: 800,
41+
default: () => options.animationDuration,
4242
},
4343

4444
animationDelay: {
4545
type: Number,
46-
default: 0,
46+
default: () => options.animationDelay,
4747
},
4848

4949
color: {
5050
type: String,
51-
default: 'currentColor',
51+
default: () => options.color,
5252
},
5353

5454
strokeWidth: {
5555
type: Number,
56-
default: 1,
56+
default: () => options.strokeWidth,
5757
},
5858

5959
padding: {
6060
type: Number,
61-
default: 5,
61+
default: () => options.padding,
6262
},
6363
},
6464

@@ -111,4 +111,4 @@ export default {
111111

112112
return slot && slot[0];
113113
},
114-
};
114+
});

src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
import { defaultOptions } from './options';
12
import RoughNotation from './component';
23

34
const VueRoughNotationPlugin = {
45
/**
56
* install function
67
* @param {Vue} Vue
78
*/
8-
install (Vue) {
9-
Vue.component('rough-notation', RoughNotation);
10-
Vue.component('RoughNotation', RoughNotation);
9+
install (Vue, options = {}) {
10+
const finalOptions = {
11+
...defaultOptions,
12+
...options,
13+
};
14+
15+
const RoughNotationComponent = RoughNotation(finalOptions);
16+
17+
Vue.component('rough-notation', RoughNotationComponent);
18+
Vue.component('RoughNotation', RoughNotationComponent);
1119
},
1220
};
1321

src/options.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const defaultOptions = {
2+
// Turn on/off animation when annotating.
3+
animate: true,
4+
// Duration of the animation in milliseconds.
5+
animationDuration: 800,
6+
// Delay in animation in milliseconds.
7+
animationDelay: 0,
8+
// Representing the color of the annotation sketch.
9+
color: 'currentColor',
10+
// Width of the annotation strokes.
11+
strokeWidth: 1,
12+
// Padding between the element and roughly where the annotation is drawn.
13+
padding: 5,
14+
};

types/VueRoughNotation.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
import { PluginObject } from "vue";
22

3-
export interface VueRoughNotationPluginObject extends PluginObject<any> {};
3+
export type RoughNotationTypes = 'underline' | 'box' | 'circle' | 'highlight' | 'strike-through' | 'crossed-off';
4+
5+
export interface VueRoughNotationOptions {
6+
animate?: boolean;
7+
animationDelay?: number;
8+
color?: string;
9+
strokeWidth?: number;
10+
padding?: number
11+
};
12+
13+
export interface VueRoughNotationPluginObject extends PluginObject<VueRoughNotationOptions> {};

types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ import { VueRoughNotationPluginObject } from './VueRoughNotation';
22

33
declare var VueRoughNotation: VueRoughNotationPluginObject;
44
export default VueRoughNotation;
5+
6+
export {
7+
RoughNotationTypes,
8+
VueRoughNotationOptions,
9+
} from './VueRoughNotation';

0 commit comments

Comments
 (0)