What type of component would be required?
A good way to measure (static) magnetic fields is to use a Hall effect sensor. 

http://en.wikipedia.org/wiki/Hall_effect_sensor

They are typically used for position sensing, and it is possible to get either analog sensors (which measure the strength of the field, which may correspond to distance) or digital sensors, which just measure if the field exceeds a threshold.