Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Create BackToTop component #139

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sylvainlg
Copy link
Contributor

No description provided.

Copy link
Collaborator

@garronej garronej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your work, here is my review.

const { t } = useTranslation();
const { anchor = "#top", right = false } = props;
return (
<div className={right ? cx(fr.cx("fr-grid-row", "fr-grid-row--right")) : ""}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div className={right ? cx(fr.cx("fr-grid-row", "fr-grid-row--right")) : ""}>
<div className={!right ? undefined : fr.cx("fr-grid-row", "fr-grid-row--right")}>

const { useTranslation, addBackToTopTranslations } = createComponentI18nApi({
"componentName": symToStr({ BackToTop }),
"frMessages": {
"page_top": "Haut de page"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"page_top": "Haut de page"
"page top": "Haut de page"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need the keys to be valid variable names. They arent for other components.

);
})
);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also want export default

Suggested change
export default BackToTop;

Copy link
Collaborator

@garronej garronej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work, here is my review

import { createComponentI18nApi } from "./i18n";

export type BackToTopProps = {
anchor?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no anchor is explicitely provided the default behaviour shoud be to scroll sroll smoothly to the top of the page.
In this case you'll have to use a <button /> component since it's not accible to use a <a /> without a valid href. We need to apply the fr-link class to the button to make it look a <a />.
Beside it's ok accept a css selector but the recomended approach should be to provide ref. Dsfr components do not allow to provide html id but all enable to provide ref.


export type BackToTopProps = {
anchor?: string;
right?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
right?: boolean;
/** Default: false (the back to top button is centered) */
right?: boolean;


export default meta;

export const Default = getStory({});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best to have a story for when the back to top is to the right.

@sylvainlg sylvainlg requested a review from garronej June 13, 2023 07:50
Copy link
Collaborator

@garronej garronej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @sylvainlg,

This has to be adressed: #139 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants