diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-04 18:17:35 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:14:41 +0100 |
| commit | be61ffb6fe500cdbfa83b9cd131b8e72779f23c2 (patch) | |
| tree | 9ac57f4fac173e13c0a461d75a206819be4f3c6f /src/components/molecules/buttons/back-to-top/back-to-top.tsx | |
| parent | a724b4b38bacc631410627395b0d1190a0e8de0d (diff) | |
refactor(components): rewrite BackToTop component
* replace `link` prop with `anchor` prop
* add a `label` prop to let consumer handle the accessible name
Diffstat (limited to 'src/components/molecules/buttons/back-to-top/back-to-top.tsx')
| -rw-r--r-- | src/components/molecules/buttons/back-to-top/back-to-top.tsx | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/components/molecules/buttons/back-to-top/back-to-top.tsx b/src/components/molecules/buttons/back-to-top/back-to-top.tsx new file mode 100644 index 0000000..83e2161 --- /dev/null +++ b/src/components/molecules/buttons/back-to-top/back-to-top.tsx @@ -0,0 +1,45 @@ +import type { FC } from 'react'; +import { + ButtonLink, + type ButtonLinkProps, + Icon, + VisuallyHidden, +} from '../../../atoms'; +import styles from './back-to-top.module.scss'; + +export type BackToTopProps = Omit< + ButtonLinkProps, + 'children' | 'isExternal' | 'kind' | 'to' +> & { + /** + * Define the anchor. + */ + anchor: string; + /** + * Define an accessible label for the button. + */ + label: string; +}; + +/** + * BackToTop component + * + * Render a back to top link. + */ +export const BackToTop: FC<BackToTopProps> = ({ + anchor, + className = '', + label, + shape = 'square', + ...props +}) => { + const btnClass = `${styles.link} ${className}`; + + return ( + <ButtonLink {...props} className={btnClass} shape={shape} to={anchor}> + {/* eslint-disable-next-line react/jsx-no-literals -- Config allowed */} + <Icon aria-hidden orientation="top" shape="arrow" /> + <VisuallyHidden>{label}</VisuallyHidden> + </ButtonLink> + ); +}; |
