Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into task/DES-569-refactor-subcomponents
  • Loading branch information
alimpens committed Jan 19, 2024
2 parents 6dadf92 + ad1c421 commit 0785108
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/Grid/GridCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react'
import { GridColumnNumber, GridColumnNumbers } from './Grid'
import type { GridColumnNumber, GridColumnNumbers } from './Grid'
import { gridCellClasses } from './gridCellClasses'

type GridCellSpanAllProp = {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Grid/gridCellClasses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GridCellProps } from './GridCell'
import type { GridCellProps } from './GridCell'

export const gridCellClasses = (span?: GridCellProps['span'], start?: GridCellProps['start']): string[] => {
if (!span && !start) {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/Grid/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Grid'
export { Grid } from './Grid'
export type { GridProps, GridColumnNumber, GridColumnNumbers } from './Grid'
export type { GridCellProps } from './GridCell'
22 changes: 9 additions & 13 deletions packages/react/src/Header/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { render, screen } from '@testing-library/react'
import { createRef } from 'react'
import { Header, HeaderProps } from './Header'
import { Header } from './Header'
import '@testing-library/jest-dom'

describe('Header', () => {
const defaultProps: HeaderProps = {
logoLink: '/',
}

it('renders', () => {
render(<Header {...defaultProps} />)
render(<Header />)

const component = screen.getByRole('banner')

Expand All @@ -18,15 +14,15 @@ describe('Header', () => {
})

it('renders a design system BEM class name', () => {
render(<Header {...defaultProps} />)
render(<Header />)

const component = screen.getByRole('banner')

expect(component).toHaveClass('amsterdam-header')
})

it('renders an additional class name', () => {
render(<Header {...defaultProps} className="extra" />)
render(<Header className="extra" />)

const component = screen.getByRole('banner')

Expand All @@ -37,31 +33,31 @@ describe('Header', () => {
it('supports ForwardRef in React', () => {
const ref = createRef<HTMLElement>()

render(<Header {...defaultProps} ref={ref} />)
render(<Header ref={ref} />)

const component = screen.getByRole('banner')

expect(ref.current).toBe(component)
})

it('renders with a logo link', () => {
render(<Header {...defaultProps} logoLink="/home" />)
render(<Header logoLink="/home" />)

const logoLink = screen.getByRole('link')

expect(logoLink).toHaveAttribute('href', '/home')
})

it('renders with a logo link title', () => {
render(<Header {...defaultProps} logoLinkTitle="Go to homepage" />)
render(<Header logoLinkTitle="Go to homepage" />)

const logoLinkTitle = screen.getByRole('link', { name: 'Go to homepage' })

expect(logoLinkTitle).toHaveTextContent('Go to homepage')
})

it('renders with links', () => {
const { container } = render(<Header {...defaultProps} links={<div>Menu Content</div>} />)
const { container } = render(<Header links={<div>Menu Content</div>} />)

const menu = container.querySelector('.amsterdam-header__links')

Expand All @@ -70,7 +66,7 @@ describe('Header', () => {
})

it('renders with menu button', () => {
render(<Header {...defaultProps} menu={<button>Menu Button</button>} />)
render(<Header menu={<button>Menu Button</button>} />)

const menu = screen.getByRole('button')

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/MegaMenu/MegaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, ForwardRefExoticComponent, HTMLAttributes, PropsWithChildren, RefAttributes } from 'react'

type MegaMenuProps = {} & PropsWithChildren<HTMLAttributes<HTMLDivElement>>
export type MegaMenuProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>>

interface MegaMenuComponent extends ForwardRefExoticComponent<MegaMenuProps & RefAttributes<HTMLDivElement>> {
ListCategory: typeof MegaMenuListCategory
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/MegaMenu/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { MegaMenu } from './MegaMenu'
export type { MegaMenuProps } from './MegaMenu'
7 changes: 3 additions & 4 deletions packages/react/src/Overlap/Overlap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import clsx from 'clsx'
import { forwardRef } from 'react'
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react'

export type OverlapProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>>

export const Overlap = forwardRef(
(
{ children, className, ...restProps }: PropsWithChildren<HTMLAttributes<HTMLDivElement>>,
ref: ForwardedRef<HTMLDivElement>,
) => (
({ children, className, ...restProps }: OverlapProps, ref: ForwardedRef<HTMLDivElement>) => (
<div {...restProps} ref={ref} className={clsx('amsterdam-overlap', className)}>
{children}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/Overlap/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Overlap } from './Overlap'
export type { OverlapProps } from './Overlap'
7 changes: 3 additions & 4 deletions packages/react/src/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import clsx from 'clsx'
import { forwardRef, useId } from 'react'
import type { ForwardedRef, InputHTMLAttributes, PropsWithChildren } from 'react'

export type SwitchProps = PropsWithChildren<InputHTMLAttributes<HTMLInputElement>>

export const Switch = forwardRef(
(
{ className, id, ...restProps }: PropsWithChildren<InputHTMLAttributes<HTMLInputElement>>,
ref: ForwardedRef<HTMLInputElement>,
) => {
({ className, id, ...restProps }: SwitchProps, ref: ForwardedRef<HTMLInputElement>) => {
const inputId = id || useId()

return (
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/Switch/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Switch } from './Switch'
export type { SwitchProps } from './Switch'

0 comments on commit 0785108

Please sign in to comment.