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

test: update styleguide to isolate by state #1960

Closed
wants to merge 4 commits into from

Conversation

wusteven815
Copy link
Contributor

@wusteven815 wusteven815 commented Apr 24, 2024

  • Refactor styleguide page to filter components by if it's rendered, instead of by CSS variables
  • Refactor styleguide test to have sections be soft steps instead of its own step
    • Refactor buttons section to be a function component
  • Refactor styleguide test to run in parallel instead of serial

@wusteven815 wusteven815 self-assigned this Apr 24, 2024
@mofojed mofojed requested a review from bmingles April 24, 2024 19:09
const hasMultipleThemes = themes.length > 1;

function isHash(label: string, processLabel = false): boolean {
Copy link
Contributor

@bmingles bmingles Apr 24, 2024

Choose a reason for hiding this comment

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

Instead of passing this around via props, I would consider encapsulating the hash matching functionality in a custom hook. Something like:

function useIsHash() {
  const [hash, setHash] = useState(window.location.hash);

  useEffect(() => {
    const hashChangeHandler = () => setHash(window.location.hash);
    window.addEventListener('hashchange', hashChangeHandler);
    return () => window.removeEventListener('hashchange', hashChangeHandler);
  }, []);

  const isHash = useCallback(
    (label: string, processLabel = false): boolean => {
      const newLabel = processLabel
        ? label.toLocaleLowerCase().replaceAll(' ', '-')
        : label;

      return hash === `#${newLabel}` || hash === '';
    },
    [hash]
  );

  return isHash;
}

Then you can just use it in any component like:

const isHash = useIsHash();

Copy link
Contributor

Choose a reason for hiding this comment

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

is there something that can be done so that it doesn't have to be littered all over the place?

@wusteven815 wusteven815 marked this pull request as ready for review April 26, 2024 18:25
@dsmmcken
Copy link
Contributor

Closing in favor of ticket inspired by this one: #2000

@dsmmcken dsmmcken closed this May 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants