MCPcopy Create free account
hub / github.com/adobe/react-spectrum / VisualExample

Function VisualExample

packages/dev/s2-docs/src/VisualExample.tsx:115–239  ·  view source on GitHub ↗
({
  name,
  component,
  docs,
  links,
  importSource,
  props,
  initialProps,
  controlOptions,
  files,
  downloadFiles,
  code,
  wide,
  slots,
  align,
  acceptOrientation,
  type,
  propsObject,
  showCoachMark,
  hideShadcn
}: VisualExampleProps)

Source from the content-addressed store, hash-verified

113 * Displays a component example with controls for changing the props.
114 */
115export function VisualExample({
116 name,
117 component,
118 docs,
119 links,
120 importSource,
121 props,
122 initialProps,
123 controlOptions,
124 files,
125 downloadFiles,
126 code,
127 wide,
128 slots,
129 align,
130 acceptOrientation,
131 type,
132 propsObject,
133 showCoachMark,
134 hideShadcn
135}: VisualExampleProps) {
136 let componentProps = docs.type === 'interface' ? docs : docs.props;
137 if (componentProps?.type !== 'interface') {
138 return null;
139 }
140
141 // Filter down the list of controls from the TS docs to only the ones we want to display.
142 // This reduces the amount of data we need to send to the client.
143 let controls = Object.fromEntries(
144 props.map(name => {
145 let prop = componentProps.properties[name];
146 if (prop.type === 'method') {
147 throw new Error('Unexpected method in props.');
148 }
149
150 // Resolve the value type if it is a type alias.
151 if (prop.value?.type === 'link' && links?.[prop.value.id]) {
152 let value = links[prop.value.id];
153 if (value?.type === 'alias') {
154 value = value.value;
155 }
156 prop = {...prop, value};
157 }
158
159 // Try to parse the default value from the JSDocs as JSON.
160 let defaultValue = prop.default ?? undefined;
161 if (typeof defaultValue === 'string') {
162 defaultValue = defaultValue.replace(/^['"](.+)['"].*$/, '"$1"');
163 try {
164 defaultValue = json5.parse(defaultValue);
165 } catch {
166 // ignore
167 }
168 }
169
170 let renderedProp: PropControl = {
171 ...prop,
172 description: renderHTMLfromMarkdown(prop.description, {forceInline: true}),

Callers

nothing calls this directly

Calls 3

renderHTMLfromMarkdownFunction · 0.90
getFilesFunction · 0.90
parseMethod · 0.45

Tested by

no test coverage detected