generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #455 closes #470 --------- Co-authored-by: Ruben Smit <[email protected]> Co-authored-by: Mees <[email protected]>
- Loading branch information
1 parent
67403ed
commit 10bd40d
Showing
17 changed files
with
249 additions
and
149 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
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,23 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2020-2022 Gemeente Utrecht | ||
* Copyright (c) 2020-2022 Frameless B.V. | ||
*/ | ||
|
||
@mixin invisible-but-accessible { | ||
block-size: 1px !important; | ||
|
||
/* Source: https://kittygiraudel.com/snippets/sr-only-class/ */ | ||
border: 0 !important; | ||
clip: rect(1px, 1px, 1px, 1px) !important; | ||
-webkit-clip-path: inset(50%) !important; | ||
clip-path: inset(50%) !important; | ||
inline-size: 1px !important; | ||
/* stylelint-disable-next-line property-disallowed-list */ | ||
margin: -1px !important; | ||
overflow: hidden !important; | ||
/* stylelint-disable-next-line property-disallowed-list */ | ||
padding: 0 !important; | ||
position: absolute !important; | ||
white-space: nowrap !important; | ||
} |
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,16 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Community for NL Design System | ||
*/ | ||
@import "./mixin"; | ||
|
||
.rhc-button--icon-only { | ||
padding-block-end: var(--rhc-icon-only-button-padding-block-end); | ||
padding-block-start: var(--rhc-icon-only-button-padding-block-start); | ||
padding-inline-end: var(--rhc-icon-only-button-padding-inline-end); | ||
padding-inline-start: var(--rhc-icon-only-button-padding-inline-start); | ||
} | ||
|
||
.rhc-button--icon-only .rhc-button__sr-only { | ||
@include invisible-but-accessible; | ||
} |
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,81 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { IconButton } from './Button'; | ||
import '@testing-library/jest-dom'; | ||
|
||
describe('IconButton', () => { | ||
it('renders an HTML button element', () => { | ||
const { container } = render(<IconButton label="example-icon-label" />); | ||
|
||
const button = container.querySelector('button'); | ||
|
||
expect(button).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders an sr-only label for accessibility', () => { | ||
render(<IconButton label="example-icon-label" />); | ||
|
||
const span = screen.getByText('example-icon-label'); | ||
|
||
expect(span).toHaveClass('rhc-button__sr-only'); | ||
}); | ||
|
||
it('renders a design system BEM class name', () => { | ||
const { container } = render(<IconButton label="example-icon-label" />); | ||
|
||
const button = container.querySelector('button'); | ||
|
||
expect(button).toHaveClass('rhc-button'); | ||
|
||
expect(button).toHaveClass('rhc-button--icon-only'); | ||
}); | ||
|
||
it('is not disabled by default', () => { | ||
const { container } = render(<IconButton label="example-icon-label" />); | ||
|
||
const button = container.querySelector('button'); | ||
|
||
expect(button).not.toBeDisabled(); | ||
|
||
expect(button).not.toHaveAttribute('aria-disabled'); | ||
|
||
expect(button).not.toHaveAttribute('disabled'); | ||
}); | ||
|
||
it('can have a disabled state', () => { | ||
const { container } = render(<IconButton label="example-icon-label" disabled={true} />); | ||
|
||
const button = container.querySelector('button'); | ||
|
||
expect(button).toBeDisabled(); | ||
}); | ||
|
||
it('can be hidden', () => { | ||
const { container } = render(<IconButton label="example-icon-label" hidden />); | ||
|
||
const button = container.querySelector('button'); | ||
|
||
expect(button).not.toBeVisible(); | ||
}); | ||
|
||
it('can have a additional class name', () => { | ||
const { container } = render(<IconButton label="example-icon-label" className="large" />); | ||
|
||
const button = container.querySelector('button'); | ||
|
||
expect(button).toHaveClass('large'); | ||
|
||
expect(button).toHaveClass('utrecht-button'); | ||
}); | ||
|
||
it('can trigger a click event', () => { | ||
const handleClick = jest.fn(); | ||
|
||
const { container } = render(<IconButton label="example-icon-label" onClick={handleClick} />); | ||
|
||
const button = container.querySelector<HTMLElement>('button'); | ||
|
||
button?.click(); | ||
|
||
expect(handleClick).toHaveBeenCalled(); | ||
}); | ||
}); |
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,31 @@ | ||
import '@rijkshuisstijl-community/components-css/index.scss'; | ||
import { | ||
Button, | ||
type ButtonProps, | ||
Icon, | ||
PrimaryActionButton, | ||
SecondaryActionButton, | ||
SubtleButton, | ||
} from '@utrecht/component-library-react/dist/css-module'; | ||
import clsx from 'clsx'; | ||
import { ForwardedRef, forwardRef, PropsWithChildren } from 'react'; | ||
|
||
export { type ButtonProps, Button, PrimaryActionButton, SecondaryActionButton, SubtleButton }; | ||
|
||
export interface IconButtonProps extends ButtonProps { | ||
label: string; | ||
} | ||
|
||
export const IconButton = forwardRef( | ||
( | ||
{ children, className, label, ...restProps }: PropsWithChildren<IconButtonProps>, | ||
ref: ForwardedRef<HTMLButtonElement>, | ||
) => ( | ||
<SubtleButton ref={ref} className={clsx('rhc-button', 'rhc-button--icon-only', className)} {...restProps}> | ||
<span className="rhc-button__sr-only">{label}</span> | ||
<Icon>{children}</Icon> | ||
</SubtleButton> | ||
), | ||
); | ||
|
||
IconButton.displayName = 'IconButton'; |
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
Oops, something went wrong.