I can't offer you any code, but I can provide my usual rambling on it.
Gizmos are fairly simple- when you begin dragging any part of one, you should treat the mouse as if it were moving along a 3D plane aligned to where the gizmo is moving. E.g., dragging X would use a plane aligned along the XZ axises and based on the mouse's position on (so to speak) the plane, set it to the mouse's X position. Y would be YX (or YZ, or pick the one closest to the camera's view direction), Z would be ZX, etc. Picking which plane for single axises to use is probably best decided based on your camera's view direction, rather than hard-coding a specific one.
Hopefully that made something close to sense.
Short version:
1. Select axis
2. Align plane to axis (based on view direction where necessary)
3. Project 2D mouse onto 3D plane
4. Use the value of the projected point to set the new value
Gizmos are fairly simple- when you begin dragging any part of one, you should treat the mouse as if it were moving along a 3D plane aligned to where the gizmo is moving. E.g., dragging X would use a plane aligned along the XZ axises and based on the mouse's position on (so to speak) the plane, set it to the mouse's X position. Y would be YX (or YZ, or pick the one closest to the camera's view direction), Z would be ZX, etc. Picking which plane for single axises to use is probably best decided based on your camera's view direction, rather than hard-coding a specific one.
Hopefully that made something close to sense.
Short version:
1. Select axis
2. Align plane to axis (based on view direction where necessary)
3. Project 2D mouse onto 3D plane
4. Use the value of the projected point to set the new value