import * as React from 'react'; import { useRef, forwardRef, useImperativeHandle, useCallback } from 'react'; const { themeStyle } = require('../theme.js'); const Mark = require('mark.js/dist/mark.min.js'); const markJsUtils = require('lib/markJsUtils'); const Note = require('lib/models/Note'); const { replaceRegexDiacritics, pregQuote } = require('lib/string-utils'); interface NoteListItemProps { theme: number, width: number, style: any, dragItemIndex: number, highlightedWords: string[], index: number, isProvisional: boolean, isSelected: boolean, isWatched: boolean item: any, itemCount: number, onCheckboxClick: any, onDragStart: any, onNoteDragOver: any, onNoteDrop: any, onTitleClick: any, } function NoteListItem(props:NoteListItemProps, ref:any) { const item = props.item; const theme = themeStyle(props.theme); const hPadding = 10; const anchorRef = useRef(null); useImperativeHandle(ref, () => { return { focus: function() { if (anchorRef.current) anchorRef.current.focus(); }, }; }); let rootStyle = Object.assign({ width: props.width, opacity: props.isProvisional ? 0.5 : 1 }, props.style.listItem); if (props.isSelected) rootStyle = Object.assign(rootStyle, props.style.listItemSelected); if (props.dragItemIndex === props.index) { rootStyle.borderTop = `2px solid ${theme.color}`; } else if (props.index === props.itemCount - 1 && props.dragItemIndex >= props.itemCount) { rootStyle.borderBottom = `2px solid ${theme.color}`; } const onTitleClick = useCallback((event) => { props.onTitleClick(event, props.item); }, [props.onTitleClick, props.item]); const onCheckboxClick = useCallback((event) => { props.onCheckboxClick(event, props.item); }, [props.onCheckboxClick, props.item]); // Setting marginBottom = 1 because it makes the checkbox looks more centered, at least on Windows // but don't know how it will look in other OSes. function renderCheckbox() { if (!item.is_todo) return null; return (