forked from XiaoMi/hiui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stepper): 支持配置字段别名(XiaoMi#2914)
* feat(stepper): 支持配置字段别名(XiaoMi#2914) * chore: 生成变更记录文件 * feat(stepper): 修改fieldNames类型 * feat(stepper): 代码规范 --------- Co-authored-by: xiamiao <[email protected]>
- Loading branch information
1 parent
9b2dc02
commit 2d8fd92
Showing
4 changed files
with
50 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/stepper": minor | ||
--- | ||
|
||
feat: 支持配置字段别名 |
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,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(stepper): 支持配置字段别名 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { HiBaseFieldNameKeys, HiBaseFieldNames } from '@hi-ui/core' | ||
import { StepperDataItem } from './types' | ||
import React from 'react' | ||
|
||
export const transformData = ( | ||
data: StepperDataItem[], | ||
fieldNames?: HiBaseFieldNames | ||
): StepperDataItem[] => { | ||
const getKeyFields = (node: StepperDataItem, key: HiBaseFieldNameKeys) => { | ||
if (fieldNames) { | ||
return node[(fieldNames[key] || key) as keyof StepperDataItem] | ||
} | ||
return node[key as keyof StepperDataItem] | ||
} | ||
|
||
const traverseNode = (node: StepperDataItem) => { | ||
const newNode: StepperDataItem = { ...node } | ||
|
||
newNode.title = getKeyFields(newNode, 'title') as React.ReactNode | ||
newNode.content = getKeyFields(newNode, 'content' as HiBaseFieldNameKeys) as React.ReactNode | ||
newNode.icon = getKeyFields(newNode, 'icon' as HiBaseFieldNameKeys) as React.ReactNode | ||
|
||
return newNode | ||
} | ||
|
||
return data.map((node) => traverseNode(node)) | ||
} |