-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: explain custom event props and detail when PropFunction is need…
…ed (#5386)
- Loading branch information
Showing
3 changed files
with
86 additions
and
32 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/docs/src/routes/demo/events/custom-event/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { component$, Slot, useStore } from '@builder.io/qwik'; | ||
|
||
export default component$(() => { | ||
return ( | ||
<Button onTripleClick$={() => alert('TRIPLE CLICKED!')}> | ||
Triple Click me! | ||
</Button> | ||
); | ||
}); | ||
|
||
type ButtonProps = { | ||
onTripleClick$: () => void; | ||
}; | ||
|
||
export const Button = component$<ButtonProps>(({ onTripleClick$ }) => { | ||
const state = useStore({ | ||
clicks: 0, | ||
lastClickTime: 0, | ||
}); | ||
return ( | ||
<button | ||
onClick$={() => { | ||
// triple click logic | ||
const now = Date.now(); | ||
const timeBetweenClicks = now - state.lastClickTime; | ||
state.lastClickTime = now; | ||
if (timeBetweenClicks > 500) { | ||
state.clicks = 0; | ||
} | ||
state.clicks++; | ||
if (state.clicks === 3) { | ||
// handle custom event | ||
onTripleClick$(); | ||
state.clicks = 0; | ||
} | ||
}} | ||
> | ||
<Slot /> | ||
</button> | ||
); | ||
}); |
16 changes: 0 additions & 16 deletions
16
packages/docs/src/routes/demo/events/prop-function/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters