MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / Cell

Function Cell

packages/app-core/src/components/DatabaseTableView.tsx:749–807  ·  view source on GitHub ↗
({ field, value, editing, onStartEdit, onEndEdit, onCommit }: CellProps)

Source from the content-addressed store, hash-verified

747}
748
749function Cell({ field, value, editing, onStartEdit, onEndEdit, onCommit }: CellProps): JSX.Element {
750 if (field.type === 'checkbox') {
751 const checked = isCheckboxTrue(value)
752 return (
753 <button
754 type="button"
755 onClick={() => onCommit(checked ? 'false' : 'true')}
756 className="flex h-full w-full items-center justify-center px-2 py-1.5"
757 title={checked ? 'Checked' : 'Unchecked'}
758 >
759 <span
760 className={[
761 'flex h-4 w-4 items-center justify-center rounded border',
762 checked ? 'border-accent bg-accent text-white' : 'border-paper-400 text-transparent'
763 ].join(' ')}
764 >
765
766 </span>
767 </button>
768 )
769 }
770
771 if (field.type === 'select' || field.type === 'multiSelect') {
772 return (
773 <SelectCell field={field} value={value} editing={editing} onStartEdit={onStartEdit} onEndEdit={onEndEdit} onCommit={onCommit} />
774 )
775 }
776
777 if (editing) {
778 return (
779 <input
780 autoFocus
781 type={field.type === 'number' ? 'number' : field.type === 'date' ? 'date' : 'text'}
782 defaultValue={value}
783 onFocus={(e) => e.currentTarget.select()}
784 onBlur={(e) => {
785 onCommit(e.currentTarget.value)
786 onEndEdit()
787 }}
788 onKeyDown={(e) => {
789 e.stopPropagation()
790 if (e.key === 'Enter' && !isImeComposing(e)) e.currentTarget.blur()
791 else if (e.key === 'Escape') onEndEdit()
792 }}
793 className="w-full bg-paper-50 px-2 py-1.5 text-sm text-ink-900 outline-none ring-1 ring-inset ring-accent"
794 />
795 )
796 }
797
798 return (
799 <button type="button" onClick={onStartEdit} className="block h-full w-full px-2 py-1.5 text-left">
800 {/* min-h reserves one line so an empty cell keeps the same row height as a
801 filled one (otherwise a new/blank row collapses shorter). (#185) */}
802 <span className="block min-h-5 truncate text-ink-900">
803 {field.type === 'date' ? formatDate(value) : value}
804 </span>
805 </button>
806 )

Callers

nothing calls this directly

Calls 3

isImeComposingFunction · 0.90
formatDateFunction · 0.90
isCheckboxTrueFunction · 0.85

Tested by

no test coverage detected