-
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.
Merge branch 'develop' into task/DES-474-translate-docs
# Conflicts: # documentation/storybook.md
- Loading branch information
Showing
59 changed files
with
1,027 additions
and
853 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Badge | ||
|
||
A prominently coloured box containing 1 or 2 words. | ||
Guides the user in taking a specific action or describes its surrounding content. | ||
|
||
## Design | ||
|
||
The badge can contain a short text or a number. | ||
The default background colour is dark green. | ||
Suggestions on when to use the other colours will follow soon. |
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,58 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
.amsterdam-badge { | ||
display: inline-block; | ||
font-family: var(--amsterdam-badge-font-family); | ||
font-size: var(--amsterdam-badge-spacious-font-size); | ||
font-weight: var(--amsterdam-badge-font-weight); | ||
line-height: var(--amsterdam-badge-spacious-line-height); | ||
padding-inline: var(--amsterdam-badge-padding-inline); | ||
|
||
.amsterdam-theme--compact & { | ||
font-size: var(--amsterdam-badge-compact-font-size); | ||
line-height: var(--amsterdam-badge-compact-line-height); | ||
} | ||
} | ||
|
||
.amsterdam-badge--blue { | ||
background-color: var(--amsterdam-badge-blue-background-color); | ||
color: var(--amsterdam-badge-blue-color); | ||
} | ||
|
||
.amsterdam-badge--dark-blue { | ||
background-color: var(--amsterdam-badge-dark-blue-background-color); | ||
color: var(--amsterdam-badge-dark-blue-color); | ||
} | ||
|
||
.amsterdam-badge--dark-green { | ||
background-color: var(--amsterdam-badge-dark-green-background-color); | ||
color: var(--amsterdam-badge-dark-green-color); | ||
} | ||
|
||
.amsterdam-badge--green { | ||
background-color: var(--amsterdam-badge-green-background-color); | ||
color: var(--amsterdam-badge-green-color); | ||
} | ||
|
||
.amsterdam-badge--magenta { | ||
background-color: var(--amsterdam-badge-magenta-background-color); | ||
color: var(--amsterdam-badge-magenta-color); | ||
} | ||
|
||
.amsterdam-badge--orange { | ||
background-color: var(--amsterdam-badge-orange-background-color); | ||
color: var(--amsterdam-badge-orange-color); | ||
} | ||
|
||
.amsterdam-badge--purple { | ||
background-color: var(--amsterdam-badge-purple-background-color); | ||
color: var(--amsterdam-badge-purple-color); | ||
} | ||
|
||
.amsterdam-badge--yellow { | ||
background-color: var(--amsterdam-badge-yellow-background-color); | ||
color: var(--amsterdam-badge-yellow-color); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { render } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { Badge, badgeColors } from './Badge' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Badge', () => { | ||
it('renders', () => { | ||
const { container } = render(<Badge label="test" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<Badge label="test" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('amsterdam-badge') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
const { container } = render(<Badge label="test" className="extra" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('amsterdam-badge extra') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLElement>() | ||
|
||
const { container } = render(<Badge label="test" ref={ref} />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(ref.current).toBe(component) | ||
}) | ||
|
||
it('renders with a number label', () => { | ||
const { container } = render(<Badge label={1} />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveTextContent('1') | ||
}) | ||
|
||
it('renders with default color', () => { | ||
const { container } = render(<Badge label="test" />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass('amsterdam-badge--dark-green') | ||
}) | ||
|
||
badgeColors.map((color) => | ||
it(`renders with ${color} color`, () => { | ||
const { container } = render(<Badge label="test" color={color} />) | ||
|
||
const component = container.querySelector(':only-child') | ||
|
||
expect(component).toHaveClass(`amsterdam-badge--${color}`) | ||
}), | ||
) | ||
}) |
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 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2024 Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes } from 'react' | ||
|
||
export const badgeColors = [ | ||
'blue', | ||
'dark-blue', | ||
'dark-green', | ||
'green', | ||
'magenta', | ||
'orange', | ||
'purple', | ||
'yellow', | ||
] as const | ||
|
||
type BadgeColor = (typeof badgeColors)[number] | ||
|
||
export type BadgeProps = { | ||
color?: BadgeColor | ||
label: string | number | ||
} & HTMLAttributes<HTMLElement> | ||
|
||
export const Badge = forwardRef( | ||
({ label, className, color = 'dark-green', ...restProps }: BadgeProps, ref: ForwardedRef<HTMLElement>) => ( | ||
<span {...restProps} ref={ref} className={clsx('amsterdam-badge', `amsterdam-badge--${color}`, className)}> | ||
{label} | ||
</span> | ||
), | ||
) | ||
|
||
Badge.displayName = 'Badge' |
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,3 @@ | ||
# React Badge component | ||
|
||
[Badge documentation](../../../css/src/badge/README.md) |
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,2 @@ | ||
export { Badge } from './Badge' | ||
export type { BadgeProps } from './Badge' |
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,41 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { BreadcrumbItem } from './BreadcrumbItem' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('BreadcrumbItem', () => { | ||
it('renders', () => { | ||
render(<BreadcrumbItem href="/" />) | ||
const component = screen.getByRole('listitem') | ||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
render(<BreadcrumbItem href="/" />) | ||
const item = screen.getByRole('listitem') | ||
expect(item).toHaveClass('amsterdam-breadcrumb__item') | ||
|
||
const link = screen.getByRole('link') | ||
expect(link).toHaveClass('amsterdam-breadcrumb__link') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
render(<BreadcrumbItem href="/" className="extra" />) | ||
const component = screen.getByRole('listitem') | ||
expect(component).toHaveClass('amsterdam-breadcrumb__item extra') | ||
}) | ||
|
||
it('renders the href attribute', () => { | ||
render(<BreadcrumbItem href="/" />) | ||
const component = screen.getByRole('link') | ||
expect(component).toHaveAttribute('href', '/') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLLIElement>() | ||
render(<BreadcrumbItem href="/" ref={ref} />) | ||
const component = screen.getByRole('listitem') | ||
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,24 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright (c) 2023 Gemeente Amsterdam | ||
*/ | ||
|
||
import { clsx } from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
|
||
export interface BreadcrumbItemProps extends PropsWithChildren<HTMLAttributes<HTMLLIElement>> { | ||
href: string | ||
} | ||
|
||
export const BreadcrumbItem = forwardRef( | ||
({ children, className, href, ...restProps }: BreadcrumbItemProps, ref: ForwardedRef<HTMLLIElement>) => ( | ||
<li {...restProps} className={clsx('amsterdam-breadcrumb__item', className)} ref={ref}> | ||
<a className="amsterdam-breadcrumb__link" href={href}> | ||
{children} | ||
</a> | ||
</li> | ||
), | ||
) | ||
|
||
BreadcrumbItem.displayName = 'BreadcrumbItem' |
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,2 +1,3 @@ | ||
export { Breadcrumb } from './Breadcrumb' | ||
export type { BreadcrumbProps, BreadcrumbItemProps } from './Breadcrumb' | ||
export type { BreadcrumbProps } from './Breadcrumb' | ||
export type { BreadcrumbItemProps } from './BreadcrumbItem' |
Oops, something went wrong.