Download web/src/customer-grid/CellNoteMenu.tsx from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 3.67 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/customer-grid/CellNoteMenu.tsx
- Command line
-
hf download hf://spaces/fsanyoto/loopable/web/src/customer-grid/CellNoteMenu.tsx
-
curl -L -o CellNoteMenu.tsx https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/customer-grid/CellNoteMenu.tsx
3.67 kB
| import { useState } from "react"; | |
| import type { ComponentProps, KeyboardEvent } from "react"; | |
| import { AnchoredOverlay } from "./OverlaySurface"; | |
| import { isDerivedLink, isMachineWritten, mayOverrideSourceValue } from "./types"; | |
| import type { Field } from "./types"; | |
| import "../styles/sdlc80/cell-note.css"; | |
| /** A pre-set definition lock never decides whether a cell can carry a note. */ | |
| export function cellNoteRefusal(field: Field, editable: boolean, embedded: boolean): string | undefined { | |
| if (embedded) return "This table is view only."; | |
| if (editable) return undefined; | |
| if (field.source !== "overlay" && !mayOverrideSourceValue(field)) return "This source field is read only."; | |
| if (["formula", "created_time", "rollup"].includes(field.type) || isDerivedLink(field)) | |
| return "This calculated cell is read only."; | |
| if (isMachineWritten(field)) return "This cell is filled by an automation."; | |
| return "Your access does not allow editing this field."; | |
| } | |
| export function drawCellNoteMarker(ctx: CanvasRenderingContext2D, | |
| rect: { x: number; y: number; width: number }, color: string): void { | |
| ctx.save(); | |
| ctx.fillStyle = color; | |
| ctx.beginPath(); | |
| ctx.moveTo(rect.x + rect.width - 9, rect.y + 2); | |
| ctx.lineTo(rect.x + rect.width - 2, rect.y + 2); | |
| ctx.lineTo(rect.x + rect.width - 2, rect.y + 9); | |
| ctx.closePath(); | |
| ctx.fill(); | |
| ctx.restore(); | |
| } | |
| export default function CellNoteMenu({ anchor, note, refusal, onSave, onClose }: { | |
| anchor: ComponentProps<typeof AnchoredOverlay>["anchor"]; | |
| note: string | null; | |
| refusal?: string; | |
| onSave: (text: string | null) => void; | |
| onClose: () => void; | |
| }) { | |
| const [editing, setEditing] = useState(false); | |
| const [draft, setDraft] = useState(note ?? ""); | |
| const label = note ? "Edit note" : "Add note"; | |
| const walk = (event: KeyboardEvent<HTMLElement>) => { | |
| if (editing || !["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return; | |
| const buttons = [...event.currentTarget.querySelectorAll<HTMLButtonElement>("[role=menuitem]:not(:disabled)")]; | |
| const at = buttons.indexOf(document.activeElement as HTMLButtonElement); | |
| const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 | |
| : event.key === "ArrowDown" ? at + 1 : at < 0 ? buttons.length - 1 : at - 1; | |
| event.preventDefault(); | |
| buttons[(next + buttons.length) % buttons.length]?.focus(); | |
| }; | |
| return <AnchoredOverlay anchor={anchor} className="cg-pop cg-cell-note-pop" placement="bottom-start" | |
| role={editing ? "dialog" : "menu"} ariaLabel={editing ? label : "Cell note"} | |
| dismissOnOutside={!editing} onDismiss={onClose} onKeyDown={walk}> | |
| {editing ? <form className="cg-cell-note-editor" onSubmit={(event) => { | |
| event.preventDefault(); | |
| if (!refusal) onSave(draft.trim() || null); | |
| }}> | |
| <label>{label}<textarea rows={4} aria-label="Cell note" autoFocus value={draft} disabled={!!refusal} | |
| onChange={(event) => setDraft(event.currentTarget.value)} /></label> | |
| <div className="cg-cell-note-actions"> | |
| <button type="submit" disabled={!!refusal || (!note && !draft.trim())}>Save</button> | |
| <button type="button" onClick={onClose}>Cancel</button> | |
| </div> | |
| </form> : <> | |
| <button type="button" role="menuitem" className="cg-cell-note-item" disabled={!!refusal} | |
| title={refusal} onClick={() => setEditing(true)}>{label}</button> | |
| {note && <button type="button" role="menuitem" className="cg-cell-note-item" disabled={!!refusal} | |
| title={refusal} onClick={() => onSave(null)}>Delete note</button>} | |
| </>} | |
| {refusal && <p className="cg-cell-note-refusal" role="status">{refusal}</p>} | |
| </AnchoredOverlay>; | |
| } | |