microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
61ba17d2d29dedf4553b21a055aa6b442a304688

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/html-program-viewer/src/type-ui-base.tsx

59lines · modecode

1import { css } from "@emotion/react";
2import { Type } from "@typespec/compiler";
3import { FunctionComponent } from "react";
4import { KeyValueSection } from "./common.js";
5import { Colors } from "./constants.js";
6import { getIdForType } from "./utils.js";
7
8export interface TypeUIBaseProperty {
9 name: string;
10 value: any;
11 description?: string;
12}
13
14export interface TypeUIBaseProps {
15 type: Type;
16 name: string;
17 /**
18 * Alternate id
19 * @default getIdForType(type)
20 */
21 id?: string;
22 properties: TypeUIBaseProperty[];
23}
24
25const TypeNameStyles = css({
26 display: "inline",
27 color: "#333333",
28});
29
30export const TypeUIBase: FunctionComponent<TypeUIBaseProps> = (props) => {
31 const id = props.id ?? getIdForType(props.type);
32 const properties = props.properties.map((prop) => {
33 return (
34 <li key={prop.name}>
35 <span css={{ color: "#9c5d27" }} title={prop.description}>
36 {prop.name}
37 </span>
38 : <span>{prop.value}</span>
39 </li>
40 );
41 });
42 return (
43 <div>
44 <div id={id}>
45 <span
46 css={{
47 display: "inline",
48 color: Colors.typeKind,
49 marginRight: "5px",
50 }}
51 >
52 {props.type.kind}
53 </span>
54 <span css={TypeNameStyles}>{props.name}</span>
55 </div>
56 <KeyValueSection>{properties}</KeyValueSection>
57 </div>
58 );
59};
60