nodejs 014: React.FC 与 Evergreen(常青树) React UI 框架的的Dialog组件

news2024/9/27 5:53:38

React.FC

  • React.FC是React中用于定义函数组件“Function Component”的类型。它代表,可以帮助你在TypeScript中提供类型检查和自动补全。使用React.FC时,可以明确指定组件的props类型,并且它会自动推导children属性。下面是一个使用 React.FC 定义函数组件的示例:
import React from 'react';

interface MyComponentProps {
  title: string;
  count: number;
}

// 用React.FC声明一个函数组件
const MyComponent: React.FC<MyComponentProps> = ({ title, count, children }) => {
  return (
    <div>
      <h1>{title}</h1>
      <p>Count: {count}</p>
      {children}
    </div>
  );
};

// 使用示例
const App: React.FC = () => {
  return (
    <MyComponent title="Hello World" count={5}>
      <p>This is a child element!</p>
    </MyComponent>
  );
};

export default App;
  • 使用效果:
    在这里插入图片描述

Evergreen(常青树) 的Dialog组件声明

  • Evergreen代码中export declare const Dialog: React.FC<DialogProps> 定义了一个 React 函数组件 Dialog,该组件使用 DialogProps 接口定义的属性。这使得开发者在使用该组件时,可以根据需要传入相应的属性,以实现不同的功能和样式。

在这里插入图片描述

// 这段代码定义了一个 TypeScript 接口 `DialogProps`,它描述了一个对话框(Dialog)组件的所有可配置属性。
export interface DialogProps {
  // children: 可以是字符串、React 节点或一个接受 `{ close }` 参数的函数。若为字符串,则用 `<Paragraph />` 包裹
  children?: React.ReactNode | (({ close }: { close: () => void }) => void)
  
  // The intent of the Dialog. Used for the button. Defaults to none.
  intent?: IntentTypes
  
  // 一个布尔值,指示对话框是否显示。默认为 `false`
  isShown?: boolean
  
  // 对话框的标题 Title of the Dialog. Titles should use Title Case.
  title?: React.ReactNode
  
  // When true, the header with the title and close icon button is shown.Defaults to true.
  hasHeader?: boolean
  
  // 自定义的头部内容,可以是 React 节点或接受 `{ close }` 参数的函数。
  header?: React.ReactNode | (({ close }: { close: () => void }) => void)
  
  // When true, the footer with the cancel and confirm button is shown.Defaults to true
  hasFooter?: boolean
  
  // You can override the default footer with your own custom component.
  footer?: React.ReactNode | (({ close }: { close: () => void }) => void)
  
  // When true, the cancel button is shown. Defaults to true.
  hasCancel?: boolean
  
  // When true, the close button is shown. Defaults to true.
  hasClose?: boolean
  
  // 当退出过渡完成时调用的函数。
  onCloseComplete?: () => void
  
  // **onOpenComplete**: 当进入过渡完成时调用的函数。
  onOpenComplete?: () => void
  
  // **onConfirm**: 当确认按钮被点击时调用的函数,传入一个 `close` 函数,默认行为是关闭对话框。
  onConfirm?: (close: () => void) => void
  
  // **confirmLabel**: 确认按钮的标签,默认为“Confirm”。
  confirmLabel?: string
  
  // When true, the confirm button is set to loading. Defaults to false.
  isConfirmLoading?: boolean
  
  // When true, the confirm button is set to disabled. Defaults to false.
  isConfirmDisabled?: boolean
  
  // Function that will be called when the cancel button is clicked.This closes the Dialog by default./
  onCancel?: (close: () => void) => void
  
  // **cancelLabel**: 取消按钮的标签,默认为“Cancel”。
  cancelLabel?: string
  
  // Boolean indicating if clicking the overlay should close the overlay.Defaults to true.
  shouldCloseOnOverlayClick?: boolean
  
  // Boolean indicating if pressing the esc key should close the overlay.Defaults to true.
  shouldCloseOnEscapePress?: boolean
  
  // Width of the Dialog.
  width?: string | number
  
  // The space above the dialog. 
  topOffset?: string | number
  
  // The space on the left/right sides of the dialog when there isn't enough horizontal space available on screen.
  sideOffset?: string | number
  
  // The min height of the body content.Makes it less weird when only showing little content.
  minHeightContent?: string | number
  
  // Props that are passed to the dialog container.
  containerProps?: React.ComponentProps<typeof Pane>
  
  // Props that are passed to the content container.
  contentContainerProps?: React.ComponentProps<typeof Pane>
  
  // Whether or not to prevent scrolling in the outer body. Defaults to false.
  preventBodyScrolling?: boolean
}

