Most of them use a hall effect sensor and moving magnets. You can use a potentiometer as well, but those tend to have limited life as the wiper wears out.
There are several variations on the magnet/hall sensor arrangement. I've seen both single and dual magnet setups.
Below is a two magnet type.