-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: hooks useId docs * fix: hooks Toggle docs * fix: hooks useClickOutside docs * fix: hooks useScrollLock docs * fix: hooks useForceUpdate docs * fix: hooks useDidUpdate docs * fix: hooks useClipboard docs * fix: docs menu
- Loading branch information
1 parent
2f7e25b
commit ed70ae1
Showing
23 changed files
with
896 additions
and
212 deletions.
There are no files selected for viewing
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,6 @@ | ||
--- | ||
'kubed-documents': major | ||
'@kubed/hooks': major | ||
--- | ||
|
||
fix: add hooks docs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
group: 'hooks' | ||
category: 'state' | ||
title: 'useClickOutside' | ||
description: 'Listen to click events outside the target element' | ||
order: 2 | ||
--- | ||
|
||
## Usage | ||
|
||
useClickOutside Please click the button or outside the button to see the effect | ||
|
||
```jsx live=true | ||
import React from 'react'; | ||
import { useClickOutside } from '@kubed/hooks'; | ||
import { Button } from '@kubed/components' | ||
|
||
export default function App() { | ||
const [counter, setCounter] = React.useState(0); | ||
const ref = useClickOutside(() => { | ||
console.log('OutsideClick') | ||
setCounter(counter => counter+1) | ||
} | ||
); | ||
|
||
return ( | ||
<div> | ||
<p>counter: {counter}</p> | ||
<Button ref={ref}>Button</Button> | ||
</div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
## API | ||
|
||
The useClickOutside hook accepts three parameters: | ||
|
||
- `handler` – the callback function that triggers the event | ||
- `events` – the event type used for monitoring, default value: `['mousedown', 'touchstart']` | ||
- `nodes` – DOM nodes or Ref, supports arrays | ||
|
||
```tsx | ||
function useClickOutside<T extends HTMLElement = any>( | ||
handler: () => void, events?: string[] | null, nodes?: HTMLElement[] | ||
): React.MutableRefObject<T> | ||
``` | ||
|
||
## Params | ||
|
||
| Parameters | Default Value | Type | Description | | ||
|---------|----------------------------------|------ ------------|-------------------| | ||
| handler | - | `() => void` | callback function that triggers the event | | ||
| events | `['mousedown', 'touchstart']` | `(string[] null)` | Event type for listening | | ||
| nodes | - | `HTMLElement[]` | DOM node or Ref, supports array | | ||
|
||
## Result | ||
|
||
|
||
| Parameters | Default Value | Type | Description | | ||
|------------|---------------|-----------------------------|----------------| | ||
| ref | - | `React.MutableRefObject<T>` | target element | |
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,57 @@ | ||
--- | ||
group: 'hooks' | ||
category: 'state' | ||
title: 'useClipboard' | ||
description: 'useClipboard copies values in components' | ||
Order: 4 | ||
--- | ||
|
||
## Usage | ||
|
||
useClipboard copies the value in the component. | ||
|
||
```jsx live=true | ||
import { useClipboard } from '@kubed/hooks'; | ||
import { Button, Group } from '@kubed/components' | ||
|
||
export default function App() { | ||
const {copy, reset, error, copied } = useClipboard(); | ||
|
||
return ( | ||
<div> | ||
<p>{"copied: "+copied}</p> | ||
<p>error: {error}</p> | ||
<Group spacing="xl"> | ||
<Button onClick={() => copy('copy message')}> copy </Button> | ||
<Button onClick={() => reset() }> reset </Button> | ||
</Group> | ||
</div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
## API | ||
|
||
```tsx | ||
|
||
function useClipboard( | ||
{timeout}?: {timeout?: number} | ||
): {copy: (valueToCopy: any) => void, reset: () => void, error: Error, copied: boolean} | ||
``` | ||
|
||
## Params | ||
|
||
| Parameters | Default Value | Type | Description | | ||
|---------|--------|----------|-------------| | ||
| timeout | `2000` | `number` | The time delay for event triggering | | ||
|
||
## Result | ||
|
||
|
||
| Parameters | Default Value | Type | Description | | ||
|--------|-----|---------------------------------|--- --------| | ||
| copy | - | `(valueToCopy: any) => void` | The value to be copied | | ||
| reset | - | `() => void` | Reset the copied value | | ||
| error | - | `Error` | An error when copying a value | | ||
| copied | - | `boolean` | Whether the copied value was successful | |
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,45 @@ | ||
--- | ||
group: 'hooks' | ||
category: 'state' | ||
title: 'useDidUpdate' | ||
description: 'useDidUpdate Hook executed when the component updates its dependencies. ' | ||
Order: 4 | ||
--- | ||
|
||
## Usage | ||
|
||
useDidUpdate is identical to useEffect except that it ignores the first execution and only executes when dependencies are updated. | ||
|
||
```jsx live=true | ||
import React from 'react'; | ||
import { useDidUpdate } from '@kubed/hooks'; | ||
import { Button, Group } from '@kubed/components' | ||
|
||
export default function App() { | ||
const [counter, setCounter] = React.useState(0); | ||
const [updateCount, setUpdateCount] = React.useState(0); | ||
useDidUpdate(() => { | ||
setUpdateCount((updateCount) => updateCount + 1) | ||
}, [counter]); | ||
|
||
return ( | ||
<div> | ||
<p>counter:{counter}</p> | ||
<p>updateCount: {updateCount}</p> | ||
<Group spacing="xl"> | ||
<Button onClick={() => setCounter((counter) =>counter + 1 )}> counter +1 </Button> | ||
</Group> | ||
</div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
## API | ||
|
||
```tsx | ||
|
||
function useDidUpdate( | ||
fn: () => void, | ||
dependencies?: any[]): void | ||
``` |
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,37 @@ | ||
--- | ||
group: 'hooks' | ||
category: 'state' | ||
title: 'useForceUpdate' | ||
description: 'useForceUpdate will return a function, calling this function will force the component to re-render' | ||
Order: 2 | ||
--- | ||
|
||
## Usage | ||
|
||
useForceUpdate forces the component to re-render. | ||
|
||
```jsx live=true | ||
import React from 'react'; | ||
import { useForceUpdate } from '@kubed/hooks'; | ||
import { Button, Group } from '@kubed/components' | ||
|
||
export default function App() { | ||
const update = useForceUpdate(); | ||
|
||
return ( | ||
<div> | ||
<p>Time:{Date.now()}</p> | ||
<Group spacing="xl"> | ||
<Button onClick={() => update()}>update</Button> | ||
</Group> | ||
</div> | ||
); | ||
} | ||
|
||
``` | ||
|
||
## API | ||
|
||
```tsx | ||
function useForceUpdate(): () => void | ||
``` |
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
Oops, something went wrong.