-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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-infra] Move API pages to TS #43199
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7a04d93
Move API pages to TS
alexfauquette 4a74e29
work
alexfauquette 1ae9c7b
work
alexfauquette de93837
Merge remote-tracking branch 'upstream/next' into api-to-ts
alexfauquette d647677
migrate classes section to processors strategy
alexfauquette f29c6c7
clean up
alexfauquette a4ecdad
recreate the ToC generators
alexfauquette 2ce4e3c
fixes
alexfauquette 5c3031d
fix TS
alexfauquette 7aa7447
[docs-infra] Move Remaining API content to TS
alexfauquette 527d0d7
Merge remote-tracking branch 'upstream/next' into ts-other-pages
alexfauquette baf3eb3
remove uselees stuff
alexfauquette f6bf1c5
fixes
alexfauquette ef15bbc
fix imports
alexfauquette a82c250
move the missing tpe definition to the same package as others
alexfauquette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { PropsTranslations, ComponentApiContent } from '@mui-internal/api-docs-builder'; | ||
import { Translate } from '@mui/docs/i18n'; | ||
import kebabCase from 'lodash/kebabCase'; | ||
|
||
export interface ClassDefinition { | ||
className: string; | ||
key: string; | ||
hash: string; | ||
description?: string; | ||
isGlobal?: boolean; | ||
isDeprecated?: boolean; | ||
deprecationInfo?: string; | ||
} | ||
|
||
export type GetCssToCParams = { | ||
classes: ClassDefinition[]; | ||
t: Translate; | ||
hash?: string; | ||
}; | ||
|
||
export const getClassesToC = ({ classes, t, hash }: GetCssToCParams) => | ||
!classes || classes.length === 0 | ||
? [] | ||
: [ | ||
{ | ||
text: t('api-docs.classes'), | ||
hash: hash ?? 'classes', | ||
children: [ | ||
...classes.map(({ key, hash: classeHash }) => ({ | ||
text: key, | ||
hash: classeHash, | ||
children: [], | ||
})), | ||
], | ||
}, | ||
]; | ||
|
||
export interface ClassesApiProcessorParams { | ||
componentClasses: ComponentApiContent['classes']; | ||
classDescriptions: PropsTranslations['classDescriptions']; | ||
componentName: string; | ||
} | ||
|
||
export function classesApiProcessor(params: ClassesApiProcessorParams): ClassDefinition[] { | ||
const { componentClasses, classDescriptions, componentName } = params; | ||
|
||
return componentClasses.map((classDefinition) => { | ||
return { | ||
...classDefinition, | ||
description: | ||
classDescriptions[classDefinition.key]?.description | ||
?.replace(/{{conditions}}/, classDescriptions[classDefinition.key].conditions!) | ||
?.replace(/{{nodeName}}/, classDescriptions[classDefinition.key].nodeName!) ?? | ||
classDefinition.description, | ||
deprecationInfo: classDescriptions[classDefinition.key]?.deprecationInfo, | ||
hash: `${kebabCase(componentName)}-classes-${classDefinition.className}`, | ||
}; | ||
}); | ||
} |
182 changes: 182 additions & 0 deletions
182
docs/src/modules/components/ApiPage/processors/properties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import { PropsTableItem, PropsTranslations } from '@mui-internal/api-docs-builder'; | ||
import { Translate } from '@mui/docs/i18n'; | ||
import kebabCase from 'lodash/kebabCase'; | ||
import { | ||
HookApiContent, | ||
HooksTranslations, | ||
} from 'packages/api-docs-builder/types/ApiBuilder.types'; | ||
|
||
export interface PropertyDefinition { | ||
additionalInfo?: string[]; | ||
hash: string; | ||
deprecationInfo?: string; | ||
description?: string; | ||
isDeprecated?: boolean; | ||
isOptional?: boolean; | ||
isRequired?: boolean; | ||
propDefault?: string; | ||
propName: string; | ||
requiresRef?: boolean; | ||
seeMoreDescription?: string; | ||
signature?: string; | ||
signatureArgs?: { argName: string; argDescription?: string }[]; | ||
signatureReturnDescription?: string; | ||
typeName: string; | ||
/** | ||
* Used by MUI X interface documentation | ||
*/ | ||
isProPlan?: boolean; | ||
/** | ||
* Used by MUI X interface documentation | ||
*/ | ||
isPremiumPlan?: boolean; | ||
} | ||
|
||
export type GetCssToCParams = { | ||
properties: PropertyDefinition[]; | ||
inheritance?: boolean; | ||
themeDefaultProps?: boolean; | ||
t: Translate; | ||
hash?: string; | ||
}; | ||
|
||
export const getPropertiesToC = ({ | ||
properties, | ||
inheritance, | ||
themeDefaultProps, | ||
t, | ||
hash, | ||
}: GetCssToCParams) => ({ | ||
text: t('api-docs.props'), | ||
hash, | ||
children: [ | ||
...properties.map(({ propName, hash: propertyHash }) => ({ | ||
text: propName, | ||
hash: propertyHash, | ||
children: [], | ||
})), | ||
...(inheritance | ||
? [{ text: t('api-docs.inheritance'), hash: 'inheritance', children: [] }] | ||
: []), | ||
...(themeDefaultProps | ||
? [{ text: t('api-docs.themeDefaultProps'), hash: 'theme-default-props', children: [] }] | ||
: []), | ||
], | ||
}); | ||
|
||
interface PropsApiProcessorParams { | ||
componentName: string; | ||
properties: { | ||
[name: string]: PropsTableItem; | ||
}; | ||
propertiesDescriptions: PropsTranslations['propDescriptions']; | ||
/** | ||
* Add indicators that the properties is optional instead of showing it is required. | ||
*/ | ||
showOptionalAbbr?: boolean; | ||
} | ||
|
||
export function propsApiProcessor(params: PropsApiProcessorParams): PropertyDefinition[] { | ||
const { properties, propertiesDescriptions, componentName, showOptionalAbbr = false } = params; | ||
|
||
return Object.entries(properties).map(([propName, propData]) => { | ||
const isRequired = propData.required && !showOptionalAbbr; | ||
const isOptional = !propData.required && showOptionalAbbr; | ||
|
||
const isDeprecated = propData.deprecated; | ||
const deprecationInfo = propData.deprecationInfo; | ||
|
||
const typeName = propData.type?.description || propData.type.name; | ||
const propDefault = propData.default; | ||
const propDescription = propertiesDescriptions[propName]; | ||
|
||
const additionalInfo = ( | ||
['cssApi', 'sx', 'slotsApi', 'joy-size', 'joy-color', 'joy-variant'] as const | ||
).filter((key) => propData.additionalInfo?.[key]); | ||
|
||
const seeMoreDescription = | ||
propDescription?.seeMoreText && | ||
propData.seeMoreLink && | ||
propDescription.seeMoreText.replace( | ||
'{{link}}', | ||
`<a href="${propData.seeMoreLink.url}">${propData.seeMoreLink.text}</a>`, | ||
); | ||
|
||
const signature = propData.signature?.type; | ||
const signatureArgs = propData.signature?.describedArgs?.map((argName) => ({ | ||
argName, | ||
argDescription: propertiesDescriptions[propName].typeDescriptions?.[argName], | ||
})); | ||
const signatureReturnDescription = | ||
propData.signature?.returned && | ||
propertiesDescriptions[propName].typeDescriptions?.[propData.signature.returned]; | ||
|
||
return { | ||
hash: `${kebabCase(componentName)}-prop-${propName}`, | ||
propName, | ||
seeMoreDescription, | ||
description: propDescription?.description, | ||
requiresRef: propDescription?.requiresRef, | ||
isOptional, | ||
isRequired, | ||
isDeprecated, | ||
deprecationInfo, | ||
typeName, | ||
propDefault, | ||
additionalInfo, | ||
signature, | ||
signatureArgs, | ||
signatureReturnDescription, | ||
}; | ||
}); | ||
} | ||
|
||
// interface InterfaceApiProcessorParams {} | ||
|
||
// export function InterfaceApiProcessor(params: InterfaceApiProcessorParams): PropertyDefinition[] { | ||
// return []; | ||
// } | ||
|
||
interface HookCommonApiParams { | ||
hookName: string; | ||
} | ||
|
||
interface HookReturnApiProcessorParams extends HookCommonApiParams { | ||
kind: 'return'; | ||
properties: HookApiContent['returnValue']; | ||
translations: HooksTranslations['returnValueDescriptions']; | ||
} | ||
|
||
interface HookParametersApiProcessorParams extends HookCommonApiParams { | ||
kind: 'parameters'; | ||
properties: HookApiContent['parameters']; | ||
translations: HooksTranslations['parametersDescriptions']; | ||
} | ||
|
||
export function hookApiProcessor( | ||
params: HookReturnApiProcessorParams | HookParametersApiProcessorParams, | ||
): PropertyDefinition[] { | ||
const { properties, translations, hookName, kind } = params; | ||
|
||
return Object.entries(properties).map(([propName, propData]) => { | ||
const isOptional = !propData.required; | ||
|
||
const isDeprecated = propData.deprecated; | ||
const deprecationInfo = propData.deprecationInfo; | ||
|
||
const typeName = propData.type?.description || propData.type.name; | ||
const propDefault = propData.default; | ||
const propDescription = translations[propName]; | ||
|
||
return { | ||
hash: `${kebabCase(hookName)}-${kind === 'parameters' ? 'parameters' : 'return-value'}-${propName}`, | ||
propName, | ||
description: propDescription?.description, | ||
isOptional, | ||
isDeprecated, | ||
deprecationInfo, | ||
typeName, | ||
propDefault, | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PropsTranslations, ComponentApiContent } from '@mui-internal/api-docs-builder'; | ||
|
||
export type SlotDefinition = { | ||
className: string | null; | ||
hash: string; | ||
description?: string; | ||
name: string; | ||
defaultValue?: string; | ||
}; | ||
|
||
export interface SlotsApiProcessorParams { | ||
componentSlots: ComponentApiContent['slots']; | ||
slotDescriptions: PropsTranslations['slotDescriptions']; | ||
componentName: string; | ||
} | ||
|
||
export function slotsApiProcessor(params: SlotsApiProcessorParams): SlotDefinition[] { | ||
const { componentSlots, slotDescriptions, componentName } = params; | ||
|
||
if (!componentSlots) { | ||
return []; | ||
} | ||
return componentSlots.map(({ class: className, name, default: defaultValue }) => { | ||
return { | ||
description: slotDescriptions?.[name], | ||
className, | ||
name, | ||
defaultValue, | ||
hash: `${componentName}-css-${className ?? name}`, | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,8 +74,8 @@ export type ClassesSectionProps = ( | |
level?: 'h2' | 'h3' | 'h4'; | ||
defaultLayout: ApiDisplayOptions; | ||
layoutStorageKey: string; | ||
displayClassKeys: boolean; | ||
styleOverridesLink: string; | ||
displayClassKeys?: boolean; | ||
styleOverridesLink?: string; | ||
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The more you type pages, the more you fix inconsistencies 😅 |
||
}; | ||
|
||
export default function ClassesSection(props: ClassesSectionProps) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relative imports make more sense imo, but that's a little pet peeve of mine 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a post traumatic symptomes.
Did not took care of it so I've little context, but most of the files on
docs/modules
don't have a relative import because it was causing conflict when used in mui-x repo. Since mui-x and material-ui agree on the fact thedocs/
point to this folder (in mui-x thedocs
folder is aliaseddocsx
), every import start withdocs/