github.com/minio/console@v1.4.1/web-app/src/screens/Console/Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper.tsx (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2021 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  import React, { Fragment } from "react";
    18  import { Button, CodeEditor, CopyIcon } from "mds";
    19  import CopyToClipboard from "react-copy-to-clipboard";
    20  import TooltipWrapper from "../../TooltipWrapper/TooltipWrapper";
    21  
    22  interface ICodeWrapper {
    23    value: string;
    24    label?: string;
    25    mode?: string;
    26    tooltip?: string;
    27    onChange: (value: string) => any;
    28    editorHeight?: string | number;
    29    helptip?: any;
    30  }
    31  
    32  const CodeMirrorWrapper = ({
    33    value,
    34    label = "",
    35    tooltip = "",
    36    mode = "json",
    37    onChange,
    38    editorHeight = 250,
    39    helptip,
    40  }: ICodeWrapper) => {
    41    return (
    42      <CodeEditor
    43        value={value}
    44        onChange={(value) => onChange(value)}
    45        mode={mode}
    46        tooltip={tooltip}
    47        editorHeight={editorHeight}
    48        label={label}
    49        helpTools={
    50          <Fragment>
    51            <TooltipWrapper tooltip={"Copy to Clipboard"}>
    52              <CopyToClipboard text={value}>
    53                <Button
    54                  type={"button"}
    55                  id={"copy-code-mirror"}
    56                  icon={<CopyIcon />}
    57                  color={"primary"}
    58                  variant={"regular"}
    59                />
    60              </CopyToClipboard>
    61            </TooltipWrapper>
    62          </Fragment>
    63        }
    64        helpTip={helptip}
    65        helpTipPlacement="right"
    66      />
    67    );
    68  };
    69  
    70  export default CodeMirrorWrapper;