-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add long-text and long-text-modal valueTypes
- Loading branch information
Showing
10 changed files
with
153 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/search-table-react/src/valueTypes/CommaNumber.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { REG_COMMA_NUMBER } from '../constants/regexp' | ||
import { isEmpty } from '../utils/common' | ||
|
||
interface ICommaNumberProps { | ||
value?: any | ||
} | ||
|
||
const CommaNumber = ({ value }: ICommaNumberProps) => { | ||
// 排除空数据 | ||
if (isEmpty(value)) { | ||
return '-' | ||
} | ||
|
||
// 保证 value 是数字 | ||
if (isNaN(Number(value))) { | ||
return value | ||
} | ||
|
||
// 千分位处理 | ||
return String(value).replace(REG_COMMA_NUMBER, ',') | ||
} | ||
|
||
export default CommaNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { IObjectAny } from '@schema-render/core-react' | ||
import { Tooltip } from 'antd' | ||
import type { FC } from 'react' | ||
|
||
interface ILongTextProps { | ||
value?: string | ||
options?: IObjectAny | ||
} | ||
|
||
const LongText: FC<ILongTextProps> = ({ value, options = {} }) => { | ||
const text = value ? String(value) : '-' | ||
const { maxLength = 10, ...tooltipProps } = options | ||
|
||
return text.length > maxLength ? ( | ||
<Tooltip title={text} {...tooltipProps}> | ||
{text.slice(0, maxLength - 1)}... | ||
</Tooltip> | ||
) : ( | ||
<>{text}</> | ||
) | ||
} | ||
|
||
export default LongText |
38 changes: 38 additions & 0 deletions
38
packages/search-table-react/src/valueTypes/LongTextModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { IObjectAny } from '@schema-render/core-react' | ||
import { Button, Modal } from 'antd' | ||
import type { FC } from 'react' | ||
import { useState } from 'react' | ||
|
||
interface ILongTextModalProps { | ||
value?: string | ||
options?: IObjectAny | ||
} | ||
|
||
const LongTextModal: FC<ILongTextModalProps> = ({ value, options = {} }) => { | ||
const text = value ? String(value) : '-' | ||
const { maxLength = 10, ...modalProps } = options | ||
const [isOpen, setIsOpen] = useState(false) | ||
|
||
return text.length > maxLength ? ( | ||
<> | ||
{text.slice(0, maxLength - 3)}... | ||
<Button type="link" style={{ padding: 0 }} onClick={() => setIsOpen(true)}> | ||
全部 | ||
</Button> | ||
<Modal | ||
width={600} | ||
title="全部" | ||
footer={null} | ||
{...modalProps} | ||
open={isOpen} | ||
onCancel={() => setIsOpen(false)} | ||
> | ||
{text} | ||
</Modal> | ||
</> | ||
) : ( | ||
<>{text}</> | ||
) | ||
} | ||
|
||
export default LongTextModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters