aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/buttons
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-09-20 16:38:54 +0200
committerArmand Philippot <git@armandphilippot.com>2023-09-20 16:38:54 +0200
commitf861e6a269ba9f62700776d3cd13b644a9e836d4 (patch)
treea5a107e7a6e4ff8b4261fe04349357bc00b783ee /src/components/atoms/buttons
parent03331c44276ec56e9f235e4d5ee75030455a753f (diff)
refactor: use named export for everything except pages
Next expect a default export for pages so only those components should use default exports. Everything else should use named exports to reduce the number of import statements.
Diffstat (limited to 'src/components/atoms/buttons')
-rw-r--r--src/components/atoms/buttons/button-link.stories.tsx2
-rw-r--r--src/components/atoms/buttons/button-link.test.tsx2
-rw-r--r--src/components/atoms/buttons/button-link.tsx33
-rw-r--r--src/components/atoms/buttons/button.stories.tsx2
-rw-r--r--src/components/atoms/buttons/button.test.tsx2
-rw-r--r--src/components/atoms/buttons/button.tsx58
-rw-r--r--src/components/atoms/buttons/index.ts2
7 files changed, 39 insertions, 62 deletions
diff --git a/src/components/atoms/buttons/button-link.stories.tsx b/src/components/atoms/buttons/button-link.stories.tsx
index ff0a67f..32c2a7f 100644
--- a/src/components/atoms/buttons/button-link.stories.tsx
+++ b/src/components/atoms/buttons/button-link.stories.tsx
@@ -1,5 +1,5 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
-import ButtonLink from './button-link';
+import { ButtonLink } from './button-link';
/**
* ButtonLink - Storybook Meta
diff --git a/src/components/atoms/buttons/button-link.test.tsx b/src/components/atoms/buttons/button-link.test.tsx
index a5aa7b1..8fabacf 100644
--- a/src/components/atoms/buttons/button-link.test.tsx
+++ b/src/components/atoms/buttons/button-link.test.tsx
@@ -1,5 +1,5 @@
import { render, screen } from '../../../../tests/utils';
-import ButtonLink from './button-link';
+import { ButtonLink } from './button-link';
describe('ButtonLink', () => {
it('renders a ButtonLink component', () => {
diff --git a/src/components/atoms/buttons/button-link.tsx b/src/components/atoms/buttons/button-link.tsx
index 7182d94..c8180c9 100644
--- a/src/components/atoms/buttons/button-link.tsx
+++ b/src/components/atoms/buttons/button-link.tsx
@@ -1,25 +1,13 @@
import Link from 'next/link';
-import { FC, ReactNode } from 'react';
+import { AnchorHTMLAttributes, FC, ReactNode } from 'react';
import styles from './buttons.module.scss';
-export type ButtonLinkProps = {
- /**
- * ButtonLink accessible label.
- */
- 'aria-label'?: string;
- /**
- * One or more ids that refer to the accessible label.
- */
- 'aria-labelledby'?: string;
+export type ButtonLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
/**
* The button link body.
*/
children: ReactNode;
/**
- * Set additional classnames to the button link.
- */
- className?: string;
- /**
* True if it is an external link. Default: false.
*/
external?: boolean;
@@ -42,7 +30,7 @@ export type ButtonLinkProps = {
*
* Use a button-like link as call to action.
*/
-const ButtonLink: FC<ButtonLinkProps> = ({
+export const ButtonLink: FC<ButtonLinkProps> = ({
children,
className,
target,
@@ -53,24 +41,15 @@ const ButtonLink: FC<ButtonLinkProps> = ({
}) => {
const kindClass = styles[`btn--${kind}`];
const shapeClass = styles[`btn--${shape}`];
+ const btnClass = `${styles.btn} ${kindClass} ${shapeClass} ${className}`;
return external ? (
- <a
- href={target}
- className={`${styles.btn} ${kindClass} ${shapeClass} ${className}`}
- {...props}
- >
+ <a {...props} className={btnClass} href={target}>
{children}
</a>
) : (
- <Link
- {...props}
- className={`${styles.btn} ${kindClass} ${shapeClass} ${className}`}
- href={target}
- >
+ <Link {...props} className={btnClass} href={target}>
{children}
</Link>
);
};
-
-export default ButtonLink;
diff --git a/src/components/atoms/buttons/button.stories.tsx b/src/components/atoms/buttons/button.stories.tsx
index 6803706..ba09a0d 100644
--- a/src/components/atoms/buttons/button.stories.tsx
+++ b/src/components/atoms/buttons/button.stories.tsx
@@ -1,5 +1,5 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
-import Button from './button';
+import { Button } from './button';
/**
* Button - Storybook Meta
diff --git a/src/components/atoms/buttons/button.test.tsx b/src/components/atoms/buttons/button.test.tsx
index 90fca02..1162b2b 100644
--- a/src/components/atoms/buttons/button.test.tsx
+++ b/src/components/atoms/buttons/button.test.tsx
@@ -1,5 +1,5 @@
import { render, screen } from '../../../../tests/utils';
-import Button from './button';
+import { Button } from './button';
describe('Button', () => {
it('renders the Button component', () => {
diff --git a/src/components/atoms/buttons/button.tsx b/src/components/atoms/buttons/button.tsx
index fecbcfd..6ef5775 100644
--- a/src/components/atoms/buttons/button.tsx
+++ b/src/components/atoms/buttons/button.tsx
@@ -1,56 +1,46 @@
import {
+ ButtonHTMLAttributes,
forwardRef,
ForwardRefRenderFunction,
- MouseEventHandler,
ReactNode,
} from 'react';
import styles from './buttons.module.scss';
-export type ButtonProps = {
- /**
- * Button accessible label.
- */
- 'aria-label'?: string;
- /**
- * Indicates the current "pressed" state of a toggle button.
- */
- 'aria-pressed'?: boolean | 'mixed';
+export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
/**
* The button body.
*/
children: ReactNode;
/**
- * Set additional classnames to the button wrapper.
- */
- className?: string;
- /**
- * Button state. Default: false.
+ * Button state.
+ *
+ * @default false
*/
disabled?: boolean;
/**
- * Button kind. Default: secondary.
+ * Button kind.
+ *
+ * @default 'secondary'
*/
kind?: 'primary' | 'secondary' | 'tertiary' | 'neutral';
/**
- * A callback function to handle click.
- */
- onClick?: MouseEventHandler<HTMLButtonElement>;
- /**
- * Button shape. Default: rectangle.
+ * Button shape.
+ *
+ * @default 'rectangle'
*/
shape?: 'circle' | 'rectangle' | 'square' | 'initial';
/**
- * Button type attribute. Default: button.
+ * Button type attribute.
+ *
+ * @default 'button'
*/
type?: 'button' | 'reset' | 'submit';
};
-/**
- * Button component
- *
- * Use a button as call to action.
- */
-const Button: ForwardRefRenderFunction<HTMLButtonElement, ButtonProps> = (
+const ButtonWithRef: ForwardRefRenderFunction<
+ HTMLButtonElement,
+ ButtonProps
+> = (
{
className = '',
children,
@@ -64,18 +54,24 @@ const Button: ForwardRefRenderFunction<HTMLButtonElement, ButtonProps> = (
) => {
const kindClass = styles[`btn--${kind}`];
const shapeClass = styles[`btn--${shape}`];
+ const btnClass = `${styles.btn} ${kindClass} ${shapeClass} ${className}`;
return (
<button
- className={`${styles.btn} ${kindClass} ${shapeClass} ${className}`}
+ {...props}
+ className={btnClass}
disabled={disabled}
ref={ref}
type={type}
- {...props}
>
{children}
</button>
);
};
-export default forwardRef(Button);
+/**
+ * Button component
+ *
+ * Use a button as call to action.
+ */
+export const Button = forwardRef(ButtonWithRef);
diff --git a/src/components/atoms/buttons/index.ts b/src/components/atoms/buttons/index.ts
new file mode 100644
index 0000000..486e485
--- /dev/null
+++ b/src/components/atoms/buttons/index.ts
@@ -0,0 +1,2 @@
+export * from './button';
+export * from './button-link';