Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Button): allow as prop on button #1994

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ type ButtonHTMLElementProps = React.ButtonHTMLAttributes<HTMLButtonElement>;

export type ButtonProps<ExtendedElement = unknown> = ButtonHTMLElementProps & {
// Component API
/**
* Component used to render the element. Meant to support interaction with framework navigation libraries.
*
* **Default is `"button"`**.
*/
as?: string | React.ElementType;
/**
* `Button` contents or label.
*/
Expand Down Expand Up @@ -91,6 +97,7 @@ export type ButtonProps<ExtendedElement = unknown> = ButtonHTMLElementProps & {
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(
{
as: Component = 'button',
children,
className,
context,
Expand Down Expand Up @@ -126,7 +133,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
);

return (
<button
<Component
className={componentClassName}
disabled={isDisabled}
ref={ref}
Expand Down Expand Up @@ -160,7 +167,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
{isLoading && (
<LoadingIndicator className={styles['button__loader']} size="xs" />
)}
</button>
</Component>
);
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/InlineNotification/InlineNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import React from 'react';

import getIconNameFromStatus from '../../util/getIconNameFromStatus-v2';
import getIconNameFromStatus from '../../util/getIconNameFromStatus';
import type { Status } from '../../util/variant-types';

import Icon from '../Icon';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function ExtendedLink(args: ExtendArgs) {
* ```tsx
* type CustomLinkProps = React.ComponentProps<typeof CustomLink>;
* type ExtendedProps = LinkProps<CustomLinkProps>;
* *
*
* export default function Link({children, ...other}: ExtendedProps) {
* return (
* <Link as={CustomLink} {...other}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/PageNotification/PageNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import React, { type ReactNode } from 'react';

import getIconNameFromStatus from '../../util/getIconNameFromStatus-v2';
import getIconNameFromStatus from '../../util/getIconNameFromStatus';
import type { Status } from '../../util/variant-types';

import Button from '../Button';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ToastNotification/ToastNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import React, { useEffect } from 'react';

import getIconNameFromStatus from '../../util/getIconNameFromStatus-v2';
import getIconNameFromStatus from '../../util/getIconNameFromStatus';
import type { Status } from '../../util/variant-types';
import Button from '../Button';
import Icon from '../Icon';
Expand Down
18 changes: 0 additions & 18 deletions src/util/getIconNameFromStatus-v2.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/util/getIconNameFromStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type { IconName } from '../icons/spritemap';
*/
export default function getIconNameFromStatus(status: Status): IconName {
const map: Record<Status, IconName> = {
informational: 'info',
informational: 'info-encircled-filled',
critical: 'dangerous',
warning: 'warning',
favorable: 'check-circle',
warning: 'warning-filled',
favorable: 'checkmark-encircled-filled',
};
return map[status];
}
Loading