diff --git a/docs/markdown/use-toggle.en-US.md b/docs/markdown/use-toggle.en-US.md new file mode 100644 index 000000000..a7fd56997 --- /dev/null +++ b/docs/markdown/use-toggle.en-US.md @@ -0,0 +1,64 @@ +# useToggle + +### Intro + +Used to switch between `true` and `false`. + +## Usage + +### Basic Usage + +```js +import { useToggle } from '@vant/use'; + +export default { + setup() { + const [state, toggle] = useToggle(); + + toggle(true); + console.log(state.value); // -> true + + toggle(false); + console.log(state.value); // -> false + + toggle(); + console.log(state.value); // -> true + }, +}; +``` + +### Default Value + +```js +import { useToggle } from '@vant/use'; + +export default { + setup() { + const [state, toggle] = useToggle(true); + console.log(state.value); // -> true + }, +}; +``` + +## API + +### Type Declarations + +```ts +function useToggle( + defaultValue: boolean +): [Ref, (newValue: boolean) => void]; +``` + +### Params + +| Name | Description | Type | Default Value | +| ------------ | ------------- | --------- | ------------- | +| defaultValue | Default value | _boolean_ | `false` | + +### Return Value + +| Name | Description | Type | +| ------ | ------------------------ | ------------------------------ | +| state | State | _Ref\_ | +| toggle | Function to switch state | _(newValue?: boolean) => void_ | diff --git a/docs/markdown/vant-use-intro.en-US.md b/docs/markdown/vant-use-intro.en-US.md new file mode 100644 index 000000000..83057db6b --- /dev/null +++ b/docs/markdown/vant-use-intro.en-US.md @@ -0,0 +1,23 @@ +# Composables + +### Intro + +Vant provide some built-in composition APIs, you can directly use these APIs for development. + +### Demo + +```js +import { useWindowSize } from '@vant/use'; + +const { width, height } = useWindowSize(); + +console.log(width.value); // -> window width +console.log(height.value); // -> window height +``` + +### API List + +| Name | Description | +| --- | --- | +| [useCountDown](#/en-US/use-count-down) | Used to manage the countdown | +| [useToggle](#/en-US/use-toggle) | Used to switch between `true` and `false` | diff --git a/vant.config.js b/vant.config.js index 27607c8ae..5d905f11b 100644 --- a/vant.config.js +++ b/vant.config.js @@ -811,6 +811,51 @@ module.exports = { }, ], }, + { + title: 'Composables', + items: [ + { + path: 'vant-use-intro', + title: 'Intro', + }, + { + path: 'use-toggle', + title: 'useToggle', + }, + // { + // path: 'use-count-down', + // title: 'useCountDown', + // }, + // { + // path: 'use-rect', + // title: 'useRect', + // }, + // { + // path: 'use-event-listener', + // title: 'useEventListener', + // }, + // { + // path: 'use-page-visibility', + // title: 'usePageVisibility', + // }, + // { + // path: 'use-scroll-parent', + // title: 'useScrollParent', + // }, + // { + // path: 'use-window-size', + // title: 'useWindowSize', + // }, + // { + // path: 'use-relation', + // title: 'useRelation', + // }, + // { + // path: 'use-click-away', + // title: 'useClickAway', + // }, + ], + }, ], }, },