Skip to content

Commit

Permalink
fix(Button): allow as prop on button (#1994)
Browse files Browse the repository at this point in the history
- also clean up getIconNameFromStatus for use in buttons, etc.
  • Loading branch information
booc0mtaco authored Jun 18, 2024
1 parent af3410f commit 37d1f5b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 27 deletions.
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];
}

0 comments on commit 37d1f5b

Please sign in to comment.