export declare const Dialog: React.FC<DialogProps>

Dialog组件示例代码

  • https://evergreen.segment.com/components/dialog

在这里插入图片描述

import React from "react";
import ReactDOM from "react-dom";
import { Pane, Dialog, Button } from "evergreen-ui";

function DefaultDialogExample() {
  //使用数组解构赋值来定义一个状态变量和更新函数
  const [isShown, setIsShown] = React.useState(false);

  return (
    <Pane>
      <Dialog
        isShown={isShown}
        title="Dialog title"
        onCloseComplete={() => {
          setIsShown(false);
        }}
        confirmLabel="Custom Label"
      >
        Dialog content
      </Dialog>

      <Button
        onClick={() => {
          setIsShown(true);
        }}
      >
        Show Dialog
      </Button>
    </Pane>
  );
}

ReactDOM.render(<DefaultDialogExample />, document.getElementById("root"));

CG

  • UI-Box是一个基于React的低级别组件库。Evergreen(常青树) 的Button等组件通过BoxComponent实现,代码需要 import { extractStyles as boxExtractStyles, BoxProps, BoxComponent, PolymorphicBoxProps } from 'ui-box'

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2169102.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

微服务-- Gateway服务网关

Spring Cloud Gateway 是 Spring Cloud 的一个全新项目&#xff0c;该项目是基于 Spring 5.0&#xff0c;Spring Boot 2.0 和 Project Reactor 等响应式编程和事件流技术开发的网关&#xff0c;它旨在为微服务架构提供一种简单有效的统一的 API 路由管理方式。 为什么需要网关…

从0开始linux(5)——vim

欢迎来到博主的专栏&#xff1a;从0开始linux 博主ID&#xff1a;代码小豪 文章目录 vim的多种模式底行模式命令命令模式视块模式&#xff08;visual block&#xff09; vim的配置 vim是linux系统的文本编辑器。就像windows的记事本一样。 使用vim指令可以使用vim打开一个文本文…

MacOS多桌面调度快捷键

单桌面调度快捷键 可能是我用着妙控鼠标用着不习惯&#xff0c;所以追求快捷键操作&#xff0c;看起来也比较酷。而且在Windows上&#xff0c;我基本不使用多桌面&#xff0c;但是看着同事用Mac的多桌面用的飞起&#xff0c;炫酷程度不亚于win7的Windows键Tab。在不使用多桌面的…

小川科技携手阿里云数据库MongoDB:数据赋能企业构建年轻娱乐生态

随着信息技术的飞速发展&#xff0c;企业在处理海量数据时所面临的挑战日益严峻。特别是在年轻娱乐领域&#xff0c;用户行为的多样性和数据量的激增对数据存储与分析技术提出了更高的要求。在此背景下&#xff0c;小川凭借其前瞻性的技术视野&#xff0c;选择了MongoDB作为其数…

乒乓buffer(国科微笔试填空)_2024年9月26日

乒乓buffer是否提高了并行度&#xff1f;是 流水线式处理&#xff0c;提高并行度 位宽为4&#xff0c;深度为8的sram&#xff1a; 当sel拉高时&#xff0c;a、b模块在wren和rden有效时分别写和读&#xff1b;当sel拉低时&#xff0c;a、b模块在rdenwren有效时分别读和写

远程访问软路由

远程访问软路由主要涉及通过互联网从远程位置访问和控制基于软件的路由器系统。以下是远程访问软路由的一般方法&#xff1a; 一、远程访问软路由的方法 通过Web管理界面访问&#xff1a; 适用于大多数支持Web管理的软路由系统。用户只需在浏览器中输入软路由的公网IP地址或域…

【C语言】手把手带你拿捏指针(完)(指针笔试、面试题解析)

文章目录 一、sizeof和strlen的对⽐1.sizeof2.strlen3.sizeof与strlen对比 二、数组和指针笔试解析1.一维数组2.字符、字符串数组和字符指针代码1代码2代码3代码4代码5代码6 3.二维数组4.总结 三、指针运算笔试题解析代码1代码2代码3代码4代码5代码6 一、sizeof和strlen的对⽐ …

freeRDP OPenssl

libusb需要下载 我使用的是VS2019编译 所以需要include 与vs2019 在cmake里面修改路径 C:/Users/JPM/source/repos/freeRDP/FreeRDP-stable-2.0/libusb-1.0.24/include/libusb-1.0 C:/Users/JPM/source/repos/freeRDP/FreeRDP-stable-2.0/libusb-1.0.24/VS2019/MS64/static/l…

【中级通信工程师】终端与业务(四):通信产品

