1e0277979SBartosz Kaszubowskiimport { css } from '@emotion/react'; 2299f02f2SBartosz Kaszubowski 3299f02f2SBartosz Kaszubowskiimport { EnumDefinitionData, EnumValueData } from '~/components/plugins/api/APIDataTypes'; 425b16883SBartosz Kaszubowskiimport { APISectionDeprecationNote } from '~/components/plugins/api/APISectionDeprecationNote'; 5b3bd70ceSTomasz Sapetaimport { APISectionPlatformTags } from '~/components/plugins/api/APISectionPlatformTags'; 6c4c6b9d1SBartosz Kaszubowskiimport { 7c4c6b9d1SBartosz Kaszubowski CommentTextBlock, 8c4c6b9d1SBartosz Kaszubowski getTagNamesList, 9c4c6b9d1SBartosz Kaszubowski STYLES_APIBOX, 1012abeb84SBartosz Kaszubowski STYLES_APIBOX_NESTED, 11a16a3d18SBartosz Kaszubowski H3Code, 12c4c6b9d1SBartosz Kaszubowski} from '~/components/plugins/api/APISectionUtils'; 133324c13cSBartosz Kaszubowskiimport { H2, H4, CODE, MONOSPACE } from '~/ui/components/Text'; 14299f02f2SBartosz Kaszubowski 15299f02f2SBartosz Kaszubowskiexport type APISectionEnumsProps = { 16299f02f2SBartosz Kaszubowski data: EnumDefinitionData[]; 17299f02f2SBartosz Kaszubowski}; 18299f02f2SBartosz Kaszubowski 1942175e80SBartosz Kaszubowskiconst sortByValue = (a: EnumValueData, b: EnumValueData) => { 205990cc31SBartosz Kaszubowski if (a.type && a.type.value !== undefined && b.type && b.type.value !== undefined) { 215990cc31SBartosz Kaszubowski if (typeof a.type.value === 'string' && typeof b.type.value === 'string') { 225990cc31SBartosz Kaszubowski return a.type.value.localeCompare(b.type.value); 235990cc31SBartosz Kaszubowski } else if (typeof a.type.value === 'number' && typeof b.type.value === 'number') { 245990cc31SBartosz Kaszubowski return (a.type.value ?? Number.MIN_VALUE) - (b.type.value ?? Number.MIN_VALUE); 2542175e80SBartosz Kaszubowski } 2642175e80SBartosz Kaszubowski } 2742175e80SBartosz Kaszubowski return 0; 2842175e80SBartosz Kaszubowski}; 2942175e80SBartosz Kaszubowski 305990cc31SBartosz Kaszubowskiconst renderEnumValue = (value: any) => (typeof value === 'string' ? `"${value}"` : value); 315990cc31SBartosz Kaszubowski 32299f02f2SBartosz Kaszubowskiconst renderEnum = ({ name, children, comment }: EnumDefinitionData): JSX.Element => ( 336a5c065cSBartosz Kaszubowski <div key={`enum-definition-${name}`} css={[STYLES_APIBOX, enumContentStyles]}> 3425b16883SBartosz Kaszubowski <APISectionDeprecationNote comment={comment} /> 35d9bd5b6cSBartosz Kaszubowski <APISectionPlatformTags comment={comment} prefix="Only for:" /> 36c4c6b9d1SBartosz Kaszubowski <H3Code tags={getTagNamesList(comment)}> 373324c13cSBartosz Kaszubowski <MONOSPACE weight="medium">{name}</MONOSPACE> 38299f02f2SBartosz Kaszubowski </H3Code> 3925b16883SBartosz Kaszubowski <CommentTextBlock comment={comment} includePlatforms={false} /> 4042175e80SBartosz Kaszubowski {children.sort(sortByValue).map((enumValue: EnumValueData) => ( 4112abeb84SBartosz Kaszubowski <div css={[STYLES_APIBOX, STYLES_APIBOX_NESTED]} key={enumValue.name}> 4207ffa84cSBartosz Kaszubowski <APISectionDeprecationNote comment={enumValue.comment} /> 43d9bd5b6cSBartosz Kaszubowski <APISectionPlatformTags comment={enumValue.comment} prefix="Only for:" /> 44a16a3d18SBartosz Kaszubowski <H4 css={enumValueNameStyle}> 4512abeb84SBartosz Kaszubowski <CODE>{enumValue.name}</CODE> 46a16a3d18SBartosz Kaszubowski </H4> 47*234e070fSBartosz Kaszubowski <CODE theme="secondary" className="mb-4"> 485990cc31SBartosz Kaszubowski {`${name}.${enumValue.name} = ${renderEnumValue(enumValue.type.value)}`} 4912abeb84SBartosz Kaszubowski </CODE> 506a5c065cSBartosz Kaszubowski <CommentTextBlock comment={enumValue.comment} includePlatforms={false} /> 516a5c065cSBartosz Kaszubowski </div> 52299f02f2SBartosz Kaszubowski ))} 53299f02f2SBartosz Kaszubowski </div> 54299f02f2SBartosz Kaszubowski); 55299f02f2SBartosz Kaszubowski 56558a63feSBartosz Kaszubowskiconst APISectionEnums = ({ data }: APISectionEnumsProps) => 57299f02f2SBartosz Kaszubowski data?.length ? ( 58299f02f2SBartosz Kaszubowski <> 59299f02f2SBartosz Kaszubowski <H2 key="enums-header">Enums</H2> 60299f02f2SBartosz Kaszubowski {data.map(renderEnum)} 61299f02f2SBartosz Kaszubowski </> 62299f02f2SBartosz Kaszubowski ) : null; 63299f02f2SBartosz Kaszubowski 646a5c065cSBartosz Kaszubowskiconst enumValueNameStyle = css({ 65504f93b3SBartosz Kaszubowski h4: { 66504f93b3SBartosz Kaszubowski marginTop: 0, 67504f93b3SBartosz Kaszubowski }, 686a5c065cSBartosz Kaszubowski}); 696a5c065cSBartosz Kaszubowski 706a5c065cSBartosz Kaszubowskiconst enumContentStyles = css({ 7112abeb84SBartosz Kaszubowski paddingBottom: 0, 726a5c065cSBartosz Kaszubowski}); 736a5c065cSBartosz Kaszubowski 74299f02f2SBartosz Kaszubowskiexport default APISectionEnums; 75