Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

allow simple arithmetic in slider input field #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion lib/components/base/Slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,22 @@ const onInputWithSnap = (value: string) => {
inputValueValid(parsedValue)
}

const parseExpression = (value: string) => {
let tokens = value.match(/^\s*(\d+)\s*(\+|-|\*|\/)\s*(\d+)\s*$/)
if (tokens !== null) {
let [, a, op, b] = tokens

if (op === '+') return parseInt(a) + parseInt(b)
if (op === '-') return parseInt(a) - parseInt(b)
if (op === '*') return parseInt(a) * parseInt(b)
if (op === '/') return parseInt(a) / parseInt(b)
}

return parseInt(value)
}

const onInput = (value: string) => {
inputValueValid(parseInt(value))
inputValueValid(parseExpression(value))
}
</script>

Expand Down