32 |
33 | {selectedLabelList?.length 34 | ? `选中了 ${selectedLabelList?.join?.('、')}` 35 | : '未选中'} 36 |
37 | 38 |14 | {"data":{"id":"1","createdAt":1736479532239,"title":"What is your name?","messages":[{"id":"1","createdAt":1736479532239,"content":"My Name is dt-react-component","status":0}]}} 15 |16 |
20 | {"prompt":{"id":"1","createdAt":1736479532239,"title":"What is your name?","messages":[{"id":"1","createdAt":1736479532239,"content":"My Name is dt-react-component","status":0}]},"data":[{"id":"1","createdAt":1736479532239,"content":"My Name is dt-react-component","status":0}],"regenerate":true} 21 |22 | 27 | 32 | 37 |
18 | What is your name? 19 |
20 |
18 |
19 | ## API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | ---- | ---- | -------------------------- | ------ |
23 | | type | 类型 | `'primary' \| 'secondary'` | - |
24 |
--------------------------------------------------------------------------------
/src/chat/index.$tab-codeBlock.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: CodeBlock
3 | group: 组件
4 | toc: content
5 | ---
6 |
7 | # CodeBlock
8 |
9 | ## 何时使用
10 |
11 | CodeBlock 组件用以展示代码块
12 |
13 | ## 示例
14 |
15 |
16 |
17 |
18 | ## API
19 |
20 | | 参数 | 说明 | 类型 | 默认值 |
21 | | --------- | ---------------- | -------------------------------------------- | ------ |
22 | | copy | 是否支持复制功能 | `boolean \| ICopyProps` | `true` |
23 | | className | 类名 | `string` | - |
24 | | style | 样式 | `CSSProperties` | - |
25 | | convert | 反色模式 | `boolean` | - |
26 | | toolbars | 渲染工具位 | `React.ReactNode \| (() => React.ReactNode)` | - |
27 | | options | 配置项 | `SyntaxHighlighterProps` | - |
28 | | children | 文案 | `React.ReactNode & React.ReactNode[]` | - |
29 |
--------------------------------------------------------------------------------
/src/chat/index.$tab-input.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Input
3 | group: 组件
4 | toc: content
5 | demo:
6 | cols: 2
7 | ---
8 |
9 | # Input
10 |
11 | ## 何时使用
12 |
13 | Input 组件用以解决 AI 交互中的输入框
14 |
15 | ## 示例
16 |
17 |
18 |
19 | ## API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | ----------------- | ------------------------- | ---------------------- | ------ |
23 | | onChange | 值发生变化时的回调 | `(str:string) => void` | - |
24 | | onPressShiftEnter | 输入 Shift + Enter 的回调 | `Function` | - |
25 |
--------------------------------------------------------------------------------
/src/chat/index.$tab-loading.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Loading
3 | group: 组件
4 | toc: content
5 | demo:
6 | cols: 2
7 | ---
8 |
9 | # Loading
10 |
11 | ## 何时使用
12 |
13 | Loading 组件用以解决 AI 交互中的 loading 状态
14 |
15 | ## 示例
16 |
17 |
18 |
19 | ## API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | ------- | ---------- | --------- | ------ |
23 | | loading | 是否加载中 | `boolean` | - |
24 |
--------------------------------------------------------------------------------
/src/chat/index.$tab-markdown.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Markdown
3 | group: 组件
4 | toc: content
5 | ---
6 |
7 | # Markdown
8 |
9 | ## 何时使用
10 |
11 | Markdown 组件用以渲染 markdown 内容
12 |
13 | :::warning
14 | Markdown 组件自带 memo 用于性能优化,只有 `typing`、`children`、`className` 属性修改才会引起重渲染。
15 | :::
16 |
17 | ## 示例
18 |
19 |
20 |
21 | ## API
22 |
23 | | 参数 | 说明 | 类型 | 默认值 |
24 | | --------- | ------------------- | ------------ | ------ |
25 | | typing | 是否输入中 | `boolean` | - |
26 | | className | 类名 | `string` | - |
27 | | children | 文案 | `string` | - |
28 | | onMount | didMount 的回调函数 | `() => void` | - |
29 |
30 | 其余属性参考 `react-markdown@~8.0.6`
31 |
--------------------------------------------------------------------------------
/src/chat/index.$tab-message.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Message
3 | group: 组件
4 | toc: content
5 | ---
6 |
7 | # Message
8 |
9 | ## 何时使用
10 |
11 | Message 组件用以渲染回答框
12 |
13 | ## 示例
14 |
15 |
16 |
17 |
18 | ## API
19 |
20 | | 参数 | 说明 | 类型 | 默认值 |
21 | | -------------- | ---------------------- | ----------------------------------- | ------- |
22 | | data | 数据 | `Message[]` | - |
23 | | regenerate | 是否支持重新生成 | `boolean` | `false` |
24 | | copy | 是否支持复制功能 | `boolean \| CopyOptions` | `true` |
25 | | onRegenerate | 点击重新生成的回调函数 | `(data: Message) => void` | - |
26 | | onStop | 点击停止问答的回调函数 | `(data: Message) => void` | - |
27 | | onLazyRendered | 懒加载的回调函数 | `(cb: () => Promise
18 |
19 | ## API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | --------- | ---- | -------- | ------ |
23 | | content | 文案 | `string` | - |
24 | | className | 类名 | `string` | - |
25 |
--------------------------------------------------------------------------------
/src/chat/index.$tab-tag.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Tag
3 | group: 组件
4 | toc: content
5 | demo:
6 | cols: 2
7 | ---
8 |
9 | # Tag
10 |
11 | ## 何时使用
12 |
13 | Tag 组件作为提示集合提供给用户快捷操作
14 |
15 | ## 示例
16 |
17 |
18 |
19 | ## API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | -------- | ---- | ----------------- | ------ |
23 | | children | | `React.ReactNode` | - |
24 |
--------------------------------------------------------------------------------
/src/chat/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Chat 智能问答
3 | group: 组件
4 | toc: content
5 | ---
6 |
7 | # 智能问答
8 |
9 | ## 组件概述
10 |
11 | Chat 规范由多个组件复合使用实现落地场景,其中:
12 |
13 | - `useChat` 是旨在解决 Chat 的数据问题的 hook
14 | - `Chat` 组件是作为 Chat 组件的集合及 Provider
15 | - `Loading` 组件是回答框在等待生成时的加载组件
16 | - `Button` 组件是符合 AI 规范的按钮组件
17 | - `CodeBlock` 组件是符合 AI 规范的代码块组件
18 | - `Input` 组件是符合 AI 规范的输入框组件
19 | - `Markdown` 组件是符合 AI 规范的渲染 markdown 的组件
20 | - `Pagination` 组件是符合 AI 规范的分页器
21 | - `Message` 组件是符合 AI 规范的回答框
22 | - `Prompt` 组件是符合 AI 规范的提问框
23 | - `Content` 组件是符合 AI 规范的正文内容
24 |
25 | ## 何时使用
26 |
27 | 涉及到 AI 相关功能时。
28 |
29 | ## 示例
30 |
31 |
32 |
33 |
34 | ## API
35 |
--------------------------------------------------------------------------------
/src/chat/input/index.scss:
--------------------------------------------------------------------------------
1 | .dtc__chat__textarea__container {
2 | width: 100%;
3 | border-radius: 8px;
4 | border: 1px solid #D8DAE2;
5 | background: #FFF;
6 | position: relative;
7 | max-width: 800px;
8 | margin: 0 auto;
9 | .dtc__chat__textarea {
10 | border: none;
11 | background-color: transparent;
12 | color: #3D446E;
13 | font-size: 12px;
14 | font-style: normal;
15 | font-weight: 400;
16 | line-height: 20px;
17 | padding: 8px 36px 8px 16px;
18 | &:focus {
19 | box-shadow: none;
20 | }
21 | }
22 | .dtc__chat__textarea__send {
23 | font-size: 24px;
24 | position: absolute;
25 | bottom: 8px;
26 | right: 8px;
27 | &:hover:not(&--disabled) {
28 | &.dtc__icon path {
29 | fill: url(#paint0_linear_3878_6538_hover);
30 | }
31 | }
32 | &--disabled {
33 | cursor: not-allowed;
34 | color: #B1B4C5;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/chat/loading/index.scss:
--------------------------------------------------------------------------------
1 | .dtc__aigc__loading {
2 | display: flex;
3 | gap: 2px;
4 | width: 100%;
5 | padding: 10px 0;
6 | align-items: center;
7 | justify-content: center;
8 | height: 28px;
9 | > div {
10 | width: 4px;
11 | height: 4px;
12 | border-radius: 50%;
13 | background-color: #E8F1FF;
14 | &:nth-child(1) {
15 | animation: 0.6s linear 0s infinite alternate loading;
16 | }
17 | &:nth-child(2) {
18 | animation: 0.6s linear 0.2s infinite alternate loading;
19 | }
20 | &:nth-child(3) {
21 | animation: 0.6s linear 0.4s infinite alternate loading;
22 | }
23 | }
24 | }
25 |
26 | @keyframes loading {
27 | 0% {
28 | width: 4px;
29 | height: 4px;
30 | background-color: #FFF;
31 | }
32 | 50% {
33 | width: 5px;
34 | height: 5px;
35 | background-color: #BBD6FF;
36 | }
37 | 100% {
38 | width: 6px;
39 | height: 6px;
40 | background-color: #1D78FF;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/chat/loading/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { PropsWithChildren } from 'react';
2 |
3 | import './index.scss';
4 |
5 | interface ILoadingProps {
6 | loading: boolean;
7 | }
8 |
9 | export default function Loading(props: PropsWithChildren{text}
15 |{text}
20 |{text}
25 |{text}
13 |{text}
17 |
18 |
19 |
20 | ### API
21 |
22 | | 参数 | 说明 | 类型 | 默认值 |
23 | | --------- | ---------------- | --------------------------------------- | ----------------------------------- |
24 | | text | 需要复制的文本 | `string` | - |
25 | | tooltip | 配置提示信息 | `TooltipProps['title'] \| TooltipProps` | `复制` |
26 | | button | 自定义按钮 | `React.ReactNode` | `
18 |
19 | ### API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | ----------- | ---- | ------------------- | ------ |
23 | | tableLayout | - | `'auto' \| 'fixed'` | 'auto' |
24 |
25 | ## FAQ
26 |
27 | ### 为什么要把 table-layout 设置为 fixed?
28 |
29 | 参考 [MDN](https://developer.mozilla.org/zh-CN/docs/Web/CSS/table-layout#fixed) 中关于 `table-layout` 的相关描述可以看出,当我们的需求是用 `Descriptions` 组件用固定比例展示字段信息的时候,相比 `auto` 的属性,更好地是 `fixed` 属性
30 |
--------------------------------------------------------------------------------
/src/descriptions/index.scss:
--------------------------------------------------------------------------------
1 | .dtc-descriptions {
2 | &__fixed {
3 | .ant-descriptions-view > table {
4 | table-layout: fixed;
5 | }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/descriptions/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Descriptions as AntdDescriptions, DescriptionsProps as AntdDescriptionsProps } from 'antd';
3 | import classNames from 'classnames';
4 |
5 | import './index.scss';
6 |
7 | interface DescriptionsProps extends AntdDescriptionsProps {
8 | tableLayout?: 'auto' | 'fixed';
9 | }
10 |
11 | function Descriptions({ className, tableLayout, ...rest }: DescriptionsProps) {
12 | return (
13 |
18 |
19 |
20 |
21 | ## API
22 |
23 | | 参数 | 说明 | 类型 | 默认值 |
24 | | ----------------- | ---------------------------------- | ------------------------------------------- | ------ |
25 | | value | 当前选中的值 | `(string \| number)[]` | - |
26 | | defaultValue | 初始值 | `(string \| number)[]` | - |
27 | | className | - | `string` | - |
28 | | options | Checkbox 指定可选项 | `(string \| number \| Option)[]` | `[]` |
29 | | getPopupContainer | 同 Dropdown 的 `getPopupContainer` | `(triggerNode: HTMLElement) => HTMLElement` | - |
30 | | onChange | 变化时的回调函数 | `(checkedValue) => void` | - |
31 |
--------------------------------------------------------------------------------
/src/dropdown/index.tsx:
--------------------------------------------------------------------------------
1 | import { Dropdown } from 'antd';
2 |
3 | import Select from './select';
4 |
5 | type OriginalInterface = typeof Dropdown;
6 | interface DropdownInterface extends OriginalInterface {
7 | Select: typeof Select;
8 | }
9 | const WrapperDropdown = Dropdown;
10 | (WrapperDropdown as DropdownInterface).Select = Select;
11 | export default WrapperDropdown as DropdownInterface;
12 |
--------------------------------------------------------------------------------
/src/dropdown/style.scss:
--------------------------------------------------------------------------------
1 | $gap: 8px;
2 | $item-size: 32px;
3 |
4 | .dtc-dropdown-select {
5 | &__container {
6 | background: #FFF;
7 | box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.1);
8 | border-radius: 2px;
9 | height: auto;
10 | padding: $gap 0;
11 | .ant-checkbox-group {
12 | width: 100%;
13 | display: block;
14 | }
15 | }
16 | &__shadow {
17 | position: absolute;
18 | top: 0;
19 | width: 100%;
20 | box-shadow: inset 0 10px 10px -10px #EBECF0;
21 | height: 10px;
22 | z-index: 999;
23 | opacity: 0;
24 | transform: opacity 0.3s;
25 | pointer-events: none;
26 | &.active {
27 | opacity: 1;
28 | }
29 | }
30 | &__col {
31 | height: $item-size;
32 | line-height: $item-size;
33 | padding: 0 $gap;
34 | cursor: pointer;
35 | transition: background-color 0.3s;
36 | .ant-checkbox-wrapper {
37 | width: 100%;
38 | }
39 | &:hover {
40 | background-color: #F9F9FA;
41 | }
42 | }
43 | &__btns {
44 | height: $item-size;
45 | line-height: $item-size;
46 | padding: 0 $gap;
47 | width: 100%;
48 | justify-content: end;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/ellipsisText/demos/basic.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { EllipsisText } from 'dt-react-component';
3 |
4 | export default () => {
5 | return (
6 | 基本使用
18 | 自定义错误页面
19 |
20 | ## API
21 |
22 | | 参数 | 说明 | 类型 | 默认值 |
23 | | --------- | ------------------ | ------------------------ | --------------- |
24 | | children | 子组件 | `React.ReactNode` | - |
25 | | errorPage | 自定义错误展示页面 | `React.ReactNode` | `
16 |
17 |
18 | ## API
19 |
20 | | 参数 | 说明 | 类型 | 默认值 |
21 | | -------- | ----------------------- | ----------------------------------------------------------------------------------- | -------- |
22 | | vertical | flex 主轴的方向是否垂直 | `boolean` | `false` |
23 | | wrap | 主轴换行 | [flex-wrap](https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex-wrap) | `nowrap` |
24 | | justify | `justify-content` | [justify-content](https://developer.mozilla.org/zh-CN/docs/Web/CSS/justify-content) | `normal` |
25 | | align | `align-items` | [align-items](https://developer.mozilla.org/zh-CN/docs/Web/CSS/align-items) | `normal` |
26 | | flex | `flex` | [flex](https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex) | `normal` |
27 | | gap | `gap` | [gap](https://developer.mozilla.org/zh-CN/docs/Web/CSS/gap) | `0` |
28 | | children | 展示内容 | `React.ReactNode` | - |
29 |
--------------------------------------------------------------------------------
/src/flex/index.scss:
--------------------------------------------------------------------------------
1 | .dtc-flex {
2 | display: flex;
3 | flex-direction: row;
4 | &__vertical {
5 | flex-direction: column;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/flex/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { CSSProperties, forwardRef } from 'react';
2 | import classNames from 'classnames';
3 |
4 | import './index.scss';
5 |
6 | export interface IFlexProps extends React.DOMAttributes
18 |
19 |
20 |
21 |
22 | ## API
23 |
24 | | 参数 | 说明 | 类型 | 默认值 |
25 | | ------------ | -------------------------- | ----------------- | ------- |
26 | | target | 全局操作作用于指定目标对象 | `string` | - |
27 | | themeDark | 是否使用暗黑主题模式 | `boolean` | `false` |
28 | | iconStyle | 图标元素样式 | `CSSProperties` | - |
29 | | fullIcon | 自定义全屏图标 | `React.ReactNode` | - |
30 | | exitFullIcon | 自定义退出全屏图标 | `React.ReactNode` | - |
31 |
--------------------------------------------------------------------------------
/src/fullscreen/style.scss:
--------------------------------------------------------------------------------
1 | .dtc-fullscreen-icon {
2 | width: 16px;
3 | height: 16px;
4 | margin-right: 5px;
5 | margin-top: -4px;
6 | }
7 |
--------------------------------------------------------------------------------
/src/globalLoading/__tests__/globalLoading.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import '@testing-library/jest-dom/extend-expect';
4 |
5 | import GlobalLoading from '..';
6 |
7 | describe('test GlobalLoading', () => {
8 | it('renders loading title', () => {
9 | const { getByText } = render(
18 |
19 |
20 | ## API
21 |
22 | | 参数 | 说明 | 类型 | 默认值 |
23 | | ---------------- | ---------------------- | -------- | -------------------- |
24 | | loadingTitle | 应用名称 | `string` | 应用加载中,请等候~ |
25 | | mainBackground | 整体背景色 | `string` | `#F2F7FA` |
26 | | titleColor | 文案字体颜色 | `string` | `#3D446E` |
27 | | circleBackground | 等待动画 circle 背景色 | `string` | `#1D78FF` |
28 | | className | 设置组件 className | `string` | - |
29 |
--------------------------------------------------------------------------------
/src/image/demos/basic.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import Image from '..';
4 |
5 | export default function Component() {
6 | return (
7 |
16 |
17 |
18 | ## API
19 |
20 | ### Props
21 |
22 | | 参数 | 说明 | 类型 | 默认值 |
23 | | --------- | ----------------------- | --------------------- | ---------- |
24 | | src | 图片资源 | `string` | - |
25 | | lazy | 是否开启图片懒加载 | `boolean` | - |
26 | | className | 图片样式名 | `string` | - |
27 | | style | 图片样式 | `React.CSSProperties` | - |
28 | | width | 图片宽度 | `number` | - |
29 | | height | 图片高度 | `number` | - |
30 | | loader | 图片 loading 时展示内容 | `JSX.Element \| null` | `
18 |
19 |
20 | ## API
21 |
22 | ### 类型
23 |
24 | | 参数 | 说明 | 类型 | 默认值 |
25 | | ------------- | -------------------- | -------------------------------------------------- | -------------- |
26 | | searchType | 当前匹配项 | `SearchType` |
27 | | filterOptions | 过滤匹配项数组 | `SearchType[]` | `SearchType[]` |
28 | | onTypeChange | 匹配项修改的回调函数 | `(type: SearchType) => void;` | - |
29 | | onSearch | 搜索的回调函数 | `(value: string, searchType: SearchType) => void;` | - |
30 |
31 | ### SearchType
32 |
33 | `type SearchType = 'fuzzy' | 'caseSensitive' | 'precise' | 'front' | 'tail';`
34 |
35 | | 参数 | 说明 |
36 | | ------------- | ---------- |
37 | | fuzzy | 无选中状态 |
38 | | caseSensitive | 大小写敏感 |
39 | | precise | 精准查询 |
40 | | front | 头部匹配 |
41 | | tail | 尾部匹配 |
42 |
--------------------------------------------------------------------------------
/src/input/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Input 输入框
3 | group: 组件
4 | toc: content
5 | demo:
6 | cols: 2
7 | ---
8 |
9 | # Input 输入框
10 |
11 | ## 何时使用
12 |
13 | 需要用户输入内容时。
14 |
15 | ## 示例
16 |
17 |
18 |
19 | ## API
20 |
21 | ### 类型
22 |
23 | | 参数 | 说明 | 类型 | 默认值 |
24 | | ------------------ | ---------------------- | ---------- | ------ |
25 | | onPressEnter | 输入英文回车的回调函数 | `Function` |
26 | | onPressEnterNative | 输入任意回车的回调函数 | `Function` | |
27 |
28 | 其余属性均继承自 `Input` 组件,参考 [Input API](https://4x.ant.design/components/input-cn/#Input)
29 |
--------------------------------------------------------------------------------
/src/input/index.tsx:
--------------------------------------------------------------------------------
1 | import InternalInput from './internalInput';
2 | import InternalMatch from './match';
3 |
4 | type OriginInputType = typeof InternalInput;
5 | interface InputInterface extends OriginInputType {
6 | Match: typeof InternalMatch;
7 | }
8 |
9 | const WrapperInput = InternalInput;
10 |
11 | (WrapperInput as InputInterface).Match = InternalMatch;
12 |
13 | export default WrapperInput as InputInterface;
14 |
--------------------------------------------------------------------------------
/src/input/internalInput.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Input, type InputProps } from 'antd';
3 |
4 | export interface IInternalInputProps extends InputProps {
5 | onPressEnterNative?: InputProps['onPressEnter'];
6 | }
7 |
8 | export default function InternalInput({
9 | onPressEnterNative,
10 | onPressEnter,
11 | ...rest
12 | }: IInternalInputProps) {
13 | return (
14 | {
17 | if (e.keyCode === 13) {
18 | onPressEnter?.(e);
19 | }
20 | onPressEnterNative?.(e);
21 | }}
22 | />
23 | );
24 | }
25 |
--------------------------------------------------------------------------------
/src/input/match.scss:
--------------------------------------------------------------------------------
1 | .dtc-input-match {
2 | &-items {
3 | display: flex;
4 | align-items: center;
5 | gap: 8px;
6 | }
7 | &-suffixItem {
8 | cursor: pointer;
9 | transition: color 0.15s;
10 | color: #B1B4C5;
11 | outline: 1px solid transparent;
12 | outline-offset: -1px;
13 | padding: 2px;
14 | box-sizing: content-box;
15 | &:hover {
16 | color: #1D78FF;
17 | }
18 | &:active,
19 | &:focus {
20 | color: #005CE6;
21 | }
22 | &__active {
23 | color: #1D78FF;
24 | outline-color: #1D78FF;
25 | border-radius: 2px;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/keyEventListener/__tests__/__snapshots__/index.test.tsx.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`test KeyCombiner suite snapshot match 1`] = `
4 |
18 |
19 |
20 | ## API
21 |
22 | ### KeyEventListener
23 |
24 | | 参数 | 说明 | 类型 | 默认值 |
25 | | --------- | ------------ | ----------------- | ------ |
26 | | onKeyDown | 键盘按下执行 | `function` | - |
27 | | onKeyUp | 键盘抬起执行 | `function` | - |
28 | | children | 子组件 | `React.ReactNode` | - |
29 |
30 | ### KeyEventListener.KeyCombiner
31 |
32 | | 参数 | 说明 | 类型 | 默认值 |
33 | | --------- | ------------------------------------------------------------------------------------------ | ----------------- | ------ |
34 | | keyMap | 监听的一组 key map,eg: { 70: true, 91: true, 16: true } 则表示监听 command+shift+f 组合键 | `object` | - |
35 | | onTrigger | 触发事件 | `function` | - |
36 | | children | 子组件 | `React.ReactNode` | - |
37 |
--------------------------------------------------------------------------------
/src/keyEventListener/index.tsx:
--------------------------------------------------------------------------------
1 | import { ForwardRefExoticComponent, ReactNode, useCallback, useEffect } from 'react';
2 |
3 | import KeyCombiner from './listener';
4 |
5 | export interface IKeyEventListenerProps {
6 | onKeyDown?: (e: KeyboardEvent) => void;
7 | onKeyUp?: (e: KeyboardEvent) => void;
8 | children?: ReactNode;
9 | }
10 | interface CompoundedComponent extends ForwardRefExoticComponent]*>',
32 | '
',
33 | 'g'
34 | );
35 | },
36 | };
37 | }
38 |
--------------------------------------------------------------------------------
/src/markdownRender/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: MarkdownRender 渲染
3 | group: 组件
4 | toc: content
5 | ---
6 |
7 | # MarkdownRender 渲染
8 |
9 | ## 何时使用
10 |
11 | 用于 Markdown 语法在 HTML 上展示,只负责渲染
12 |
13 | ## 示例
14 |
15 |
16 |
17 |
18 |
19 | ## API
20 |
21 | | 参数 | 说明 | 类型 | 默认值 |
22 | | --------- | ----------------- | --------- | ------ |
23 | | value | markdown 文本数据 | `string` | - |
24 | | dark | 暗黑主题 | `boolean` | - |
25 | | className | 类名 | `string` | - |
26 |
--------------------------------------------------------------------------------
/src/markdownRender/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { useMemo } from 'react';
2 | import classnames from 'classnames';
3 | import showdown from 'showdown';
4 |
5 | import sqlHighlightExtension from './extensions';
6 | import './style.scss';
7 |
8 | export interface IMarkdownRenderProps {
9 | /**
10 | * 当前渲染的值
11 | */
12 | value?: string;
13 | style?: React.CSSProperties;
14 | className?: string;
15 | /**
16 | * 暗黑模式
17 | */
18 | dark?: boolean;
19 | }
20 |
21 | export default function MarkdownRender({
22 | value = '',
23 | className,
24 | style,
25 | dark,
26 | }: IMarkdownRenderProps) {
27 | const result = useMemo(() => {
28 | const converter = new showdown.Converter({
29 | extensions: [sqlHighlightExtension],
30 | emoji: true,
31 | });
32 | return converter.makeHtml(value);
33 | }, [value]);
34 |
35 | return (
36 |
45 | );
46 | }
47 |
--------------------------------------------------------------------------------
/src/markdownRender/theme/vs.scss:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Visual Studio-like style based on original C# coloring by Jason Diamond
18 |
19 |
20 |
21 |
22 | ## API
23 |
24 | ### AlertProps
25 |
26 | [AlertProps](https://4x-ant-design.antgroup.com/components/alert-cn/#API)
27 |
28 | | 参数 | 说明 | 类型 | 默认值 |
29 | | ------ | ---- | --------------------------------------------- | --------- |
30 | | size | 尺寸 | `'small' \| 'default' \| 'middle' \| 'large'` | `default` |
31 | | banner | 提示 | `React.ReactNode \| AlertProps` | |
32 |
33 | :::info
34 | 其余参数继承 antd4.x 的 [Modal](https://4x.ant.design/components/modal-cn/#API)
35 | :::
36 |
--------------------------------------------------------------------------------
/src/modal/index.scss:
--------------------------------------------------------------------------------
1 | $modal-max-height: 80vh;
2 |
3 | .dtc-modal {
4 | .ant-modal-content {
5 | max-height: $modal-max-height;
6 | display: flex;
7 | flex-direction: column;
8 | .ant-modal-body {
9 | overflow: hidden;
10 | flex: 1;
11 | display: flex;
12 | flex-direction: column;
13 | .dtc-modal-body {
14 | flex: 1;
15 | padding: 16px 24px;
16 | overflow-y: auto;
17 | min-height: 0;
18 | }
19 | .dtc-modal-alert {
20 | border-radius: 6px;
21 | margin: 4px;
22 | }
23 | }
24 | .ant-modal-header,
25 | .ant-modal-footer {
26 | flex: 0 1 auto;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/modal/index.tsx:
--------------------------------------------------------------------------------
1 | import { Modal as AntdModal } from 'antd';
2 | import { ModalStaticFunctions } from 'antd/lib/modal/confirm';
3 |
4 | import InternalModal from './modal';
5 |
6 | type ModalType = typeof InternalModal &
7 | ModalStaticFunctions & {
8 | useModal: typeof AntdModal.useModal;
9 | destroyAll: () => void;
10 | config: typeof AntdModal.config;
11 | };
12 |
13 | const { useModal, info, success, error, warning, confirm, destroyAll, config } = AntdModal;
14 |
15 | const Modal = InternalModal as ModalType;
16 |
17 | Object.assign(Modal, {
18 | useModal,
19 | info,
20 | success,
21 | error,
22 | warning,
23 | confirm,
24 | destroyAll,
25 | config,
26 | });
27 |
28 | export { IModalProps } from './modal';
29 |
30 | export default Modal;
31 |
--------------------------------------------------------------------------------
/src/notFound/__tests__/notFound.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { cleanup, render } from '@testing-library/react';
3 | import '@testing-library/jest-dom/extend-expect';
4 |
5 | import NotFound from '..';
6 |
7 | describe('test NotFound', () => {
8 | afterEach(cleanup);
9 |
10 | test('renders not found message', () => {
11 | const { getByText } = render(window高度: {innerWidth}17 |
window宽度: {innerHeight}18 |
当前元素的可视宽: {clientWidth}24 |
当前元素的可视宽: {clientHegiht}25 |
基础使用
20 | 监听自定义元素
21 |
22 | ## API
23 |
24 | ### Resize
25 |
26 | | 参数 | 说明 | 类型 | 默认值 |
27 | | ----------- | ---------------------------------------- | ----------------- | ------ |
28 | | children | 子元素 | `React.ReactNode` | - |
29 | | observerEle | 监听的元素,传入元素不存在默认监听 window | `HTMLElement` | - |
30 | | onResize | 重置元素大小的函数 | `() => void` | - |
31 |
--------------------------------------------------------------------------------
/src/resize/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { ReactNode, useEffect, useRef } from 'react';
2 |
3 | export interface ResizeProps {
4 | observerEle?: HTMLElement | null;
5 | children?: ReactNode;
6 | onResize?: () => void;
7 | }
8 |
9 | const Resize: React.FC
18 |
19 |
20 | ## API
21 |
22 | ### SpreadSheet
23 |
24 | | 参数 | 说明 | 类型 | 默认值 |
25 | | ---------------------- | ------------------------------------------------------ | ------------------------------------------------------------ | -------------- |
26 | | data | 表格数据 | `Array(二维数组)` | - |
27 | | columns | 列名 | `Array` | - |
28 | | className | 外层组件的 class 名 | `string` | - |
29 | | options.copyTypes | 右键菜单中展示的选项 复制值/复制列名/复制列名和值 按钮 | `Array<'copyData' \| 'copyHeaders' \| 'copyHeadersAndData'>` | "['copyData']" |
30 | | options.trimWhitespace | 是否去除内容里的空格 | `boolean` | true |
31 |
--------------------------------------------------------------------------------
/src/statusTag/demos/icon.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { SketchOutlined } from '@ant-design/icons';
3 | import { Space } from 'antd';
4 | import { StatusTag } from 'dt-react-component';
5 |
6 | export default () => {
7 | return (
8 | 基础使用
18 |
19 | ## API
20 |
21 | ### Table
22 |
23 | 完全继承自`antd`的`Table`组件,参考[Table](https://4x.ant.design/components/table-cn/#API)
24 |
25 | ### ColumnType
26 |
27 | 除继承自`Table`组件的 ColumnType 外,还额外扩充以下属性
28 | | 参数 | 说明 | 类型 | 默认值 |
29 | | ----------- | ---------------------------------------- | ----------------- | ------ |
30 | | tooltip | 配置表格 title 提示信息 | `React.ReactNode` \| TooltipProps & { icon: React.ReactNode } | - |
31 |
--------------------------------------------------------------------------------
/src/table/index.scss:
--------------------------------------------------------------------------------
1 | .dtc-table {
2 | &__tooltip {
3 | margin-left: 4px;
4 | font-size: 16px;
5 | color: #B1B4C5;
6 | cursor: help;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/tinyTag/__tests__/__snapshots__/tinyTag.test.tsx.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`test StatusTag should match snapshot 1`] = `
4 |