-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
033188c
commit e40a7a3
Showing
17 changed files
with
355 additions
and
27 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
40 changes: 40 additions & 0 deletions
40
assets/js/src/core/components/image-preview/image-preview.stories.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,40 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import { type Meta } from '@storybook/react' | ||
import { ImagePreview } from './image-preview' | ||
|
||
const config: Meta = { | ||
title: 'Components/Data Display/ImagePreview', | ||
component: ImagePreview, | ||
tags: ['autodocs'], | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: 'This component is used to display an image preview with specified width and height. The component has a max-width of 100% and the image is displayed centered within the given box. This component can also be used within a droppable component to allow drag and drop of images.' | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default config | ||
|
||
export const _default = { | ||
args: { | ||
width: 300, | ||
height: 300, | ||
style: { | ||
border: '1px dashed #d9d9d9', | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
assets/js/src/core/components/image-preview/image-preview.styles.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,33 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import { createStyles } from 'antd-style' | ||
|
||
export const useStyle = createStyles(({ token, css }) => { | ||
return { | ||
imagePreviewContainer: css` | ||
max-width: 100%; | ||
.ant-image { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
.ant-image-img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: contain; | ||
} | ||
` | ||
} | ||
}) |
55 changes: 55 additions & 0 deletions
55
assets/js/src/core/components/image-preview/image-preview.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,55 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { type CSSProperties } from 'react' | ||
import { Flex } from '@Pimcore/components/flex/flex' | ||
import { useStyle } from './image-preview.styles' | ||
import cn from 'classnames' | ||
import { toCssDimension } from '@Pimcore/utils/css' | ||
import { Image } from 'antd' | ||
import { getPrefix } from '@Pimcore/app/api/pimcore/route' | ||
|
||
interface ImagePreviewProps { | ||
src?: string | ||
assetId?: number | ||
className?: string | ||
width: number | string | ||
height: number | string | ||
style?: CSSProperties | ||
} | ||
|
||
export const ImagePreview = ({ src, assetId, width, height, className, style }: ImagePreviewProps): React.JSX.Element => { | ||
const { styles } = useStyle() | ||
|
||
const imageSrc = assetId !== undefined ? `${getPrefix()}/assets/${assetId}/image/stream/preview` : src | ||
|
||
return ( | ||
<Flex | ||
align="center" | ||
className={ cn(className, styles.imagePreviewContainer) } | ||
justify="center" | ||
style={ { | ||
...style, | ||
height: toCssDimension(height), | ||
width: toCssDimension(width) | ||
} } | ||
> | ||
<Image | ||
className="w-full" | ||
fallback="/bundles/pimcorestudioui/img/fallback-image.svg" | ||
preview={ false } | ||
src={ imageSrc } | ||
/> | ||
</Flex> | ||
) | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...les/element/dynamic-types/defintinitions/objects/data-related/components/image/footer.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,41 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { useEffect } from 'react' | ||
import { IconButton } from '@Pimcore/components/icon-button/icon-button' | ||
|
||
interface ImageFooterProps { | ||
value?: string | ||
onChange?: (value?: string) => void | ||
disabled?: boolean | ||
} | ||
|
||
export const ImageFooter = (props: ImageFooterProps): React.JSX.Element => { | ||
const [value, setValue] = React.useState<string | undefined>(props.value) | ||
|
||
const emptyValue = (): void => { | ||
setValue(undefined) | ||
} | ||
|
||
useEffect(() => { | ||
props.onChange?.(value) | ||
}, [value]) | ||
|
||
return ( | ||
<IconButton | ||
disabled={ props.disabled } | ||
icon={ { value: 'delete-outlined' } } | ||
onClick={ emptyValue } | ||
/> | ||
) | ||
} |
Oops, something went wrong.