Skip to content

Commit

Permalink
feat(tag blot): add tag blot
Browse files Browse the repository at this point in the history
  • Loading branch information
mayyyc committed Aug 22, 2020
1 parent fda0267 commit 13b8156
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/blots/Tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Quill } from 'react-quill'

const Embed = Quill.import('blots/embed')

interface TagParams {
displayName: string
id: string
}

class Tag extends Embed {
static create(value: TagParams) {
const node = super.create(value) as HTMLElement

node.setAttribute('href', `/tags/${value.id}`)
node.setAttribute('target', '_blank')
node.dataset.displayName = value.displayName
node.dataset.id = value.id
node.textContent = `#${value.displayName}`

return node
}

static value(domNode: HTMLElement) {
return domNode.dataset
}
}

Tag.blotName = 'tag'
Tag.tagName = 'a'
Tag.className = 'tag'

Quill.register('formats/tag', Tag)

export default Tag

0 comments on commit 13b8156

Please sign in to comment.