Skip to content

Commit

Permalink
Merge pull request #507 from 3YOURMIND/add-zod/improve-documentation-…
Browse files Browse the repository at this point in the history
…rendering-for-functions

add-zod(3): Improve Documentation Rendering for Functions
  • Loading branch information
carsoli committed Sep 22, 2021
2 parents b0d28ca + 355e8ba commit b36199f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/documentation/components/ComponentInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
style="font-style: italic"
v-text="'No default'"
/>
<code v-else v-text="stringifyDefault(prop.default)" />
<code v-else v-text="stringifyDefault(prop.default, prop.type)" />
</td>
<td>
<div style="display: flex; align-items: center">
Expand Down Expand Up @@ -130,7 +130,7 @@ import { Kotti } from '@3yourmind/kotti-ui'
import { Yoco } from '@3yourmind/yoco'
import { Dashes } from '@metatypes/typography'
import { computed, defineComponent, ref } from '@vue/composition-api'
import { kebabCase } from 'lodash'
import { castArray, kebabCase } from 'lodash'
import ComponentInfoSlots from './component-info/Slots.vue'
Expand Down Expand Up @@ -253,14 +253,21 @@ export default defineComponent<{
return result
}),
showProps: ref(false),
stringifyDefault: (defaultValue: (() => unknown) | unknown) =>
typeof defaultValue === 'function'
? `${JSON.stringify(defaultValue())} *`
: JSON.stringify(defaultValue),
stringifyDefault: (
defaultValue: (() => unknown) | unknown,
type: Array<VuePropType> | VuePropType,
) => {
if (typeof defaultValue === 'function')
if (castArray(type).some((t) => t.name === 'Function'))
return `${defaultValue.toString()} *`
else return `${JSON.stringify(defaultValue())} *`
return JSON.stringify(defaultValue)
},
stringifyType: (type: Array<VuePropType> | VuePropType) =>
Array.isArray(type)
? type.map((t) => t.name.toLowerCase()).join(' | ')
: type.name.toLowerCase(),
castArray(type)
.map((t) => t.name.toLowerCase())
.join(' | '),
Yoco,
}
},
Expand Down

0 comments on commit b36199f

Please sign in to comment.