-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Figure Caption subcomponent
- Loading branch information
1 parent
a51ad85
commit ae9d076
Showing
7 changed files
with
170 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { render } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { FigureCaption } from './FigureCaption' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Figure Caption', () => { | ||
it('renders', () => { | ||
const { container } = render(<FigureCaption />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<FigureCaption />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-figure__caption') | ||
}) | ||
|
||
it('renders the right inverse color class', () => { | ||
const { container } = render(<FigureCaption inverseColor>Caption</FigureCaption>) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-figure__caption--inverse-color') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
const { container } = render(<FigureCaption className="extra" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('ams-figure__caption extra') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLAnchorElement>() | ||
|
||
const { container } = render(<FigureCaption ref={ref} />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(ref.current).toBe(component) | ||
}) | ||
}) |
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,27 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
|
||
export type FigureCaptionProps = { | ||
/** Changes the text colour for readability on a dark background. */ | ||
inverseColor?: boolean | ||
} & PropsWithChildren<HTMLAttributes<HTMLElement>> | ||
|
||
export const FigureCaption = forwardRef( | ||
({ children, className, inverseColor, ...restProps }: FigureCaptionProps, ref: ForwardedRef<HTMLElement>) => ( | ||
<figcaption | ||
{...restProps} | ||
ref={ref} | ||
className={clsx('ams-figure__caption', inverseColor && 'ams-figure__caption--inverse-color', className)} | ||
> | ||
{children} | ||
</figcaption> | ||
), | ||
) | ||
|
||
FigureCaption.displayName = 'Figure.Caption' |
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
{ | ||
"ams": { | ||
"figure": {} | ||
"figure": { | ||
"gap": { "value": "{ams.space.sm}" }, | ||
"caption": { | ||
"color": { "value": "{ams.brand.color.neutral.100}" }, | ||
"font-family": { "value": "{ams.text.font-family}" }, | ||
"font-size": { "value": "{ams.text.level.6.font-size}" }, | ||
"font-weight": { "value": "{ams.text.font-weight.normal}" }, | ||
"line-height": { "value": "{ams.text.level.6.line-height}" }, | ||
"inverse-color": { "value": "{ams.brand.color.neutral.0}" } | ||
} | ||
} | ||
} | ||
} |
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