Skip to content

Commit

Permalink
Merge pull request #8 from millnut/feature/components
Browse files Browse the repository at this point in the history
refactor: react component functions to you arrow functions
  • Loading branch information
3LivesLeft authored Oct 12, 2023
2 parents ca7e978 + 3cd0078 commit 702c49c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
7 changes: 1 addition & 6 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';
import Button from './Button';
import buttonProps, { buttonLinkProps } from './defaultProps';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta = {
title: 'Example/Button',
component: Button,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
layout: 'centered'
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: ['autodocs']
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const PrimaryButton: Story = {
args: {
...buttonProps
Expand Down
6 changes: 4 additions & 2 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactElement } from 'react';
import './button.scss';
import useTheme from '../../hooks/useDarkMode';
import './button.scss';

export interface ButtonProps {
label: string;
Expand All @@ -18,7 +18,7 @@ export interface ButtonProps {
* Primary UI component for user interaction
*/

export const Button = ({ label, url, ...props }: ButtonProps): ReactElement => {
const Button = ({ label, url, ...props }: ButtonProps): ReactElement => {
const theme = useTheme();
return url ? (
<a className={`button theme--${theme.mode}`} href={url}>
Expand All @@ -30,3 +30,5 @@ export const Button = ({ label, url, ...props }: ButtonProps): ReactElement => {
</button>
);
};

export default Button;
8 changes: 5 additions & 3 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode } from 'react';
import React, { ReactElement } from 'react';
import useTheme from '../../hooks/useDarkMode';
import Image, { ImageProps } from '../Image/Image';
import './Card.scss';
Expand All @@ -22,7 +22,7 @@ export interface CardProps {
url?: string;
}

export default function Card({ image, title, body, url }: CardProps): ReactNode {
const Card = ({ image, title, body, url }: CardProps): ReactElement => {
const theme = useTheme();

function handleClick(e: React.MouseEvent<HTMLElement>): void {
Expand Down Expand Up @@ -56,4 +56,6 @@ export default function Card({ image, title, body, url }: CardProps): ReactNode
</span>
</li>
);
}
};

export default Card;
28 changes: 14 additions & 14 deletions src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export interface ImageProps {
loadingAttr?: 'lazy' | 'eager' | undefined;
}

export default function Image({ src, size, width, height, altText, loadingAttr = 'lazy' }: ImageProps): ReactElement {
return (
<img
className="image"
srcSet={`${src.small}, ${src.medium}, ${src.default}`}
sizes={`${size?.small ?? 576}w, ${size?.medium ?? 992}w, ${size?.default ?? 1440}w`}
src={src.default}
width={width}
height={height}
alt={altText}
loading={loadingAttr}
/>
);
}
const Image = ({ src, size, width, height, altText, loadingAttr = 'lazy' }: ImageProps): ReactElement => (
<img
className="image"
srcSet={`${src.small}, ${src.medium}, ${src.default}`}
sizes={`${size?.small ?? 576}w, ${size?.medium ?? 992}w, ${size?.default ?? 1440}w`}
src={src.default}
width={width}
height={height}
alt={altText}
loading={loadingAttr}
/>
);

export default Image;
6 changes: 3 additions & 3 deletions src/components/Listing/Listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export interface ListingProps {
children: ReactNode;
}

export default function Listing({ children }: ListingProps): ReactElement {
return <ul className="listing">{children}</ul>;
}
const Listing = ({ children }: ListingProps): ReactElement => <ul className="listing">{children}</ul>;

export default Listing;
6 changes: 4 additions & 2 deletions src/components/TextImage/TextImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface TextImageProps {
image: ImageProps;
}

export default function TextImage({ title, body, image }: TextImageProps): ReactElement {
const TextImage = ({ title, body, image }: TextImageProps): ReactElement => {
const theme = useTheme();
return (
<section className={`text-image theme--${theme.mode}`}>
Expand All @@ -29,4 +29,6 @@ export default function TextImage({ title, body, image }: TextImageProps): React
</div>
</section>
);
}
};

export default TextImage;

0 comments on commit 702c49c

Please sign in to comment.