forked from liferay/liferay-portal
-
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.
LPD-16407 Partial revert of 9be93c5, since it is still been used in d…
…dm_template/edit_small_image.jsp
- Loading branch information
1 parent
442a4c8
commit 98adf06
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
modules/apps/journal/journal-web/src/main/resources/META-INF/resources/js/ImageInput.es.js
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,85 @@ | ||
/** | ||
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com | ||
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 | ||
*/ | ||
|
||
import ClayButton from '@clayui/button'; | ||
import ClayForm, {ClayInput} from '@clayui/form'; | ||
import ClayIcon from '@clayui/icon'; | ||
import {sub} from 'frontend-js-web'; | ||
import React, {useRef, useState} from 'react'; | ||
|
||
export default function ImageInput({name, portletNamespace, previewURL}) { | ||
const [fileName, setFileName] = useState(previewURL || ''); | ||
const imageTitleId = `${portletNamespace}${name}`; | ||
const inputRef = useRef(); | ||
|
||
return ( | ||
<div className="mb-3"> | ||
{previewURL ? ( | ||
<div className="aspect-ratio aspect-ratio-16-to-9 mb-2 rounded"> | ||
<img | ||
alt={Liferay.Language.get('preview')} | ||
className="aspect-ratio-item-fluid" | ||
src={previewURL} | ||
/> | ||
</div> | ||
) : null} | ||
|
||
{name ? ( | ||
<ClayForm.Group> | ||
<label className="sr-only" htmlFor={imageTitleId}> | ||
{Liferay.Language.get('image')} | ||
</label> | ||
|
||
<ClayInput.Group small> | ||
<ClayInput.GroupItem> | ||
<input | ||
className="sr-only" | ||
id={imageTitleId} | ||
name={name} | ||
onChange={(event) => | ||
setFileName( | ||
event.target.files?.[0]?.name || '' | ||
) | ||
} | ||
ref={inputRef} | ||
type="file" | ||
/> | ||
|
||
<ClayInput | ||
onClick={() => inputRef.current?.click()} | ||
placeholder={Liferay.Language.get( | ||
'select-image' | ||
)} | ||
readOnly | ||
sizing="sm" | ||
value={fileName} | ||
/> | ||
</ClayInput.GroupItem> | ||
|
||
<ClayInput.GroupItem shrink> | ||
<ClayButton | ||
displayType="secondary" | ||
monospaced | ||
onClick={() => inputRef.current?.click()} | ||
size="sm" | ||
title={sub( | ||
fileName | ||
? Liferay.Language.get('change-x') | ||
: Liferay.Language.get('select-x'), | ||
Liferay.Language.get('image') | ||
)} | ||
> | ||
<ClayIcon | ||
className="mt-0" | ||
symbol={fileName ? 'change' : 'plus'} | ||
/> | ||
</ClayButton> | ||
</ClayInput.GroupItem> | ||
</ClayInput.Group> | ||
</ClayForm.Group> | ||
) : null} | ||
</div> | ||
); | ||
} |