import Asterisk from '../../../@react-spectrum/s2/ui-icons/Asterisk'; import {Code, styles as codeStyles} from './Code'; import {CSSVariables, StateTable} from './StateTable'; import {DisclosureRow} from './DisclosureRow'; import React from 'react'; import {renderHTMLfromMarkdown, setLinks, TComponent, TInterface, TType, Type} from './types'; import {style} from '@react-spectrum/s2/style' with {type: 'macro'}; import {Table, TableBody, TableCell, TableColumn, TableHeader, TableRow} from './Table'; export const PROP_GROUPS = { Content: [ 'children', 'items', 'defaultItems', 'columns', 'loadingState', 'onLoadMore', 'renderEmptyState', 'dependencies' ], Selection: [ 'selectionMode', 'selectionBehavior', 'selectedKeys', 'defaultSelectedKeys', 'selectedKey', 'defaultSelectedKey', 'onSelectionChange', 'disabledKeys', 'disabledBehavior', 'disallowEmptySelection', 'shouldSelectOnPressUp', 'shouldFocusWrap', 'shouldFocusOnHover', 'escapeKeyBehavior' ], Value: [ 'value', 'defaultValue', 'onChange', 'onChangeEnd', 'inputValue', 'defaultInputValue', 'onInputChange', 'formatOptions' ], Labeling: ['label', 'labelPosition', 'labelAlign', 'contextualHelp'], Validation: [ 'minValue', 'maxValue', 'step', 'minLength', 'maxLength', 'pattern', 'isRequired', 'isInvalid', 'validate', 'validationBehavior', 'validationErrors', 'necessityIndicator', 'description', 'errorMessage' ], Overlay: [ 'isOpen', 'defaultOpen', 'onOpenChange', 'shouldCloseOnSelect', 'placement', 'direction', 'align', 'shouldFlip', 'offset', 'crossOffset', 'containerPadding', 'menuWidth' ], Events: [/^on[A-Z]/], Links: [ 'href', 'hrefLang', 'target', 'rel', 'download', 'ping', 'referrerPolicy', 'itemProp', 'routerOptions' ], Styling: ['style', 'className'], Forms: [ 'name', 'startName', 'endName', 'value', 'formValue', 'type', 'autoComplete', 'form', 'formTarget', 'formNoValidate', 'formMethod', 'formMethod', 'formEncType', 'formAction' ], Accessibility: [ 'autoFocus', 'role', 'id', 'tabIndex', 'excludeFromTabOrder', 'preventFocusOnPress', /^aria-/ ], Advanced: ['UNSAFE_className', 'UNSAFE_style', 'slot', 'render'] }; export const DEFAULT_EXPANDED = new Set(['Content', 'Selection', 'Value']); const GROUPS = PROP_GROUPS; const codeStyle = style({font: {default: 'code-xs', lg: 'code-sm'}, wordBreak: 'break-word'}); interface PropTableProps { component: TComponent; links: any; showDescription?: boolean; hideRenderProps?: boolean; showOptionalRenderProps?: boolean; hideSelector?: boolean; cssVariables?: {[name: string]: string}; } export function PropTable({ component, links, showDescription, hideRenderProps, showOptionalRenderProps, hideSelector, cssVariables }: PropTableProps) { let properties = component?.props?.type === 'interface' ? component.props.properties : null; if (!properties) { return null; } let hasProps = Object.values(properties).filter( prop => prop.type === 'property' && prop.access !== 'private' && prop.access !== 'protected' ).length > 0; let defaultClassName = properties.className?.default?.slice(1, -1); let renderProps: TType | null = null; let renderPropProperty = properties.className || properties.children; if (!hideRenderProps && renderPropProperty?.type === 'property') { if (renderPropProperty.value.type === 'union') { let func = renderPropProperty.value.elements.find(e => e.type === 'function'); if (func) { renderProps = func.parameters[0]?.value; } } else if (renderPropProperty.value.type === 'application') { let application = renderPropProperty.value; if ( application.base.type === 'link' && /ClassNameOrFunction|ChildrenOrFunction/.test(links[application.base.id]?.name) ) { renderProps = application.typeParameters[0]; } } if (renderProps?.type === 'link') { renderProps = links[renderProps.id]; } } return ( <> {component.description && showDescription && (
{prop.name}
{!prop.optional && showRequired ? (
{prop.default}
) : (
'—'
)}
Default className: {defaultClassName}
); }