-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created by Github action --------- Co-authored-by: Stuart Runyan <shrunyan@gmail.com> Co-authored-by: Nar -- <28705606+finnar-bin@users.noreply.github.com>
- Loading branch information
1 parent
51ce943
commit e98c511
Showing
8 changed files
with
201 additions
and
8 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
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
119 changes: 119 additions & 0 deletions
119
src/apps/content-editor/src/app/views/ItemEdit/Meta/settings/TCImage.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,119 @@ | ||
import { useState, useMemo } from "react"; | ||
import { MemoryRouter } from "react-router"; | ||
import { Dialog } from "@mui/material"; | ||
import { IconButton } from "@zesty-io/material"; | ||
import { Close } from "@mui/icons-material"; | ||
|
||
import { FieldShell } from "../../../../components/Editor/Field/FieldShell"; | ||
import { FieldTypeMedia } from "../../../../components/FieldTypeMedia"; | ||
import { MediaApp } from "../../../../../../../media/src/app"; | ||
import { ContentModelField } from "../../../../../../../../shell/services/types"; | ||
import { Error } from "../../../../components/Editor/Field/FieldShell"; | ||
import { hasErrors } from "./util"; | ||
|
||
type TCImageProps = { | ||
field: ContentModelField; | ||
error: Error; | ||
onChange: (value: string, name: string) => void; | ||
value: string; | ||
}; | ||
export const TCImage = ({ field, error, onChange, value }: TCImageProps) => { | ||
const [imageModal, setImageModal] = useState(null); | ||
|
||
const imagesArray = useMemo(() => { | ||
if (!value) return []; | ||
|
||
return ((value as string) || "").split(",").filter((el: string) => el); | ||
}, [value]); | ||
|
||
return ( | ||
<> | ||
<FieldShell | ||
settings={{ | ||
label: field?.label, | ||
required: field?.required, | ||
}} | ||
withInteractiveTooltip={false} | ||
errors={error ?? {}} | ||
> | ||
<FieldTypeMedia | ||
hasError={hasErrors(error)} | ||
limit={1} | ||
images={imagesArray} | ||
openMediaBrowser={(opts: any) => { | ||
setImageModal({ | ||
...opts, | ||
locked: Boolean( | ||
field?.settings && | ||
field?.settings.group_id && | ||
field?.settings.group_id != "0" | ||
), | ||
}); | ||
}} | ||
settings={{ | ||
fileExtensions: [ | ||
".png", | ||
".jpg", | ||
".jpeg", | ||
".svg", | ||
".gif", | ||
".tif", | ||
".webp", | ||
], | ||
fileExtensionsErrorMessage: | ||
"Only files with the following extensions are allowed: .png, .jpg, .jpeg, .svg, .gif, .tif, .webp", | ||
}} | ||
name={field?.name} | ||
onChange={onChange} | ||
lockedToGroupId={ | ||
field?.settings?.group_id && field?.settings?.group_id !== "0" | ||
? field?.settings.group_id | ||
: null | ||
} | ||
/> | ||
</FieldShell> | ||
{imageModal && ( | ||
<MemoryRouter initialEntries={["/media?filetype=Image"]}> | ||
<Dialog | ||
open | ||
fullScreen | ||
sx={{ my: 2.5, mx: 10 }} | ||
PaperProps={{ | ||
style: { | ||
borderRadius: "4px", | ||
overflow: "hidden", | ||
}, | ||
}} | ||
onClose={() => setImageModal(null)} | ||
> | ||
<IconButton | ||
sx={{ | ||
position: "fixed", | ||
right: 5, | ||
top: 0, | ||
}} | ||
onClick={() => setImageModal(null)} | ||
> | ||
<Close sx={{ color: "common.white" }} /> | ||
</IconButton> | ||
<MediaApp | ||
limitSelected={1} | ||
isSelectDialog={true} | ||
showHeaderActions={false} | ||
lockedToGroupId={ | ||
field?.settings?.group_id && field?.settings?.group_id !== "0" | ||
? field?.settings.group_id | ||
: null | ||
} | ||
addImagesCallback={(images) => { | ||
imageModal.callback(images); | ||
setImageModal(null); | ||
}} | ||
isReplace={imageModal.isReplace} | ||
/> | ||
</Dialog> | ||
</MemoryRouter> | ||
)} | ||
</> | ||
); | ||
}; |