【零基础3天通关中级通信工程师】 终端与业务(四)&#xff1a;通信产品 本文是中级通信工程师考试《终端与业务》科目第四章《通信产品》的复习资料和真题汇总。终端与业务是通信考试里最简单的科目&#xff0c;有效复习通过率可达90%以上&#xff0c;本文结合了高频考点和近几…

计算机毕业设计PySpark+Django深度学习游戏推荐系统 游戏可视化 游戏数据分析 游戏爬虫 Scrapy 机器学习 人工智能 大数据毕设

本论文的主要研究内容如下&#xff1a; 了解基于Spark的TapTap游戏数据分析系统的基本架构&#xff0c;掌握系统的开发方法&#xff0c;包括系统开发基本流程、开发环境的搭建、测试与运行等。 主要功能如下&#xff1a; &#xff08;1&#xff09;用户管理模块&#xff1a;…

OpenCV图像文件读写(5)从文件系统中读取图像的标准函数imread()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 从文件加载图像。 imread 函数从指定的文件加载图像并返回它。如果图像无法读取&#xff08;因为文件缺失、权限不当、格式不受支持或无效&…

IDEA使用技巧和插件推荐

作为专业开发人员&#xff0c;选择一个强大的集成开发环境&#xff08;IDE&#xff09;是至关重要的。IntelliJ IDEA&#xff08;简称IDEA&#xff09;不仅功能丰富&#xff0c;而且操作便捷&#xff0c;是众多开发者的首选。本文将分享一些使用IDEA的技巧&#xff0c;以及推荐…

测试部署单副本 oceanbase-3.2.4.1 企业版

由于项目需要&#xff0c;测试部署单副本 oceanbase-3.2.4.1 企业版 1.安装前提 准备4cpu,12G内存,100G磁盘 统为centos7.9 yum install -y yum-utils wget net-tools tree yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo 2.创建用…

SLF4J报错log4j又报错

项目场景&#xff1a; 搭建一个spirngboot项目&#xff0c;启动运行时&#xff0c;SLF4J报错 解决后 ~ log4j又报错了。 问题描述 首先是SLF4J报错了&#xff0c;解决完SL4J报错问题后&#xff0c;再次启动项目&#xff0c;log4j又报错了 。。。 报错信息&#xff1a; SLF4J…

IDEA Dependency Analyzer 分析 maven 项目包的依赖

一、场景分析 javax.validation 是我们 SpringMVC 常用的数据校验框架。但是 javax.validation 是一个规范&#xff08;Java Bean Validation&#xff0c;简称 JSR 380&#xff09;&#xff0c;它并没有具体的实现&#xff0c;它的常用实现&#xff0c;是hibernate-validator。…

【知了社保-注册安全分析报告-无验证方式导致安全隐患】

前言 由于网站注册入口容易被黑客攻击&#xff0c;存在如下安全问题&#xff1a; 1. 暴力破解密码&#xff0c;造成用户信息泄露 2. 短信盗刷的安全问题&#xff0c;影响业务及导致用户投诉 3. 带来经济损失&#xff0c;尤其是后付费客户&#xff0c;风险巨大&#xff0c;造…

CentOs-Stream-9 解决此系统未向授权服务器注册问题

RPM包注册安装问题 无法执行yum安装rpm问题(后面安装Mysql会遇到)&#xff1a;This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register. Mysql5.7本地无法注册&#xff1a; Mysql8本地无法…

EtherNET IP 转 Profinet 网关:工业通信的桥梁

在工业自动化领域&#xff0c;不同设备之间的通信协议兼容性是一个关键问题。EtherNET IP 和 Profinet 作为两种常用的工业以太网协议&#xff0c;各自在不同的设备和系统中广泛应用。而 EtherNET IP 转 Profinet 网关则成为了连接这两个不同协议世界的桥梁&#xff0c;发挥着至…

OJ在线评测系统 后端 用策略模式优化判题机架构

判题机架构优化(策略模式) 思考 我们的判题策略可能会有很多种 比如 我们的代码沙箱本身执行程序需要消耗时间 这个时间可能不同的编程语言是不同的 比如沙箱执行Java要额外花费2秒 我们可以采用策略模式 针对不同的情况 定义不同独立的策略 而不是把所有情况全部放在一个i…

【Mysql】数据库系统和Mysql

1、数据库系统 数据库&#xff08;Database&#xff09;是一个以某种组织方式存储在磁盘上的数据当代集合。 2、数据库应用 数据库应用系统是指基于数据库的应用软件。 3、数据库管理系统&#xff08;数据库软件&#xff09; &#xff08;1&#xff09;关系型数据库&#…