Skip to content

Commit

Permalink
fix types, simplify Link
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Jan 25, 2024
1 parent d21c368 commit c3c503a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion code/ui/components/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { styled } from '@storybook/theming';
import { deprecate, logger } from '@storybook/client-logger';

export type IconType = keyof typeof icons;
type NewIconTypes = typeof icons[IconType];
type NewIconTypes = (typeof icons)[IconType];

const NEW_ICON_MAP = StorybookIcons as Record<NewIconTypes, (props: unknown) => React.ReactNode>;

Expand Down
15 changes: 4 additions & 11 deletions code/ui/components/src/components/typography/elements/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React from 'react';

export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
children: React.ReactNode;
}

export const Link = ({ href: input, children, ...props }: LinkProps) => {
export const Link = ({ href: input, ...props }: React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
const isStorybookPath = /^\//.test(input);
const isAnchorUrl = /^#.*/.test(input);
const href = isStorybookPath ? `./?path=${input}` : input;

const isAnchorUrl = /^#.*/.test(input);
const target = isAnchorUrl ? '_self' : '_top';

return (
<a href={href} target={target} {...props}>
{children}
</a>
);
return <a href={href} target={target} {...props} />;
};

0 comments on commit c3c503a

Please sign in to comment.