Pause story on mouse/space hold

This commit is contained in:
Jamie Kyle 2024-04-15 13:14:26 -07:00 committed by GitHub
parent be68c739e5
commit ef012d3bf4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 93 additions and 9 deletions

View file

@ -1,9 +1,24 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useMemo } from 'react';
import { useMemo, useState } from 'react';
import { v4 as uuid } from 'uuid';
export function useUniqueId(): string {
return useMemo(() => uuid(), []);
}
let nextElementId = 0;
export function useElementId(
namePrefix: string
): [id: string, selector: string] {
// Prefixed to avoid starting with a number (which is invalid in CSS selectors)
const [id] = useState(() => {
const currentId = nextElementId;
nextElementId += 1;
return `${namePrefix}-${currentId}`;
});
// Return the ID and a selector that can be used in CSS or JS
return [id, `#${id}`] as const;
}