-
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.
Merge branch '1.x' of github.com:pimcore/studio-ui-bundle into edit-v…
…iew-styling
- Loading branch information
Showing
45 changed files
with
789 additions
and
2,136 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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' | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
/** | ||
* 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` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
max-width: 100%; | ||
.ant-image { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
.ant-image-img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: contain; | ||
} | ||
` | ||
} | ||
}) |
74 changes: 74 additions & 0 deletions
74
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,74 @@ | ||
/** | ||
* 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, forwardRef, type MutableRefObject, useEffect } from 'react' | ||
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' | ||
import { useDroppable } from '@Pimcore/components/drag-and-drop/hooks/use-droppable' | ||
import { Spin } from '@Pimcore/components/spin/spin' | ||
import { Flex } from '@Pimcore/components/flex/flex' | ||
|
||
interface ImagePreviewProps { | ||
src?: string | ||
assetId?: number | ||
className?: string | ||
width: number | string | ||
height: number | string | ||
style?: CSSProperties | ||
} | ||
|
||
export const ImagePreview = forwardRef(function ImagePreview ({ src, assetId, width, height, className, style }: ImagePreviewProps, ref: MutableRefObject<HTMLDivElement>): React.JSX.Element { | ||
const [key, setKey] = React.useState(0) | ||
const { getStateClasses } = useDroppable() | ||
const { styles } = useStyle() | ||
|
||
const imageSrc = assetId !== undefined ? `${getPrefix()}/assets/${assetId}/image/stream/preview` : src | ||
|
||
useEffect(() => { | ||
setKey(key + 1) | ||
}, [imageSrc]) | ||
|
||
const loadingSpinner = ( | ||
<Flex | ||
align="center" | ||
className="h-full" | ||
justify="center" | ||
> | ||
<Spin size="small" /> | ||
</Flex> | ||
) | ||
|
||
return ( | ||
<div | ||
className={ cn(className, styles.imagePreviewContainer, ...getStateClasses()) } | ||
ref={ ref } | ||
style={ { | ||
...style, | ||
height: toCssDimension(height), | ||
width: toCssDimension(width) | ||
} } | ||
> | ||
<Image | ||
className="w-full" | ||
fallback="/bundles/pimcorestudioui/img/fallback-image.svg" | ||
key={ key } | ||
placeholder={ loadingSpinner } | ||
preview={ false } | ||
src={ imageSrc } | ||
/> | ||
</div> | ||
) | ||
}) |
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
Oops, something went wrong.