microsoft/typespec
Publicmirrored fromhttps://github.com/microsoft/typespecAvailable
packages/html-program-viewer/src/common.tsx
61lines · modecode
| 1 | import { css } from "@emotion/react"; |
| 2 | import { FunctionComponent, PropsWithChildren, ReactElement } from "react"; |
| 3 | import { Colors } from "./constants.js"; |
| 4 | |
| 5 | export interface ItemProps { |
| 6 | title: string; |
| 7 | id?: string; |
| 8 | hide?: boolean; |
| 9 | } |
| 10 | |
| 11 | const ItemStyles = css({ |
| 12 | border: "1px solid #c5c5c5", |
| 13 | }); |
| 14 | |
| 15 | const ItemTitleStyles = css({ |
| 16 | border: "1px solid #c5c5c5", |
| 17 | backgroundColor: "#dedede", |
| 18 | padding: "2px 5px", |
| 19 | }); |
| 20 | |
| 21 | const ItemContentStyles = css({ |
| 22 | padding: "1rem", |
| 23 | }); |
| 24 | |
| 25 | export const Item: FunctionComponent<PropsWithChildren<ItemProps>> = ({ |
| 26 | id, |
| 27 | title, |
| 28 | hide, |
| 29 | children, |
| 30 | }) => { |
| 31 | if (hide) { |
| 32 | return <div></div>; |
| 33 | } |
| 34 | return ( |
| 35 | <div css={ItemStyles} id={id}> |
| 36 | <div css={ItemTitleStyles}>{title}</div> |
| 37 | <div css={ItemContentStyles}>{children}</div> |
| 38 | </div> |
| 39 | ); |
| 40 | }; |
| 41 | |
| 42 | export const Literal: FunctionComponent<{ children: any }> = ({ children }) => ( |
| 43 | <div css={{ color: "#5da713", display: "inline" }}>{children}</div> |
| 44 | ); |
| 45 | |
| 46 | export const KeyValueSection: FunctionComponent<{ children: ReactElement | ReactElement[] }> = ({ |
| 47 | children, |
| 48 | }) => { |
| 49 | return ( |
| 50 | <ul |
| 51 | css={{ |
| 52 | margin: 0, |
| 53 | padding: "0 0 0 16px", |
| 54 | borderLeft: `1px dashed ${Colors.indentationGuide}`, |
| 55 | overflow: "auto", |
| 56 | }} |
| 57 | > |
| 58 | {children} |
| 59 | </ul> |
| 60 | ); |
| 61 | }; |
| 62 | |