-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: bookmark can custom title
- Loading branch information
Showing
4 changed files
with
144 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from "react"; | ||
import Dialog, { type DialogProps } from "@mui/material/Dialog"; | ||
import useVirtualKeyboard from "y/hooks/useVirtualKeyboard"; | ||
import { makeStyles } from "y/utils/makesStyles"; | ||
|
||
const useStyles = makeStyles<{ | ||
isOpen: boolean; | ||
bottom: string; | ||
}>()((_, { isOpen, bottom }) => { | ||
if (isOpen) { | ||
return { | ||
container: { | ||
position: "relative", | ||
}, | ||
root: { | ||
position: "absolute", | ||
bottom, | ||
}, | ||
}; | ||
} else { | ||
return { | ||
container: {}, | ||
root: {}, | ||
}; | ||
} | ||
}); | ||
|
||
export default function DialogKb(props: DialogProps) { | ||
const { isSupported, isKeyboardOpen, boundingRect } = useVirtualKeyboard(); | ||
|
||
const { classes } = useStyles({ | ||
isOpen: isSupported && isKeyboardOpen, | ||
bottom: boundingRect?.height ? `${boundingRect.height}px` : "50vh", | ||
}); | ||
|
||
return ( | ||
<Dialog | ||
{...props} | ||
classes={{ | ||
container: classes.container, | ||
root: classes.root, | ||
}} | ||
/> | ||
); | ||
} |
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,46 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import DialogTitle from "@mui/material/DialogTitle"; | ||
import DialogContent from "@mui/material/DialogContent"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
import Button from "@mui/material/Button"; | ||
import Box from "@mui/material/Box"; | ||
import TextField from "@mui/material/TextField"; | ||
import DialogKb from "y/components/dialogKb"; | ||
|
||
type BookmarkTitleProps = { | ||
open: boolean; | ||
title: string; | ||
onCancel: () => void; | ||
onConfirm: (title: string) => void; | ||
}; | ||
|
||
export default function BookmarkTitle(props: BookmarkTitleProps) { | ||
const [title, setTitle] = useState(props.title); | ||
|
||
useEffect(() => { | ||
setTitle(props.title); | ||
}, [props.title]); | ||
|
||
return ( | ||
<DialogKb open={props.open} maxWidth="xs"> | ||
<DialogTitle>书签标题</DialogTitle> | ||
<DialogContent> | ||
<Box sx={{ pt: 1 }}> | ||
<TextField | ||
value={title} | ||
onInput={(e) => setTitle(e.target.value as string)} | ||
autoFocus | ||
label="请输入标题" | ||
fullWidth | ||
/> | ||
</Box> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={props.onCancel}>取消</Button> | ||
<Button color="primary" onClick={() => props.onConfirm(title)}> | ||
确定 | ||
</Button> | ||
</DialogActions> | ||
</DialogKb> | ||
); | ||
} |
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