3-4 days: Trancoso only
Enough time to enjoy the Quadrado properly, see 2-3 beaches at a relaxed pace, and take your time at restaurants. Works well for repeat visitors or anyone with limited travel time.
5-7 days: Trancoso plus day trips
With a week, you can set aside a full day for Praia do Espelho (remember to check the low tide) and another for Caraíva, which is worth more with at least one overnight stay than as a quick day trip, according to travelers who've done both.
More than a week
If time allows, consider staying in Caraíva itself for 2-3 nights instead of just a day trip, and add Arraial d'Ajuda to the itinerary. Itacaré doesn't fit into this — it's in a different part of Bahia and calls for a separate trip.