generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Contents <!-- Description of what this PR contains. New components/features, bugfixes, etc. --> ## Checklist <!-- Surround an item with double tildes `~~` to indicate that it does not apply to this PR --> - [x] New features/components and bugfixes are covered by tests - [x] Changesets are created - [x] Definition of Done is checked --------- Co-authored-by: Jaap-Hein Wester <j.h.wester@setonix.nl>
- Loading branch information
1 parent
60ac1d8
commit e7a4ac7
Showing
15 changed files
with
543 additions
and
2,022 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,7 @@ | ||
--- | ||
"@lux-design-system/components-react": major | ||
--- | ||
|
||
In deze commit: | ||
|
||
- Nieuw component: LuxButton |
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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
.lux-button { | ||
display: inline-flex; | ||
} | ||
|
||
.lux-button--small { | ||
padding-block-start: var(--lux-button-small-padding-block-start); | ||
padding-block-end: var(--lux-button-small-padding-block-end); | ||
min-inline-size: var(--lux-button-small-min-inline-size); | ||
min-block-size: var(--lux-button-small-min-block-size); | ||
} | ||
|
||
.lux-button-icon--start { | ||
order: 0; | ||
} | ||
|
||
.lux-button-icon--end { | ||
order: 1; | ||
} |
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,45 @@ | ||
import { | ||
Button as UtrechtButton, | ||
type ButtonProps as UtrechtButtonProps, | ||
} from '@utrecht/component-library-react/dist/css-module'; | ||
import './Button.css'; | ||
import React, { ReactElement } from 'react'; | ||
|
||
type IconPosition = 'start' | 'end'; | ||
type Size = 'small'; | ||
|
||
export type LuxButtonProps = UtrechtButtonProps & { | ||
size?: Size; | ||
iconPosition?: IconPosition; | ||
}; | ||
|
||
const SIZE_CLASSNAME: { [key: string]: string } = { | ||
small: 'lux-button--small', | ||
}; | ||
|
||
const ICON_POSITIONS: { [key: string]: string } = { | ||
start: 'lux-button-icon--start', | ||
end: 'lux-button-icon--end', | ||
}; | ||
|
||
export const LuxButton = (props: LuxButtonProps) => { | ||
const { size, icon: iconNode, iconPosition, ...otherProps } = props; | ||
|
||
const className = `lux-button ${size !== undefined ? SIZE_CLASSNAME[size] : ''}`; | ||
|
||
const positionedIcon = React.Children.map(iconNode, (iconElement) => { | ||
if (!iconElement) { | ||
return null; | ||
} | ||
|
||
if (!React.isValidElement<HTMLElement>(iconElement)) { | ||
return iconElement; | ||
} | ||
|
||
return React.cloneElement(iconElement as ReactElement, { | ||
className: `${iconElement?.props?.className || ''}${iconPosition !== undefined ? ICON_POSITIONS[iconPosition] : ''}`, | ||
}); | ||
}); | ||
|
||
return <UtrechtButton {...otherProps} className={className} {...(positionedIcon ? { icon: positionedIcon } : {})} />; | ||
}; |
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,51 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { LuxButton } from '../Button'; | ||
|
||
//TODO replace icon in #308 | ||
const ExampleIcon = ( | ||
<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg"> | ||
<circle r="6" cx="7" cy="7" fill="white" stroke="green" /> | ||
</svg> | ||
); | ||
|
||
describe('Button', () => { | ||
it('renders a button', () => { | ||
render(<LuxButton label="LUX Button" />); | ||
|
||
const button = screen.getByRole('button', { | ||
name: 'LUX Button', | ||
}); | ||
expect(button).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders a small button', () => { | ||
render(<LuxButton label="LUX Button" size="small" />); | ||
|
||
const button = screen.getByRole('button', { | ||
name: 'LUX Button', | ||
}); | ||
|
||
expect(button).toHaveClass('lux-button--small'); | ||
}); | ||
|
||
it('renders a button with a start icon', () => { | ||
render(<LuxButton label="LUX Button" icon={ExampleIcon} iconPosition="start" />); | ||
|
||
const button = screen.getByRole('button', { | ||
name: 'LUX Button', | ||
}); | ||
|
||
expect(button.children[0].getAttribute('class')).toEqual('lux-button-icon--start'); | ||
}); | ||
|
||
it('renders a button with an end icon', () => { | ||
render(<LuxButton label="LUX Button" icon={ExampleIcon} iconPosition="end" />); | ||
|
||
const button = screen.getByRole('button', { | ||
name: 'LUX Button', | ||
}); | ||
|
||
expect(button.children[0].getAttribute('class')).toEqual('lux-button-icon--end'); | ||
}); | ||
}); |
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
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 { Canvas, Controls, Markdown, Meta } from "@storybook/blocks"; | ||
import markdown from "@utrecht/button-css/README.md?raw"; | ||
import * as ButtonStories from "./button.stories.tsx"; | ||
import { CitationDocumentation } from "../../utils/CitationDocumentation.tsx"; | ||
|
||
<Meta of={ButtonStories} /> | ||
|
||
# Button | ||
|
||
<CitationDocumentation | ||
component="Utrecht Button" | ||
url="https://nl-design-system.github.io/utrecht/storybook-css/index.html?path=/docs/css-heading--docs" | ||
/> | ||
|
||
<Markdown>{markdown}</Markdown> | ||
|
||
## Opmerkingen | ||
|
||
- De `iconPosition` property is toegevoegd om het icoon te positioneren binnen de button. | ||
- Met de `size` property kan de grootte van de button ingesteld worden. | ||
|
||
## Playground | ||
|
||
<Canvas of={ButtonStories.Playground} /> | ||
<Controls of={ButtonStories.Playground} /> | ||
|
||
## Small Button | ||
|
||
<Canvas of={ButtonStories.SmallButton} /> | ||
|
||
## Variants | ||
|
||
<Canvas of={ButtonStories.Primary} /> | ||
<Canvas of={ButtonStories.Secondary} /> | ||
<Canvas of={ButtonStories.Tertiary} /> | ||
|
||
## Button states | ||
|
||
<Canvas of={ButtonStories.Active} /> | ||
<Canvas of={ButtonStories.Focus} /> | ||
<Canvas of={ButtonStories.Hover} /> | ||
<Canvas of={ButtonStories.Disabled} /> | ||
<Canvas of={ButtonStories.Busy} /> | ||
<Canvas of={ButtonStories.Toggle} /> | ||
|
||
## Button With Icon | ||
|
||
<Canvas of={ButtonStories.ButtonWithIconAtPositionStart} /> | ||
<Canvas of={ButtonStories.ButtonWithIconAtPositionEnd} /> |
Oops, something went wrong.