Skip to content

Commit d66cdbd

Browse files
authored
fix: add classes for picture tag in media component (#11605)
Sometimes I need to add some classes to the `picture` tag of Media component. in this case I need to do this: ``` <Media resource={content.image} className="w-full h-full [&>picture]:w-full" // <<< follow this imgClassName="w-full h-full object-cover" /> ``` So I added an additional props `pictureClassName` for the picture tag. Now I can do this: ``` <Media resource={content.image} className="w-full h-full" pictureClassName="w-full h-full" // <<< follow this imgClassName="w-full h-full object-cover" /> ``` NOTE: I've encountered situations where I needed to add classes to the `picture` tag, not just for `w-full h-full`. To handle this, I had to update the Media component. I believe this would be a valuable improvement to the Media component.
1 parent 5e3d07b commit d66cdbd

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

templates/website/src/components/Media/ImageMedia/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const ImageMedia: React.FC<MediaProps> = (props) => {
2121
const {
2222
alt: altFromProps,
2323
fill,
24+
pictureClassName,
2425
imgClassName,
2526
priority,
2627
resource,
@@ -56,7 +57,7 @@ export const ImageMedia: React.FC<MediaProps> = (props) => {
5657
.join(', ')
5758

5859
return (
59-
<picture>
60+
<picture className={cn(pictureClassName)}>
6061
<NextImage
6162
alt={alt || ''}
6263
className={cn(imgClassName)}

templates/website/src/components/Media/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface Props {
88
className?: string
99
fill?: boolean // for NextImage only
1010
htmlElement?: ElementType | null
11+
pictureClassName?: string
1112
imgClassName?: string
1213
onClick?: () => void
1314
onLoad?: () => void

0 commit comments

Comments
 (0)