mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
24 lines
593 B
TypeScript
24 lines
593 B
TypeScript
import { computed } from 'vue'
|
|
import type { ISliderProps, Mark } from './slider.type'
|
|
|
|
export const useMarks = (props: ISliderProps) => {
|
|
return computed(() => {
|
|
if (!props.marks) {
|
|
return []
|
|
}
|
|
|
|
const marksKeys = Object.keys(props.marks)
|
|
return marksKeys
|
|
.map(parseFloat)
|
|
.sort((a, b) => a - b)
|
|
.filter((point) => point <= props.max && point >= props.min)
|
|
.map(
|
|
(point): Mark => ({
|
|
point,
|
|
position: ((point - props.min) * 100) / (props.max - props.min),
|
|
mark: props.marks[point],
|
|
})
|
|
)
|
|
})
|
|
}
|