mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 00:48:25 +00:00
* new implementation/image
* Revert "new implementation/image"
This reverts commit 637bd83108.
* new implementation/image
This commit is contained in:
parent
c550836497
commit
8fa30f5612
1 changed files with 5 additions and 28 deletions
|
|
@ -1,41 +1,18 @@
|
|||
import React from 'react';
|
||||
import { resolveReferences, resolveWidgetFieldValue } from '@/_helpers/utils';
|
||||
import LazyLoad from 'react-lazyload';
|
||||
|
||||
export const Image = function Image({ id, height, component, onComponentClick, currentState }) {
|
||||
const source = component.definition.properties.source.value;
|
||||
const widgetVisibility = component.definition.styles?.visibility?.value ?? true;
|
||||
const disabledState = component.definition.styles?.disabledState?.value ?? false;
|
||||
|
||||
const parsedDisabledState =
|
||||
typeof disabledState !== 'boolean' ? resolveWidgetFieldValue(disabledState, currentState) : disabledState;
|
||||
|
||||
let data = resolveReferences(source, currentState, null);
|
||||
|
||||
let parsedWidgetVisibility = widgetVisibility;
|
||||
|
||||
try {
|
||||
parsedWidgetVisibility = resolveReferences(parsedWidgetVisibility, currentState, []);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
if (data === '') data = null;
|
||||
export const Image = function Image({ height, properties, styles }) {
|
||||
const source = properties.source;
|
||||
const widgetVisibility = styles.visibility ?? true;
|
||||
|
||||
function Placeholder() {
|
||||
return <div className="skeleton-image" style={{ objectFit: 'contain', height }}></div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
data-disabled={parsedDisabledState}
|
||||
style={{ display: parsedWidgetVisibility ? '' : 'none' }}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onComponentClick(id, component, event);
|
||||
}}
|
||||
>
|
||||
<div data-disabled={styles.disabledState} style={{ display: widgetVisibility ? '' : 'none' }}>
|
||||
<LazyLoad height={height} placeholder={<Placeholder />} debounce={500}>
|
||||
<img style={{ objectFit: 'contain' }} src={data} height={height} />
|
||||
<img src={source} height={height} />
|
||||
</LazyLoad>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue