I loath those things. There is no legal way to connect them to the line and then leave the box. These are the most abused components in domestic lighting products. the primary and secondary leads must use the same voltage class of wire if there is no barrier and are only approved as a component part of a fixture.
The outputs are marked class 2 but in order to enjoy class 2 relaxations the line must be seperated from the load by a barrier or spaced in such a way as it is impossible to make contact with the input wires with the output. These transformers were designed to provide low voltage output for the bulb but inside of a fixture canopy or luminaire.
The legal way to wire undercounter low voltage lighting is with a transformer that has a plug and load connector hard wired at the factory for external use and plugged into a switched outlet with no dimmer.
Or use a barriered box that seperated the line and load wiring.
If you can find a 75 0r 100 va class 2 doorbell transformer that mounts on a box, that would be legal but maybe not compatible to the fixtures?