-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flat-components): add rename panel
- Loading branch information
Showing
12 changed files
with
208 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ponents/src/components/CloudStorage/CloudStorageFileTitle/CloudStorageFileTitleRename.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import checkSVG from "./icons/check.svg"; | ||
import crossSVG from "./icons/cross.svg"; | ||
|
||
import { Button, Input } from "antd"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
|
||
export interface CloudStorageFileTitleRenameProps { | ||
fileUUID: string; | ||
fileName: string; | ||
/** Rename file. Empty name for cancelling */ | ||
onRename?: (fileUUID: string, name: string) => void; | ||
} | ||
|
||
export const CloudStorageFileTitleRename = React.memo<CloudStorageFileTitleRenameProps>( | ||
function CloudStorageFileTitleRename({ fileUUID, fileName, onRename }) { | ||
// Antd docs uses any | ||
const inputRef = useRef<any>(); | ||
const [oldName, ext] = splitFileName(fileName); | ||
const [newName, setText] = useState(oldName); | ||
|
||
const onCancel = onRename && (() => onRename(fileUUID, "")); | ||
const onConfirm = | ||
onRename && | ||
(() => { | ||
const newFileName = newName + ext; | ||
onRename(fileUUID, newFileName === fileName ? "" : newFileName); | ||
}); | ||
|
||
useEffect(() => { | ||
const input: Input = inputRef.current; | ||
if (input) { | ||
input.focus(); | ||
input.select(); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Input | ||
ref={inputRef} | ||
size="small" | ||
className="cloud-storage-file-title-rename-input" | ||
value={newName} | ||
onChange={e => setText(e.currentTarget.value)} | ||
onPressEnter={onConfirm} | ||
/> | ||
<Button | ||
type="text" | ||
shape="circle" | ||
size="small" | ||
className="cloud-storage-file-title-rename-btn" | ||
onClick={onConfirm} | ||
> | ||
<img src={checkSVG} width={22} height={22} alt="confirm" /> | ||
</Button> | ||
<Button | ||
type="text" | ||
shape="circle" | ||
size="small" | ||
className="cloud-storage-file-title-rename-btn" | ||
onClick={onCancel} | ||
> | ||
<img src={crossSVG} width={22} height={22} alt="cancel" /> | ||
</Button> | ||
</> | ||
); | ||
}, | ||
); | ||
|
||
/** split filename to name and extension */ | ||
function splitFileName(fileName: string): [string, string] { | ||
const dotIndex = fileName.lastIndexOf("."); | ||
return [fileName.substr(0, dotIndex), fileName.slice(dotIndex)]; | ||
} |
15 changes: 15 additions & 0 deletions
15
...at-components/src/components/CloudStorage/CloudStorageFileTitle/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
...at-components/src/components/CloudStorage/CloudStorageFileTitle/icons/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters