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

How to hide the feedback component? #1263

Open
billalive opened this issue Oct 14, 2022 · 1 comment
Open

How to hide the feedback component? #1263

billalive opened this issue Oct 14, 2022 · 1 comment
Labels
role: dev 🤖 severity: 3 Affects minor functionality, has a workaround type: bug 🐛

Comments

@billalive
Copy link

First off, thanks for this fantastic design system!

I want to hide the "feedback" component. This looks like a simple case of shadowing, but I want to post my solution here in case there is a more elegant way to do it.

The feedback component is sourced as FeedbackDialog in the Utils component at 'src/components/Utils/Utils.js'.

The current original version of this component is:

import React, { useState } from 'react';
import { useWindowScroll } from 'beautiful-react-hooks';
import cx from 'classnames';
import FeedbackDialog from '../FeedbackDialog';
import BackToTopBtn from '../BackToTopBtn';

import * as styles from './Utils.module.scss';

const Utils = () => {
  const [hidden, setHidden] = useState(true);
  const onScroll = useWindowScroll();

  onScroll(() => {
    if (hidden && window.scrollY > 300) {
      setHidden(false);
    }
    if (!hidden && window.scrollY < 300) {
      setHidden(true);
    }
  });

  return (
    <div
      aria-label="This section contains utilities"
      className={cx(styles.container, { [styles.hidden]: hidden })}>
      <FeedbackDialog />
      <BackToTopBtn />
    </div>
  );
};

export default Utils;

To shadow this, I copy this file to my own site at: src/gatsby-theme-carbon/components/Utils/Utils.js, and modify it to:

// Shadow Utils.js to remove FeedbackDialog
// Original:
// https://github.com/carbon-design-system/gatsby-theme-carbon/blob/main/packages/gatsby-theme-carbon/src/components/Utils/Utils.js

import React, { useState } from "react";
import { useWindowScroll } from "beautiful-react-hooks";
import cx from "classnames";
// import FeedbackDialog from '../FeedbackDialog';
// import BackToTopBtn from "../BackToTopBtn";
import BackToTopBtn from "gatsby-theme-carbon/src/components/BackToTopBtn";

// import * as styles from "./Utils.module.scss";
import * as styles from "gatsby-theme-carbon/src/components/Utils/Utils.module.scss";

const Utils = () => {
  const [hidden, setHidden] = useState(true);
  const onScroll = useWindowScroll();

  onScroll(() => {
    if (hidden && window.scrollY > 300) {
      setHidden(false);
    }
    if (!hidden && window.scrollY < 300) {
      setHidden(true);
    }
  });

  return (
    <div
      aria-label="This section contains utilities"
      className={cx(styles.container, { [styles.hidden]: hidden })}
    >
      <BackToTopBtn />
    </div>
  );
};

export default Utils;

The charges are:

  • Remove the import FeedbackDialog at the top.
  • Adjust the paths for the other imports.
  • Remove the <FeedbackDialog /> in the return().

As a final step, I also seem to need to copy 'src/components/Utils/index.js' to my site at src/gatsby-theme-carbon/components/Utils/index.js

No change to the file is needed:

import Utils from "./Utils";

export default Utils;

but in this new location, it will source my shadowed version at Utils.js.

Is this the correct method? It seems like there might be a more elegant way to do this than copying the entire Utils.js and also the unchanged index.js. So I wanted to check.

Thank you!

@billalive billalive changed the title How to hide the feedback component? ❓ How to hide the feedback component? Oct 14, 2022
@sstrubberg
Copy link
Member

hey @billalive. I'm curious how you're getting the Feedback component right out of the box. You should have to activate the Feedback component to get it going. Let us know!

@sstrubberg sstrubberg added severity: 3 Affects minor functionality, has a workaround role: dev 🤖 and removed status: needs triage 🕵️‍♀️ labels Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
role: dev 🤖 severity: 3 Affects minor functionality, has a workaround type: bug 🐛
Projects
Status: ⏱ Backlog
Development

No branches or pull requests

2 participants