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
Can I use composition API? #679
Comments
Hi @ozum, Great question. A short answer would be: No, but we want to. With the new composition API, explicitly specified props are still valid and useful. Those will work with styleguidist today. Do you have an example of what component you would like to parse and document? |
@elevatebart, thanks for the answer. I know, it is too early to ask for composition API support, but great to hear it's on your roadmap.
Currently not, I'm adopting to new API slowly, and trying to design a workflow for it. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions. |
I'm interested in vue-styleguidist working with Vue composition API. I have it working nicely with Storybook creating the documentation for me, but it's only picking up props and slots, not any properties provided in the Here is a basic button component using composition API and Typescript. <script lang="ts">
import { defineComponent, SetupContext } from "@vue/composition-api";
interface IProps {
rounded: Boolean;
disabled: Boolean;
whiteText: Boolean;
}
export default defineComponent({
props: {
/**
* Rounded edges
*/
rounded: {
type: Boolean,
default: false,
},
/**
* Disabled button
*/
disabled: {
type: Boolean,
default: false,
},
/**
* Whether or not the text is white
*/
whiteText: {
type: Boolean,
default: false,
},
},
setup(props: IProps, context: SetupContext) {
/**
* My clicked event
*/
const clicked: (arg0: MouseEvent) => void = (e) => {
context.emit("clicked", e);
};
return {
clicked,
};
},
});
</script>
<template>
<button :class="{ white: whiteText, rounded }" :disabled="disabled" @click="clicked">
<!-- @slot The text shown inside the button -->
<slot />
</button>
</template>
<style lang="scss" scoped>
button.white {
color: white;
}
button.rounded {
border-radius: 10px;
}
</style> |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions. |
In this case vue-styleguidist detects all props but not the event. |
This allows components written using the composition API to have events emitted via their setup functions be documented. closes vue-styleguidist#679
For the docgen-api, are there plans to more specifically parse the contents the setup() function if a component is using it? export default {
name: 'LoadingSkeleon',
props: {
show: {
type: Boolean,
required: false,
default: false
}
},
setup (props, { emit}) {
/**
* Number of loading cards (skeletons) to show while fetching data
* to populate component
* @type {number}
*/
const loadingCardsCount = 3
return { loadingCardsCount }
}
} |
Hi @Mootook What is the expected output in this case of vue-docgen-api for this component? I really am interested. |
@elevatebart To be a honest, I'm not quite sure. I don't have extensive experience with creating documented components, just jsdoc for productivity and intellisense purposes. This question probably has bigger implications though for the vue3's usage of composable functions, which I don't have a clear thought on as I store all of my reusable state logic in 'src/composables'. A component with a setup() then, for example: setup(props) {
const { isFetchingData, toggleIsFetchingData } = useDataFetch()
return { isFetchingData, toggleIsFetchingData }
} I would expect to make some reference to its use of the data fetch composable. By storing the toggleIsFetchingData() in methods array, or grouping this stuff in a |
+1 @Mootook The solution could be to render pure JSDoc/TSDoc alongside rendered components. We could have a list of exposed composable objects on the side that are rendered in the same website. For now, though, the vue 3 version of styleguidist is in a pickle because of the use of JSX. |
@elevatebart I think keeping data private/internal is better but that may just be for my use case. That solution seems nice, in my opinion. Ah yea, I remember seeing an issue about that somewhere. Could you link the issue if you get a chance? I can't seem to find it or remember what repo it was opened in. |
In the case of using new syntax <script setup> vue-docgen-api doesn't work at all. Are there any solutions to this problem? |
@RDMStreet could you make this claim a little more concrete? This syntax should work naturally without changes: I know this proposal is still in flux. If I start implementing it immediately, it may force the VueJs core team into bad decisions. If you want things to go a little faster, please start working on a proposal for what the props extraction should look like. Maybe starting with this: |
@Mootook the issue about JSX was open on vue-next : vuejs/core#1033 |
@elevatebart the current implementation of script setup (https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md#declaring-props-and-emits) uses <script setup>
const props = defineProps({
/**
* the first prop for the component
*/
propOne: {
type: String,
default: 'one'
}
})
// ... code that uses `props`
</script> It seems that |
There are plans to support this but time is a commodity that young/first fatherhood tends to rarify. |
@elevatebart congratulations! I'd love to write a PR for this but the sheer complexity of the codebase is daunting. Nevertheless, I'll get on it soon and will definitely request for help if I'm stuck. Thanks for the amazing work you've done on this project. |
Any updates on this?? |
The composition API is supported since version 4.44.0. We can document |
Can support @vue/composition-api? My code is like this. <script>
import { defineComponent } from "@vue/composition-api";
const name = "MyButton";
const props = {
text: { type: String },
}
export default defineComponent({
name,
props,
setup(props, { emit }) {
return {
btnClick: () => {
emit("btnClick", this.text);
},
};
},
});
</script> Now, when i use vue-docgen-api, i can not get the name, props and event. |
Hello @Juliiii , You are right! If you write the same code the way below, props and name will be recognized: <script>
import { defineComponent } from "@vue/composition-api";
export default defineComponent({
name: "MyButton",
props: {
text: { type: String },
},
setup(props, { emit }) {
return {
btnClick: () => {
emit("btnClick", this.text);
},
};
},
});
</script> I hope this helps ! |
is there any update on this? |
你好!我已经收到你的邮件,我会尽快回复你的~
|
Hi,
Can I use vue-styleguidist with composition API?
Thanks,
The text was updated successfully, but these errors were encountered: