Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs on how to reference generic components (#309) #310

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vitepress/theme/styles/style-guide.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@
.style-verb.avoid {
background-color: var(--vt-c-red);
}
.vt-doc summary {
width: fit-content;
cursor: pointer;
}
35 changes: 10 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/guide/components/v-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const emit = defineEmits(['update:modelValue'])

<template>
<input
:value="props.modelValue"
:value="modelValue"
@input="emit('update:modelValue', $event.target.value)"
/>
</template>
Expand Down
4 changes: 4 additions & 0 deletions src/guide/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ Zkontrolujte, že máte nainstalovanou nejnovější verzi [Node.js](https://nod
<VTCodeGroupTab label="yarn">

```sh
# For Yarn Modern (v2+)
$ yarn create vue@latest

# For Yarn ^v4.11
$ yarn dlx create-vue@latest
```

</VTCodeGroupTab>
Expand Down
4 changes: 4 additions & 0 deletions src/guide/scaling-up/tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ Pro zahájení práce s Vite + Vue jednoduše spusťte:
<VTCodeGroupTab label="yarn">

```sh
# For Yarn Modern (v2+)
$ yarn create vue@latest

# For Yarn ^v4.11
$ yarn dlx create-vue@latest
```

</VTCodeGroupTab>
Expand Down
35 changes: 35 additions & 0 deletions src/guide/typescript/composition-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,38 @@ import type { ComponentPublicInstance } from 'vue'

const child = ref<ComponentPublicInstance | null>(null)
```

In cases where the component referenced is a [generic component](/guide/typescript/overview.html#generic-components), for instance `MyGenericModal`:

```vue
<!-- MyGenericModal.vue -->
<script setup lang="ts" generic="ContentType extends string | number">
import { ref } from 'vue'

const content = ref<ContentType | null>(null)

const open = (newContent: ContentType) => (content.value = newContent)

defineExpose({
open
})
</script>
```

It needs to be referenced using `ComponentExposed` from the [`vue-component-type-helpers`](https://www.npmjs.com/package/vue-component-type-helpers) library as `InstanceType` won't work.

```vue
<!-- App.vue -->
<script setup lang="ts">
import MyGenericModal from './MyGenericModal.vue'

import type { ComponentExposed } from 'vue-component-type-helpers';

const modal = ref<ComponentExposed<typeof MyModal> | null>(null)

const openModal = () => {
modal.value?.open('newValue')
}
</script>
```