Skip to content

Commit

Permalink
Docs: Pass dynamic prop condition description to PropTable component.
Browse files Browse the repository at this point in the history
  • Loading branch information
kitschpatrol committed Mar 7, 2024
1 parent a3fdffb commit 4be8169
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/src/components/docs/PropTable.astro
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ const {
Available when
{/* set:text below works around prettier */}
{Object.values(conditionData[prop.name])
.map((value) => (
<code set:text={`${Object.keys(value)[0]}="${Object.values(value)[0]}"`} />
.map(({ condition }) => (
<code
set:text={`${Object.keys(condition)[0]}="${Object.values(condition)[0]}"`}
/>
))
.reduce((previous, current) => [previous, ' or ', current])}
</td>
Expand Down
12 changes: 8 additions & 4 deletions docs/src/utils/prop-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import type { Props as StarlightProps } from '@astrojs/starlight/props';
export type ComponentData = StarlightProps['entry']['data']['componentData'];
export type ComponentProp = NonNullable<ComponentData>['props'][number];
export type Condition = NonNullable<
NonNullable<ComponentData>['dynamicProps']
>[number]['condition'];
export type Condition = Omit<
NonNullable<NonNullable<ComponentData>['dynamicProps']>[number],
'props'
>;
export type ConditionsRecord = Record<string, Condition[]>;

export function uniqueProps(
Expand All @@ -31,7 +32,10 @@ export function allPropConditions(data: ComponentData): ConditionsRecord {
conditionsRecord[prop.name] = [];
}

conditionsRecord[prop.name].push(dynamicProp.condition);
conditionsRecord[prop.name].push({
condition: dynamicProp.condition,
description: dynamicProp.description
});
}
}

Expand Down

0 comments on commit 4be8169

Please sign in to comment.