
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
draft-js-checkable-list-item
Advanced tools
Checkable list item for Draft.js
npm i draft-js-checkable-list-item
Example
import React, { Component } from 'react'
import { Editor, EditorState, RichUtils, DefaultDraftBlockRenderMap } from 'draft-js'
import {
blockRenderMap, CheckableListItem, CheckableListItemBlock, CheckableListItemUtils, CHECKABLE_LIST_ITEM
} from 'draft-js-checkable-list-item'
import 'draft-js/dist/Draft.css'
import 'draft-js-checkable-list-item/lib/CheckableListItem.css'
import type ContentBlock from 'draft-js/lib/ContentBlock'
export default class App extends Component {
editor: Editor
state: { editorState: EditorState }
blockRendererFn = (block: ContentBlock): ?CheckableListItemBlock => {
if (block.getType() === CHECKABLE_LIST_ITEM) {
return {
component: CheckableListItem,
props: {
onChangeChecked: () => this.changeEditorState(
CheckableListItemUtils.toggleChecked(this.state.editorState, block)
),
checked: !!block.getData().get('checked'),
},
}
}
}
handleTab = (ev: SyntheticKeyboardEvent): ?boolean => {
if (this.adjustBlockDepth(ev)) {
return true
}
const { editorState } = this.state
const newEditorState = RichUtils.onTab(ev, editorState, 4)
if (newEditorState !== editorState) {
this.changeEditorState(newEditorState)
}
}
changeEditorState = (editorState: EditorState): void => this.setState({ editorState })
state = { editorState: EditorState.createEmpty() }
render() {
return (
<div>
<div>
<span onMouseDown={this.createMouseDownHandler(CHECKABLE_LIST_ITEM)}>✔</span>
</div>
<Editor
blockRendererFn={this.blockRendererFn}
blockRenderMap={DefaultDraftBlockRenderMap.merge(blockRenderMap)}
blockStyleFn={this.blockStyleFn}
editorState={this.state.editorState}
onChange={this.changeEditorState}
onTab={this.handleTab}
/>
</div>
)
}
createMouseDownHandler(type: string): Function {
return (ev: SyntheticEvent) => {
ev.preventDefault()
this.changeEditorState(RichUtils.toggleBlockType(this.state.editorState, type))
}
}
blockStyleFn(block: ContentBlock): ?string {
if (block.getType() === CHECKABLE_LIST_ITEM) {
return CHECKABLE_LIST_ITEM
}
}
adjustBlockDepth(ev: SyntheticKeyboardEvent): boolean {
const { editorState } = this.state
const newEditorState = CheckableListItemUtils.onTab(ev, editorState, 4)
if (newEditorState !== editorState) {
this.changeEditorState(newEditorState)
return true
}
return false
}
}
© sugarshin
FAQs
Checkable list item for Draft.js
The npm package draft-js-checkable-list-item receives a total of 1,611 weekly downloads. As such, draft-js-checkable-list-item popularity was classified as popular.
We found that draft-js-checkable-list-item demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.