Files
element-plus/packages/components/slider/src/useMarks.ts
三咲智子 55348b30b6 style: use prettier (#3228)
* style: use prettier

* style: just prettier format, no code changes

* style: eslint fix
object-shorthand, prefer-const

* style: fix no-void

* style: no-console
2021-09-04 19:29:28 +08:00

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],
})
)
})
}