Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@uform/antd): Fix deps #435

Merged
merged 7 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"@uform/react-schema-renderer": "^1.0.0-alpha.2",
"@uform/react-shared-components": "^1.0.0-alpha.2",
"@uform/shared": "^1.0.0-alpha.2",
"@uform/types": "^0.4.0",
"classnames": "^2.2.6",
"moveto": "^1.7.4",
"react-stikky": "^0.1.15",
"react-eva": "^1.0.0-alpha.0",
"rxjs": "^6.5.1",
"styled-components": "^4.1.1"
},
"publishConfig": {
Expand Down
2 changes: 0 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
"@uform/react-schema-renderer": "^1.0.0-alpha.2",
"@uform/react-shared-components": "^1.0.0-alpha.2",
"@uform/shared": "^1.0.0-alpha.2",
"@uform/types": "^0.4.0",
"classnames": "^2.2.6",
"moveto": "^1.7.4",
"react-eva": "^1.0.0-alpha.0",
"react-stikky": "^0.1.15",
"rxjs": "^6.5.1",
Expand Down
49 changes: 35 additions & 14 deletions packages/react-shared-components/src/PreviewText.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, createContext } from 'react'
import { isFn } from '@uform/shared'
import { isFn, isEqual } from '@uform/shared'
import { IPreviewTextProps } from './types'

export interface PreviewTextConfigProps {
Expand All @@ -14,20 +14,41 @@ export const PreviewText: React.FC<IPreviewTextProps> & {
const context = useContext(PreviewTextContext) || {}
let value: any
if (props.dataSource && props.dataSource.length) {
let find = props.dataSource.filter(({ value }) =>
Array.isArray(props.value)
? props.value.some(val => val == value)
: props.value == value
)
value = find.reduce((buf, item, index) => {
return buf.concat(item.label, index < find.length - 1 ? ', ' : '')
}, [])
if (Array.isArray(props.value)) {
value = props.value.map((val, index) => {
const finded = props.dataSource.find(item => isEqual(item.value, val))
if (finded) {
return (
<span key={index}>
{finded.label}
{index < props.value.length - 1 ? ' ,' : ''}
</span>
)
}
})
} else {
const fined = props.dataSource.find(item =>
isEqual(item.value, props.value)
)
if (fined) {
value = fined.label
}
}
} else {
value = Array.isArray(props.value)
? props.value.join(' ~ ')
: String(
props.value === undefined || props.value === null ? '' : props.value
if (Array.isArray(props.value)) {
value = props.value.map((val, index) => {
return (
<span key={index}>
{val}
{index < props.value.length - 1 ? '~' : ''}
</span>
)
})
} else {
value = String(
props.value === undefined || props.value === null ? '' : props.value
)
}
}
const placeholder = isFn(context.previewPlaceholder)
? context.previewPlaceholder(props)
Expand All @@ -44,7 +65,7 @@ export const PreviewText: React.FC<IPreviewTextProps> & {
value === undefined ||
(Array.isArray(value) && value.length === 0)
? placeholder || 'N/A'
: String(value)}
: value}
{props.addonTextAfter ? ' ' + props.addonTextAfter : ''}
{props.innerAfter ? ' ' + props.innerAfter : ''}
{props.addonAfter ? ' ' + props.addonAfter : ''}
Expand Down
Loading