Download web/src/home/FolderNameDialog.tsx from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/home/FolderNameDialog.tsx
- Command line
-
hf download hf://spaces/fsanyoto/loopable/web/src/home/FolderNameDialog.tsx
-
curl -L -o FolderNameDialog.tsx https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/home/FolderNameDialog.tsx
2.27 kB
| import { useEffect, useState } from "react"; | |
| import { AnchoredOverlay } from "../customer-grid/OverlaySurface"; | |
| export const FOLDER_NAME_MAX = 40; | |
| interface FolderNameDialogProps { | |
| anchor: HTMLElement | null; | |
| title: string; | |
| initialName?: string; | |
| siblingNames: readonly string[]; | |
| onSubmit(name: string): void; | |
| onDismiss(): void; | |
| disabled?: boolean; | |
| disabledReason?: string; | |
| } | |
| export default function FolderNameDialog({ | |
| anchor, title, initialName = "", siblingNames, onSubmit, onDismiss, | |
| disabled = false, disabledReason, | |
| }: FolderNameDialogProps) { | |
| const [name, setName] = useState(() => initialName.slice(0, FOLDER_NAME_MAX)); | |
| // autoFocus can precede the overlay's opener capture. Restore the supplied trigger | |
| // after removal too, when the captured input is no longer connected. | |
| useEffect(() => () => { | |
| if (anchor?.isConnected) anchor.focus({ preventScroll: true }); | |
| }, [anchor]); | |
| const clean = name.trim(); | |
| const duplicate = siblingNames.some((sibling) => sibling.trim().toLowerCase() === clean.toLowerCase()); | |
| const disabledStyle = disabled ? { opacity: 0.45, cursor: "not-allowed" } : undefined; | |
| return ( | |
| <AnchoredOverlay | |
| anchor={anchor} | |
| className="cg-view-menu" | |
| role="dialog" | |
| ariaLabel={title} | |
| placement="right-start" | |
| onDismiss={onDismiss} | |
| > | |
| <form className="cg-data-folder-rename" onSubmit={(event) => { | |
| event.preventDefault(); | |
| if (disabled || !clean || duplicate) return; | |
| onSubmit(clean); | |
| }}> | |
| <input | |
| className="cg-input" | |
| autoFocus | |
| aria-label="Folder name" | |
| maxLength={FOLDER_NAME_MAX} | |
| value={name} | |
| disabled={disabled} | |
| title={disabledReason} | |
| style={disabledStyle} | |
| aria-invalid={duplicate || undefined} | |
| onChange={(event) => setName(event.currentTarget.value.slice(0, FOLDER_NAME_MAX))} | |
| /> | |
| {duplicate ? <p role="alert">That folder name is already taken. Pick another one.</p> : null} | |
| <button type="submit" className="cg-btn cg-btn--primary" | |
| disabled={disabled || !clean} title={disabledReason} style={disabledStyle}> | |
| Save | |
| </button> | |
| </form> | |
| </AnchoredOverlay> | |
| ); | |
| } | |