Skip to content

Commit

Permalink
Remove as prop
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga committed Dec 12, 2023
1 parent 3343801 commit aa5d3d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
8 changes: 1 addition & 7 deletions packages/react/src/HeroImage/HeroImage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { HeroImage } from './HeroImage'
import '@testing-library/jest-dom'
Expand All @@ -23,12 +23,6 @@ describe('Hero image', () => {
expect(component).toHaveClass('amsterdam-hero-image extra')
})

it('renders a custom HTML element', () => {
render(<HeroImage src="https://picsum.photos/1280/360" as="section" />)
const sectionElement = screen.getByRole('section')
expect(sectionElement).toBeInTheDocument()
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLDivElement>()
const { container } = render(<HeroImage src="https://picsum.photos/1280/360" ref={ref} />)
Expand Down
18 changes: 7 additions & 11 deletions packages/react/src/HeroImage/HeroImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ import { ImgHTMLAttributes } from 'react'
import { forwardRef, HTMLAttributes, PropsWithChildren } from 'react'

export interface HeroImageProps extends PropsWithChildren<HTMLAttributes<HTMLElement>> {
as?: 'article' | 'aside' | 'div' | 'footer' | 'section'
/** The source of the image. */
src: ImgHTMLAttributes<HTMLImageElement>['src']
}

export const HeroImage = forwardRef<HTMLDivElement, HeroImageProps>(
({ as = 'div', children, className, src, ...restProps }: HeroImageProps, ref) => {
const Component = as

return (
<Component {...restProps} ref={ref} className={clsx('amsterdam-hero-image', className)}>
<img alt="" className="amsterdam-hero-image__image" src={src} />
{children}
</Component>
)
},
({ children, className, src, ...restProps }: HeroImageProps, ref) => (
<div {...restProps} ref={ref} className={clsx('amsterdam-hero-image', className)}>
<img alt="" className="amsterdam-hero-image__image" src={src} />
{children}
</div>
),
)

HeroImage.displayName = 'HeroImage'
3 changes: 2 additions & 1 deletion storybook/storybook-react/src/HeroImage/HeroImage.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Als het nodig is wordt deze uitgerekt om de volledige oppervlakte in te nemen.
### Met zoekveld

Een [Grid](?path=/docs/react_layout-grid--docs) verzorgt horizontale witruimte aan weerszijden en kolommen voor layout.
Zo kan bijvoorbeeld een zoekveld geplaatst worden. Verticaal centreren gaat vanzelf.
Zo kan bijvoorbeeld een zoekveld geplaatst worden.
Verticaal centreren gaat vanzelf.

<Canvas of={HeroImageStories.WithSearchField} />

0 comments on commit aa5d3d4

Please sign in to comment.