Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update(EditAlbumDetailsDialog):update-styles

Aswin Asok6b389d4d1cb7
diff --git a/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx b/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx
index 3a4962a2d8..584966e00e 100644
--- a/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx
+++ b/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx
@@ -1,13 +1,18 @@
+import CloseIcon from "@mui/icons-material/Close";
import {
+ Box,
Dialog,
- DialogContent,
- DialogTitle,
+ IconButton,
+ InputBase,
Stack,
- TextField,
+ styled,
+ SvgIcon,
Typography,
+ type SvgIconProps,
+ type SxProps,
+ type Theme,
} from "@mui/material";
import type { LocalUser } from "ente-accounts-rs/services/user";
-import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import {
useModalVisibility,
@@ -20,7 +25,8 @@ import {
} from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
-import { ItemCard, PreviewItemTile } from "ente-new/photos/components/Tiles";
+import { ItemCard } from "ente-new/photos/components/Tiles";
+import { FocusVisibleUnstyledButton } from "ente-new/photos/components/UnstyledButton";
import { albumDescriptionGraphemeCount } from "ente-new/photos/services/collection";
import { useFormik } from "formik";
import { t } from "i18next";
@@ -53,6 +59,8 @@ export const EditAlbumDetailsDialog: React.FC<EditAlbumDetailsDialogProps> = ({
}) => {
const { showMiniDialog, onGenericError } = useBaseContext();
const titleID = useId();
+ const nameID = useId();
+ const descriptionID = useId();
const { show: showPickCoverPhoto, props: pickCoverPhotoVisibilityProps } =
useModalVisibility();
const [pendingCoverID, setPendingCoverID] = useState<number>();
@@ -141,83 +149,120 @@ export const EditAlbumDetailsDialog: React.FC<EditAlbumDetailsDialogProps> = ({
pickCoverPhotoVisibilityProps.open ? undefined : handleClose
}
aria-labelledby={titleID}
- maxWidth="xs"
- fullWidth
- slotProps={{ paper: { sx: { p: "8px 4px 4px 4px" } } }}
+ maxWidth={false}
+ slotProps={{ paper: { sx: paperSx } }}
>
- <DialogTitle id={titleID}>{t("edit_details")}</DialogTitle>
- <DialogContent sx={{ "&&&": { pt: 0 } }}>
- <Stack component="form" onSubmit={formik.handleSubmit}>
- {canShowCoverEditor && (
- <Stack
- direction="row"
- sx={{ alignItems: "center", gap: 2, mt: 2 }}
- >
- <ItemCard
- key={effectiveCoverFile?.id}
- TileComponent={PreviewItemTile}
- coverFile={effectiveCoverFile}
- />
- <Typography sx={{ flex: 1, minWidth: 0 }}>
- {t("album_cover")}
- </Typography>
- <FocusVisibleButton
+ <Stack
+ component="form"
+ onSubmit={formik.handleSubmit}
+ sx={{ p: "20px", gap: "36px" }}
+ >
+ <Stack direction="row" sx={headerSx}>
+ <Typography id={titleID} sx={titleSx}>
+ {t("edit_details")}
+ </Typography>
+ <IconButton
+ aria-label={t("close")}
+ disabled={formik.isSubmitting}
+ onClick={handleClose}
+ sx={headerButtonSx}
+ >
+ <CloseIcon sx={{ fontSize: 18 }} />
+ </IconButton>
+ </Stack>
+ <Stack sx={{ gap: "16px" }}>
+ <Stack direction="row" sx={nameRowSx}>
+ {canShowCoverEditor && (
+ <FocusVisibleUnstyledButton
type="button"
- color="secondary"
+ aria-label={t("set_cover")}
disabled={formik.isSubmitting}
onClick={showPickCoverPhoto}
+ sx={coverButtonSx}
>
- {t("set_cover")}
- </FocusVisibleButton>
+ <ItemCard
+ key={effectiveCoverFile?.id}
+ TileComponent={CoverTile}
+ coverFile={effectiveCoverFile}
+ />
+ <Box sx={coverBadgeSx}>
+ <PencilEditIcon
+ sx={{ fontSize: 12 }}
+ aria-hidden
+ />
+ </Box>
+ </FocusVisibleUnstyledButton>
+ )}
+ <Stack sx={fieldSx}>
+ <Typography
+ component="label"
+ htmlFor={nameID}
+ sx={labelSx}
+ >
+ {t("album_name")}
+ </Typography>
+ <InputBase
+ id={nameID}
+ name="name"
+ value={formik.values.name}
+ onChange={formik.handleChange}
+ autoFocus
+ fullWidth
+ disabled={formik.isSubmitting}
+ error={!trimmedName}
+ sx={inputSx}
+ />
+ {/* The empty string reserves the helper height. */}
+ <Typography sx={helperSx(!trimmedName)}>
+ {trimmedName ? "" : t("required")}
+ </Typography>
</Stack>
- )}
- <TextField
- name="name"
- value={formik.values.name}
- onChange={formik.handleChange}
- label={t("album_name")}
- autoFocus
- fullWidth
- margin="normal"
- disabled={formik.isSubmitting}
- error={!trimmedName}
- helperText={!trimmedName ? t("required") : " "}
- />
- <TextField
- name="description"
- value={formik.values.description}
- onChange={formik.handleChange}
- label={t("description")}
- placeholder={t("caption_placeholder")}
- multiline
- minRows={5}
- fullWidth
- disabled={formik.isSubmitting}
- error={isDescriptionTooLong}
- helperText={`${descriptionLength}/${maxAlbumDescriptionLength}`}
- />
- <Stack direction="row" sx={{ gap: "12px", mt: 3 }}>
- <FocusVisibleButton
- type="button"
- fullWidth
- color="secondary"
- disabled={formik.isSubmitting}
- onClick={handleClose}
+ </Stack>
+ <Stack sx={fieldSx}>
+ <Typography
+ component="label"
+ htmlFor={descriptionID}
+ sx={labelSx}
>
- {t("cancel")}
- </FocusVisibleButton>
- <LoadingButton
- type="submit"
+ {t("description")}
+ </Typography>
+ <InputBase
+ id={descriptionID}
+ name="description"
+ value={formik.values.description}
+ onChange={formik.handleChange}
+ placeholder={t("caption_placeholder")}
+ multiline
+ rows={5}
fullWidth
- color="primary"
- loading={formik.isSubmitting}
- disabled={isSaveDisabled}
+ disabled={formik.isSubmitting}
+ error={isDescriptionTooLong}
+ sx={multilineInputSx}
+ />
+ <Typography
+ sx={[
+ helperSx(isDescriptionTooLong),
+ { textAlign: "right" },
+ ]}
>
- {t("save_changes")}
- </LoadingButton>
+ {`${descriptionLength}/${maxAlbumDescriptionLength}`}
+ </Typography>
</Stack>
</Stack>
- </DialogContent>
+ <LoadingButton
+ type="submit"
+ fullWidth
+ color="accent"
+ loading={formik.isSubmitting}
+ disabled={isSaveDisabled}
+ sx={[
+ saveButtonSx,
+ ...(formik.isSubmitting ? [saveButtonBusySx] : []),
+ ]}
+ >
+ {t("save_changes")}
+ </LoadingButton>
+ </Stack>
</Dialog>
{canShowCoverEditor && (
<PickCoverPhotoDialog
@@ -233,3 +278,186 @@ export const EditAlbumDetailsDialog: React.FC<EditAlbumDetailsDialogProps> = ({
</>
);
};
+
+const PencilEditIcon: React.FC<SvgIconProps> = (props) => (
+ <SvgIcon {...props} viewBox="0 0 12 12">
+ <path
+ d="M1.89091 8.1546L1.5 10.5L3.84543 10.1091C4.25272 10.0413 4.62863 9.8478 4.9206 9.5558L10.2099 4.26644C10.5967 3.87961 10.5967 3.25245 10.2099 2.86563L9.13435 1.79012C8.7475 1.40329 8.1203 1.4033 7.73345 1.79014L2.44421 7.0795C2.15224 7.37145 1.95879 7.74735 1.89091 8.1546Z"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ <path
+ d="M7 3L9 5"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </SvgIcon>
+);
+
+const CoverTile = styled("div")`
+ display: flex;
+ position: relative;
+ width: 108px;
+ height: 108px;
+ border-radius: 20px;
+ overflow: hidden;
+ user-select: none;
+ & > img {
+ object-fit: cover;
+ width: 100%;
+ height: 100%;
+ pointer-events: none;
+ }
+`;
+
+const green = "#08c225";
+const greenHover = "#07ad21";
+const errorColor = "#fa1336";
+
+const paperSx: SxProps<Theme> = (theme) => ({
+ width: "min(520px, calc(100svw - 32px))",
+ maxWidth: "520px",
+ m: 2,
+ borderRadius: "20px",
+ border: "1px solid #e0e0e0",
+ backgroundColor: "#f4f4f4",
+ backgroundImage: "none",
+ boxShadow: "none",
+ color: "text.base",
+ ...theme.applyStyles("dark", {
+ borderColor: "rgba(255 255 255 / 0.12)",
+ backgroundColor: "#1b1b1b",
+ }),
+});
+
+const headerSx = {
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: "12px",
+};
+
+const titleSx = {
+ minWidth: 0,
+ fontFamily: "'Outfit Variable', sans-serif",
+ fontSize: 24,
+ lineHeight: "32px",
+ fontWeight: 600,
+ overflowWrap: "anywhere",
+};
+
+const headerButtonSx = (theme: Theme) => ({
+ width: 38,
+ height: 38,
+ p: 0,
+ flexShrink: 0,
+ color: "text.base",
+ backgroundColor: "background.paper",
+ "&:hover": { backgroundColor: "fill.faintHover" },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+});
+
+const nameRowSx = { alignItems: "center", gap: "16px" };
+
+const coverButtonSx: SxProps<Theme> = {
+ position: "relative",
+ flexShrink: 0,
+ width: 108,
+ height: 108,
+ borderRadius: "20px",
+ "&:focus-visible, &:active": { borderRadius: "20px" },
+ "&:disabled": { cursor: "default" },
+};
+
+const coverBadgeSx: SxProps<Theme> = (theme) => ({
+ position: "absolute",
+ right: "-6px",
+ bottom: "-4px",
+ display: "flex",
+ width: 22,
+ height: 22,
+ alignItems: "center",
+ justifyContent: "center",
+ borderRadius: "50%",
+ color: "#fff",
+ backgroundColor: green,
+ border: "1.5px solid #f4f4f4",
+ ...theme.applyStyles("dark", { borderColor: "#1b1b1b" }),
+});
+
+const fieldSx = { flex: 1, minWidth: 0, gap: "8px" };
+
+const labelSx = { fontSize: 14, lineHeight: "20px", fontWeight: 500 };
+
+const inputSx: SxProps<Theme> = (theme) => ({
+ minHeight: 52,
+ display: "flex",
+ alignItems: "center",
+ borderRadius: "16px",
+ border: "1px solid transparent",
+ backgroundColor: "background.paper",
+ px: "16px",
+ fontSize: 14,
+ fontWeight: 500,
+ color: "text.base",
+ "&.Mui-focused": { borderColor: "rgba(0 0 0 / 0.08)" },
+ "&.Mui-error": { borderColor: errorColor },
+ "& input, & textarea": { padding: 0 },
+ "& input::placeholder, & textarea::placeholder": {
+ color: "text.muted",
+ opacity: 1,
+ },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "#282828",
+ "&.Mui-focused": { borderColor: "rgba(255 255 255 / 0.18)" },
+ }),
+});
+
+const multilineInputSx: SxProps<Theme> = [
+ inputSx,
+ { alignItems: "flex-start", py: "20px", lineHeight: "20px" },
+];
+
+const helperSx = (isError: boolean) => (theme: Theme) => ({
+ fontSize: 12,
+ lineHeight: "16px",
+ fontWeight: 500,
+ color: isError ? errorColor : "rgba(0 0 0 / 0.45)",
+ ...(isError
+ ? {}
+ : theme.applyStyles("dark", { color: "rgba(255 255 255 / 0.45)" })),
+});
+
+const saveButtonSx = (theme: Theme) => ({
+ minHeight: 52,
+ px: 3,
+ py: "14px",
+ borderRadius: "20px",
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ textTransform: "none",
+ color: "#fff",
+ backgroundColor: green,
+ boxShadow: "none",
+ "&:hover": { backgroundColor: greenHover, boxShadow: "none" },
+ "&.Mui-disabled": {
+ color: "#d6d6d6",
+ backgroundColor: "#eaeaea",
+ ...theme.applyStyles("dark", {
+ color: "rgba(255 255 255 / 0.3)",
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+ },
+});
+
+const saveButtonBusySx = {
+ "&.Mui-disabled": { color: "#fff", backgroundColor: green, opacity: 0.7 },
+};