Skip to content

Commit

Permalink
text flag customization
Browse files Browse the repository at this point in the history
adding color, add it to docs
  • Loading branch information
Proxy-99 committed Mar 21, 2023
1 parent 6ee6cc9 commit 525bc63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ You can change the emoji in `emojiCursor`'s emoji with the `emoji` option (a lis
new cursoreffects.emojiCursor({ emoji: ["🔥", "🐬", "🦆"] });
```

### textFlag

You can change the `textFlag`'s text with the `text` option (String),
and color of the text with the `color` (an array)

```js
new textFlag({element: targetElement, text: "test",color:["#FF6800"]});
```

## Accessibility

The cursor won't display if the user's system accessibility settings have [prefers-reduced-motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) enabled.
Expand Down
3 changes: 3 additions & 0 deletions src/textFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function textFlag(options) {
let element = hasWrapperEl || document.body;

let text = cursorOptions.text ? " " + options.text : " Your Text Here";
let color = options?.color || "#000000";


let font = cursorOptions.font || "monospace";
let textSize = cursorOptions.textSize || 12;
Expand Down Expand Up @@ -119,6 +121,7 @@ export function textFlag(options) {
charArray[i].x = charArray[i - 1].x + gap;
charArray[i].y = charArray[i - 1].y;

context.fillStyle = color;
context.font = fontFamily;
context.fillText(charArray[i].letter, charArray[i].x, charArray[i].y);
}
Expand Down

0 comments on commit 525bc63

Please sign in to comment.