feat: add animation to ProfileNew component (#252)

* chore: add .vscode to .gitignore

* feat: add animation to ProfileNew component
This commit is contained in:
angrylid 2022-10-29 20:02:51 +08:00 committed by GitHub
parent 9e56b9fbb5
commit a45dc6efda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 79 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ dist-ssr
*.local *.local
update.json update.json
scripts/_env.sh scripts/_env.sh
.vscode

View File

@ -21,6 +21,7 @@ import { Settings } from "@mui/icons-material";
import { createProfile } from "@/services/cmds"; import { createProfile } from "@/services/cmds";
import Notice from "../base/base-notice"; import Notice from "../base/base-notice";
import FileInput from "./file-input"; import FileInput from "./file-input";
import { Smoother } from "./smoother";
interface Props { interface Props {
open: boolean; open: boolean;
@ -93,6 +94,7 @@ const ProfileNew = (props: Props) => {
<DialogTitle sx={{ pb: 0.5 }}>{t("Create Profile")}</DialogTitle> <DialogTitle sx={{ pb: 0.5 }}>{t("Create Profile")}</DialogTitle>
<DialogContent sx={{ width: 336, pb: 1 }}> <DialogContent sx={{ width: 336, pb: 1 }}>
<Smoother>
<FormControl size="small" fullWidth sx={{ mt: 2, mb: 1 }}> <FormControl size="small" fullWidth sx={{ mt: 2, mb: 1 }}>
<InputLabel>Type</InputLabel> <InputLabel>Type</InputLabel>
<Select <Select
@ -138,7 +140,8 @@ const ProfileNew = (props: Props) => {
<FileInput onChange={(val) => (fileDataRef.current = val)} /> <FileInput onChange={(val) => (fileDataRef.current = val)} />
)} )}
{showOpt && ( {form.type === "remote" && showOpt && (
<>
<TextField <TextField
{...textFieldProps} {...textFieldProps}
label="User Agent" label="User Agent"
@ -146,9 +149,6 @@ const ProfileNew = (props: Props) => {
value={option.user_agent} value={option.user_agent}
onChange={(e) => setOption({ user_agent: e.target.value })} onChange={(e) => setOption({ user_agent: e.target.value })}
/> />
)}
{form.type === "remote" && showOpt && (
<FormControlLabel <FormControlLabel
label={t("Use System Proxy")} label={t("Use System Proxy")}
labelPlacement="start" labelPlacement="start"
@ -166,9 +166,6 @@ const ProfileNew = (props: Props) => {
/> />
} }
/> />
)}
{form.type === "remote" && showOpt && (
<FormControlLabel <FormControlLabel
label={t("Use Clash Proxy")} label={t("Use Clash Proxy")}
labelPlacement="start" labelPlacement="start"
@ -186,7 +183,9 @@ const ProfileNew = (props: Props) => {
/> />
} }
/> />
</>
)} )}
</Smoother>
</DialogContent> </DialogContent>
<DialogActions sx={{ px: 2, pb: 2, position: "relative" }}> <DialogActions sx={{ px: 2, pb: 2, position: "relative" }}>

View File

@ -0,0 +1,30 @@
import { useEffect, useRef } from "react";
export const Smoother: React.FC = ({ children }) => {
const self = useRef<HTMLDivElement>(null);
useEffect(() => {
if (typeof window.getComputedStyle == "undefined") return;
const element = self.current;
if (!element) return;
var height = window.getComputedStyle(element).height;
element.style.transition = "none";
element.style.height = "auto";
var targetHeight = window.getComputedStyle(element).height;
element.style.height = height;
setTimeout(() => {
element.style.transition = "height .5s";
element.style.height = targetHeight;
}, 0);
});
return (
<div
ref={self}
style={{
overflowY: "hidden",
}}
>
{children}
</div>
);
};