Skip to content

Commit

Permalink
chore(antd/next): improve array table ui (#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Nov 1, 2021
1 parent fee4af0 commit 831ba8b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
19 changes: 12 additions & 7 deletions packages/antd/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useFieldSchema,
RecursionField,
} from '@formily/react'
import { FormPath, isArr, isBool } from '@formily/shared'
import { isArr, isBool } from '@formily/shared'
import { Schema } from '@formily/json-schema'
import { usePrefixCls } from '../__builtins__'
import { ArrayBase, ArrayBaseMixins } from '../array-base'
Expand Down Expand Up @@ -149,15 +149,20 @@ const StatusSelect: React.FC<IStatusSelectProps> = observer((props) => {
type: 'error',
address: `${field.address}.*`,
})
const createIndexPattern = (page: number) => {
const pattern = `${field.address}.*[${(page - 1) * props.pageSize}:${
page * props.pageSize
}].*`
return FormPath.parse(pattern)
const parseIndex = (address: string) => {
return Number(
address
.slice(address.indexOf(field.address.toString()) + 1)
.match(/(\d+)/)?.[1]
)
}

const options = props.options?.map(({ label, value }) => {
const hasError = errors.some(({ address }) => {
return createIndexPattern(value).match(address)
const currentIndex = parseIndex(address)
const startIndex = (value - 1) * props.pageSize
const endIndex = value * props.pageSize
return currentIndex >= startIndex && currentIndex <= endIndex
})
return {
label: hasError ? <Badge dot>{label}</Badge> : label,
Expand Down
3 changes: 3 additions & 0 deletions packages/antd/src/array-table/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
z-index: 1;
border-radius: 3px;
box-shadow: 0 0 10px #eee;
animation: none;
transform: translateY(0);
opacity: 1;
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions packages/next/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useFieldSchema,
RecursionField,
} from '@formily/react'
import { FormPath, isArr, isBool } from '@formily/shared'
import { isArr, isBool } from '@formily/shared'
import { Schema } from '@formily/json-schema'
import { usePrefixCls } from '../__builtins__'
import { ArrayBase, ArrayBaseMixins } from '../array-base'
Expand Down Expand Up @@ -149,15 +149,19 @@ const StatusSelect: React.FC<IStatusSelectProps> = observer(
type: 'error',
address: `${field.address}.*`,
})
const createIndexPattern = (page: number) => {
const pattern = `${field.address}.*[${(page - 1) * pageSize}:${
page * pageSize
}].*`
return FormPath.parse(pattern)
const parseIndex = (address: string) => {
return Number(
address
.slice(address.indexOf(field.address.toString()) + 1)
.match(/(\d+)/)?.[1]
)
}
const options = props.dataSource?.map(({ label, value }) => {
const hasError = errors.some(({ address }) => {
return createIndexPattern(value).match(address)
const currentIndex = parseIndex(address)
const startIndex = (value - 1) * pageSize
const endIndex = value * pageSize
return currentIndex >= startIndex && currentIndex <= endIndex
})
return {
label: hasError ? <Badge dot>{label}</Badge> : label,
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/array-table/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ $array-table-prefix-cls: '#{$css-prefix}formily-array-table';
color: #fff;
padding: 6px 8px;
margin-top: 6px;

transform: translateY(0);
opacity: 1;
&:after {
content: ' ';
background: $form-error-color;
Expand Down

0 comments on commit 831ba8b

Please sign in to comment.