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

docs(BButtonGroup): update component references #1580

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions apps/docs/.vitepress/theme/Layout.vue
Expand Up @@ -695,6 +695,17 @@ watch(
}
}

.table-hover > tbody > .custom-row:hover > * {
--bs-table-hover-bg: transparent;
}

.table .custom-row {
td {
font-weight: bold !important;
color: #000 !important;
}
}

// Code Block
[data-bs-theme='dark'] {
.vp-code-light {
Expand Down
58 changes: 33 additions & 25 deletions apps/docs/src/components/ComponentReference.vue
Expand Up @@ -45,6 +45,7 @@
<BTable
:items="component[sectionToComponentItem(section)]"
:fields="fields[sectionToComponentItem(section)]"
:tbody-tr-class="(item) => (item.isParent ? 'custom-row' : undefined)"
hover
small
responsive
Expand Down Expand Up @@ -105,37 +106,44 @@ import type {

const props = defineProps<{data: ComponentReference[]}>()

const sortItems = ({
arr,
name,
}:
| {arr: ComponentReference['props']; name: 'prop'}
| {arr: ComponentReference['emits']; name: 'event'}
| {arr: ComponentReference['slots']; name: 'name'}) => {
const withoutChild: ComponentReference['props'] = []
const withChild: ComponentReference['props'] = []

// Use for...of loop instead of forEach
arr.forEach((obj) => {
if (obj.children) {
withChild.push(obj)
} else {
withoutChild.push(obj)
}
})

withoutChild.sort((a, b) => (a[name] as string).localeCompare(b[name]))

withChild.sort((a, b) => a[name].localeCompare(b[name]))

return [...withoutChild, ...withChild]
}

/**
* Sorts the items inside so they're uniform structure
*/
const sortData = computed(() =>
[...props.data].map((el: ComponentReference): ComponentReference => {
const data: ComponentReference = {
component: el.component,
props: el.props
.map((inner) => ({
prop: inner.prop,
type: inner.type,
default: inner.default,
description: inner.description,
}))
.sort((a, b) => a.prop.localeCompare(b.prop)),
emits: el.emits
.map((inner) => ({
event: inner.event,
description: inner.description,
// Does not render inner object correctly
args: inner.args,
}))
.sort((a, b) => a.event.localeCompare(b.event)),
slots: el.slots
.map((inner) => ({
name: inner.name,
description: inner.description,
// Does not render inner object correctly
scope: inner.scope,
}))
.sort((a, b) => a.name.localeCompare(b.name)),
props: sortItems({arr: el.props, name: 'prop'}).flatMap((x) =>
!x?.children ? x : [{prop: x?.prop, type: x?.type, isParent: true}, ...x.children]
),
emits: el.emits.sort((a, b) => a.event.localeCompare(b.event)),
slots: el.slots.sort((a, b) => a.name.localeCompare(b.name)),
}

data.sections = (['Properties', 'Events', 'Slots'] as ComponentSection[]).filter(
Expand All @@ -158,5 +166,5 @@ const fields: {[P in ComponentItem]: TableField[]} = {
}

const normalizeDefault = (val: unknown) =>
val === undefined || val === null ? `${val}` : typeof val === 'string' ? `'${val}'` : val
val === null ? `${val}` : typeof val === 'string' ? `'${val}'` : val
</script>
3 changes: 3 additions & 0 deletions apps/docs/src/data/components/ComponentReference.ts
Expand Up @@ -10,16 +10,19 @@ export interface ComponentReference {
type: string
description?: string
default?: unknown
children?: Omit<ComponentReference['props'][number], 'children'>[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way would be to extend the entire props list at once. Rather than declaring a prop a child of something else. Then just using the entire list

Of course, you will need to omit the real values, you can probably reuse the util -- its called omit. I think its in object.ts

Something like

props: [],
parentProps: {
  BLink: omit(BLinkProps, ['event', '/* some other omitted props*/]),
  SomeOtherFakeComponent: ... // and so on
}

You can then use Object.entries and whatnot. The parentProps is probably something like Record<string, PropsReference> where you'd need to extract the stuff from "props" into its own type

}[]
emits: {
event: string
args: EmitArgReference[]
description?: string
children?: Omit<ComponentReference['emits'][number], 'children'>[]
}[]
slots: {
scope: SlotScopeReference[]
name: string
description?: string
children?: Omit<ComponentReference['slots'][number], 'children'>[]
}[]
sections?: ComponentSection[]
}