It appears constitutional, but also renders the state less relevant in the national elections. Since they are no longer all or nothing, purple states doing this will begin to get ignored as full electoral states will offer more ROI on the national scene.
That has the potential to pay a price down ticket that they may not be thinking of.
I may be wrong, but I believe the states participating in this are not allocating their electors proportionally according to the popular vote - I think they are awarding ALL of their electors to the winner of the popular vote. That is why the law does not go into effect until states with 270 electoral votes pass the law - that insures that all 270 of those electoral votes go to the winner of the popular vote, guaranteeing that the winner of the popular vote is the winner of the electoral college vote.