Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat: improve links
Browse files Browse the repository at this point in the history
  • Loading branch information
rudigier committed Mar 25, 2023
1 parent b631f7d commit 0e213fb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/components/Atoms/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type TLink<T> = {
newTab?: boolean;
} & Omit<T, 'className' | 'target' | 'rel'>;



/*
* Style
*/
Expand All @@ -42,7 +44,7 @@ const hoverStyle = 'hover:text-violet-700 hover:decoration-violet-200';
/**
* Link Component
*
* @param {string} as - HTML tag to render a link
* @param {string} component - Component to render a link (e.g. NextLink)
* @param {string} href - provide a link reference (target url) as string for the 'a' tag
* @param {ReactNode} children - Child Nodes
*
Expand Down
2 changes: 1 addition & 1 deletion src/components/Molecules/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const ButtonColorMap: Record<string, string> = {
/**
* Button component
*
* @param { string } as - HTML tag to render
* @param { string } component - Component to render a link (e.g. NextLink)
* @param { string } size - text size options of this button (S, M, L)
* @param { string } colorScheme - color scheme options of this button (slate, violet, gradient)
* @param { string } icon - icon name to render
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const InteractionButtonIconColorSchemeMap: Record<string, Record<string, string>

/**
* Typography for InteractionButton Component
* @param { string } component - Component to render a link (e.g. NextLink)
* @param { buttonText } buttonText label of the button
* @param { colorScheme } colorScheme of the Button: `pink`, `violet`, or `slate`
* @param { iconName } iconName name of Icon -see Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ const Template: ComponentStory<typeof Component> = (args): JSX.Element => <Compo
export const RoundButton = Template.bind({});
RoundButton.args = {
icon: 'edit',
children: 'Button Round',
buttonLabel: 'Button Round',
};
30 changes: 12 additions & 18 deletions src/components/Molecules/RoundButton/RoundButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, ButtonHTMLAttributes, AnchorHTMLAttributes } from 'react';
import React, { FC, ButtonHTMLAttributes } from 'react';

import { Icon } from '../../Atoms/Icon';
import { ButtonBaseStyle, ButtonColorMap } from '../Button';
Expand All @@ -7,11 +7,11 @@ import { ButtonBaseStyle, ButtonColorMap } from '../Button';
* Type
*/

type TRoundButton = {
type TRoundButton<T> = {
/**
* HTML tag to render a button (button, a)
* HTML tag to render a button
*/
as?: 'button' | 'a';
component?: FC<T>;

/**
* label for screenreaders
Expand All @@ -27,11 +27,7 @@ type TRoundButton = {
* specify a Icon-name string from the IconLibrary
*/
icon?: string;
};

type HTMLButtonProps = TRoundButton & { as: 'button' } & ButtonHTMLAttributes<HTMLButtonElement>;
type LinkButtonProps = TRoundButton & { as: 'a' } & AnchorHTMLAttributes<HTMLAnchorElement>;
type TButtonProps = HTMLButtonProps | LinkButtonProps;
} & Omit<T, 'className'>;

/*
* Style
Expand All @@ -43,22 +39,20 @@ export const RoundButtonColorMap: Record<string, string> = ButtonColorMap;
/**
* RoundButton Component
*
* @param {string} as - choose HTML Tag to render the RoundButton (button, a)
* @param {string} component - Component to render a link (e.g. NextLink)
* @param {string} buttonLabel - label for screenreaders
* @param {string} colorScheme - colorscheme for RoundButton background: slate, violet or gradient
* @param {string} icon - specify a Icon-name string from the IconLibrary
* @param {any} props - all other props will be spreaded to the HTML Tag
*
* @example <RoundButton buttonLabel="Mumble" as="button" colorScheme="violet" icon="mumble" />
*/

export const RoundButton: FC<TButtonProps> = ({
as: Tag = 'button',
colorScheme = 'violet',
icon = 'mumble',
buttonLabel,
...props
}) => {
export function RoundButton<
T extends {
className?: string;
} = ButtonHTMLAttributes<HTMLElement>
>({ component, colorScheme = 'violet', icon = 'mumble', buttonLabel, ...props }: TRoundButton<T>): JSX.Element {
const Tag = component || 'button';
const style = [...RoundButtonBaseStyle, RoundButtonColorMap[colorScheme]];

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Molecules/UserProfile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const UserProfile: FC<TUserProfile> = ({ size = 'M', border, href, userNa
<Image src={avatar || noAvatar} alt={userName} width={imgMap[size]} height={imgMap[size]} />
</div>
<div className="absolute -bottom-1 -right-1 md:-bottom-2 md:-right-2 sm:-bottom-4 sm:-right-4">
<RoundButton as="a" href={href} icon="edit" colorScheme="slate" buttonLabel={buttonLabel} />
<RoundButton icon="edit" colorScheme="slate" buttonLabel={buttonLabel} />
</div>
</div>
);
Expand Down

0 comments on commit 0e213fb

Please sign in to comment.