mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
23 lines
601 B
JavaScript
23 lines
601 B
JavaScript
|
|
/**
|
|
* For Select Component to use
|
|
* Todo: Refactor to avoid link list, since it will make component intrinsic
|
|
* logic more complex
|
|
*/
|
|
import cloneDeep from 'lodash/cloneDeep'
|
|
|
|
export default function linkedOptions (options) {
|
|
const decoratedOptions = cloneDeep(options).map((option, index) => {
|
|
return {
|
|
...option,
|
|
id: index
|
|
}
|
|
})
|
|
const length = decoratedOptions.length
|
|
decoratedOptions.forEach((option, i) => {
|
|
option.prev = decoratedOptions[(i + length - 1) % length]
|
|
option.next = decoratedOptions[(i + length + 1) % length]
|
|
})
|
|
return decoratedOptions
|
|
}
|