use data-... attributes for custom attributes

main
Inga 🏳‍🌈 3 weeks ago
parent 5d9e136dcb
commit 664197cb72
  1. 2
      src/backend/components/boardgame.tsx
  2. 6
      src/backend/components/counter.tsx
  3. 2
      src/frontend/components/reactive-button.ts
  4. 2
      src/frontend/utils/query-tracking-utils.ts
  5. 7
      src/jsx-augmentations.ts

@ -52,7 +52,7 @@ export const getBoardgameHtml = (key: string, gameState: BoardgameStateType, gam
.map(([name]) => name); .map(([name]) => name);
return ( return (
<board-game track={key} className={gameActiveClassNames.join(" ")} game-variant={gameVariant}> <board-game data-track={key} className={gameActiveClassNames.join(" ")} game-variant={gameVariant}>
<progressive-form-wrapper> <progressive-form-wrapper>
<form method="post" is="progressive-form"> <form method="post" is="progressive-form">
<p class="when-outcome-undecided"> <p class="when-outcome-undecided">

@ -6,15 +6,15 @@ export const getCounterHtml = (req: Request, key: string) => {
return ( return (
<> <>
<form method="post" is="progressive-form"> <form method="post" is="progressive-form">
<button type="submit" name={key} value={`${counter - 1}`} is="reactive-button" track={key} delta="-1"> <button type="submit" name={key} value={`${counter - 1}`} is="reactive-button" data-track={key} data-delta="-1">
- -
</button>{" "} </button>{" "}
<button type="submit" name={key} value={`${counter + 1}`} is="reactive-button" track={key} delta="+1"> <button type="submit" name={key} value={`${counter + 1}`} is="reactive-button" data-track={key} data-delta="+1">
+ +
</button> </button>
</form>{" "} </form>{" "}
Value of "{key}":{" "} Value of "{key}":{" "}
<span class="counter" is="reactive-span" track={key}> <span class="counter" is="reactive-span" data-track={key}>
{counter} {counter}
</span> </span>
</> </>

@ -4,7 +4,7 @@ class ReactiveButton extends HTMLButtonElement {
private readonly trackingTools = new TrackingTools(this); private readonly trackingTools = new TrackingTools(this);
handleTrackedValueUpdate(newValue: string | null) { handleTrackedValueUpdate(newValue: string | null) {
const delta = parseInt(this.getAttribute("delta") ?? "0", 10); const delta = parseInt(this.getAttribute("data-delta") ?? "0", 10);
this.value = (parseInt(newValue ?? "0", 10) + delta).toString(); this.value = (parseInt(newValue ?? "0", 10) + delta).toString();
} }

@ -27,7 +27,7 @@ export class TrackingTools<
constructor(private readonly element: TElement) {} constructor(private readonly element: TElement) {}
private setTrackerIfNeeded() { private setTrackerIfNeeded() {
const trackKey = this.element.getAttribute("track"); const trackKey = this.element.getAttribute("data-track");
if (trackKey != this.currentTrackKey) { if (trackKey != this.currentTrackKey) {
if (this.clearTracker) { if (this.clearTracker) {
this.clearTracker(); this.clearTracker();

@ -1,13 +1,6 @@
declare module "preact/jsx-runtime" { declare module "preact/jsx-runtime" {
// eslint-disable-next-line @typescript-eslint/no-namespace -- preact uses namespaces, so we have too // eslint-disable-next-line @typescript-eslint/no-namespace -- preact uses namespaces, so we have too
namespace JSX { namespace JSX {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- this is how declaration merging is done
interface HTMLAttributes {
// custom attribute used by query-tracker web components
delta?: string;
track?: string;
}
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- this is how declaration merging is done // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- this is how declaration merging is done
interface IntrinsicElements { interface IntrinsicElements {
"board-game": HTMLAttributes; "board-game": HTMLAttributes;

Loading…
Cancel
Save