diff --git a/doc/contributing/automatic_documentation.md b/doc/contributing/automatic_documentation.md index 5144d6aedc047ca6bd912cb2b45478a0bddba96e..1228ab6fd7f082f7b4cf7ea92fcc8e734326aaf0 100644 --- a/doc/contributing/automatic_documentation.md +++ b/doc/contributing/automatic_documentation.md @@ -1,8 +1,8 @@ # Automatic documentation -We have automated as much of our documentation as possible (for example props, inherited props, links to underlying documentation, etc.) and kept manual tasks (for example name of vue-bootstrap component, slot descriptions, etc.) to an absolute minimum. The target for our documentation components and exports is to have them automatically integrated into the [GitLab Design System](https://design.gitlab.com), also known as Pajamas. The main component for documentation is called `component_documentation_generator.vue`. +We have automated as much of our documentation as possible (for example props, inherited props, `v-model`, links to underlying documentation, etc.) and kept manual tasks (for example name of vue-bootstrap component, slot descriptions, etc.) to an absolute minimum. The target for our documentation components and exports is to have them automatically integrated into the [GitLab Design System](https://design.gitlab.com), also known as Pajamas. The main component for documentation is called `component_documentation_generator.vue`. -### Component documentation info +## Component documentation info To add additional information to our documentation page we are using extra files which hold additional information, those have the format `(component).documentation.js` in the component directory. The following sample has a sample documentation attribute with all possibilities. All of these properties are optional. @@ -43,4 +43,9 @@ export default { }, ] }; -``` \ No newline at end of file +``` + +## v-model + +`v-model` information is automatically added to component documentation if the component +defines a [`model`](https://vuejs.org/v2/api/#model). diff --git a/documentation/components/component_documentation_generator.vue b/documentation/components/component_documentation_generator.vue index f055bc7fa3937b49e9a52c2863a3d6e84e69ccec..443fb39a9ddf03020d4591b5cc8672cfc0e356ff 100644 --- a/documentation/components/component_documentation_generator.vue +++ b/documentation/components/component_documentation_generator.vue @@ -15,6 +15,7 @@ import { getValidationInfoText } from '../../src/utils/validation_utils'; import { gitlabComponents, gitlabChartComponents, componentValidator } from '../all_components'; import GlTable from '../../src/components/base/table/table.vue'; +import GlBadge from '../../src/components/base/badge/badge.vue'; import { getDocumentationFor } from '../components_documentation'; @@ -43,6 +44,7 @@ function getPropDefaultValue(defaultValue) { export default { components: { GlTable, + GlBadge, }, props: { componentName: { @@ -68,6 +70,19 @@ export default { actualComponentOptions() { return this.actualComponent.options || {}; }, + componentVModel() { + const { model } = this.actualComponentOptions; + + if (!model) { + return null; + } + + return { + prop: 'value', + event: 'input', + ...model, + }; + }, documentationInfo() { return getDocumentationFor(this.componentName); }, @@ -136,7 +151,23 @@ export default { return returnProps; }, displayEvents() { - return this.documentationInfo.events || []; + const events = this.documentationInfo.events || []; + if (this.componentVModel) { + const vModelEventIndex = events.findIndex( + ({ event }) => event === this.componentVModel.event + ); + if (vModelEventIndex === -1) { + events.push({ + event: this.componentVModel.event, + args: [ + { + arg: this.componentVModel.prop, + }, + ], + }); + } + } + return events; }, displaySlots() { return this.documentationInfo.slots || []; @@ -197,9 +228,15 @@ export default { >