/* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ import * as React from "react"; import { useStyletron } from "baseui"; import { StyledLink } from "baseui/link"; import { Input } from "baseui/input"; import { Radio, RadioGroup } from "baseui/radio"; import { Checkbox } from "baseui/checkbox"; import { Select, SIZE } from "baseui/select"; import { StatefulTooltip } from "baseui/tooltip"; import Editor from "./editor"; import type { TPropValue } from "react-view"; import { assertUnreachable, useValueDebounce, PropTypes, Error, } from "react-view"; const getTooltip = (description: string, type: string, name: string) => (

{name}: {type}

{description}

); const Spacing: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [css, theme] = useStyletron(); return (
{children}
); }; const Label: React.FC<{ children: React.ReactNode; tooltip: React.ReactNode; }> = ({ children, tooltip }) => { const [css, theme] = useStyletron(); return ( // eslint-disable-next-line jsx-a11y/label-has-associated-control ); }; const Knob: React.SFC<{ name: string; error: string | null; description: string; val: TPropValue; set: (val: TPropValue) => void; type: PropTypes; options?: { [key: string]: string }; placeholder?: string; enumName?: string; }> = ({ name, error, type, val: globalVal, set: globalSet, options = {}, description, placeholder, enumName, }) => { const [val, set] = useValueDebounce(globalVal, globalSet); const [css, theme] = useStyletron(); switch (type) { case PropTypes.Ref: return ( React Ref documentation ); case PropTypes.String: case PropTypes.Date: case PropTypes.Number: return ( set((event.target as HTMLInputElement).value)} placeholder={placeholder} size="compact" value={val ? String(val) : undefined} /> ); case PropTypes.Boolean: return ( { globalSet(!val); }} > {name} ); case PropTypes.Enum: // eslint-disable-next-line no-case-declarations const optionsKeys = Object.keys(options); // eslint-disable-next-line no-case-declarations const numberOfOptions = optionsKeys.length; // eslint-disable-next-line no-case-declarations const selectOptions = optionsKeys.map((key) => ({ id: key, option: options[key], })); // eslint-disable-next-line no-case-declarations const valueKey = val && String(val).split(".")[1]; return ( {numberOfOptions < 7 ? ( ({ flexWrap: "wrap", marginTop: 0, marginBottom: $theme.sizing.scale300, }), }, }} onChange={(e) => { globalSet((e.target as HTMLInputElement).value); }} value={String(val)} > {Object.keys(options).map((opt) => ( ({ marginRight: $theme.sizing.scale600, marginTop: 0, marginBottom: 0, }), }, Label: { style: ({ $theme }) => $theme.typography.font250, }, }} > {opt} ))} ) : (