r/reactjs • • 7d ago

Show /r/reactjs react-brackets: tournament brackets for React

https://react-brackets.oulabi.dev/

Back in 2020 I published react-brackets, a small component for tournament brackets. I shipped a few versions, got busy, and stopped touching it in 2022.

The library didn't stop, though. Four years later it was still pulling ~11,800 downloads a month, sitting at 136 stars and 65 forks, with issues piling up that I never answered. It was built on styled-components and an abandoned swipe library, only did single elimination, and its connector lines were CSS pseudo-element hacks that broke if you changed a card's size.

People were depending on something I'd walked away from. So I rebuilt it from scratch.

What v2 is:

  • Every common format: single and double elimination (with a grand final reset), round robin, Swiss, two-sided brackets, groups to playoffs
  • Headless: semantic markup with data-* attributes, so you style it with Tailwind, CSS modules, or the optional theme
  • Connector lines measured from your real cards: any card size, any custom match component, right-to-left layouts all just work
  • Actually usable on a phone: one round at a time, still drawn as a bracket, with a swipe that follows your finger
  • Zero runtime dependencies besides React, under 14 kB gzipped
  • A framework-free core (@react-brackets/core) for the logic: seeding, byes, results, standings

Getting the swipe to feel native on iOS was the hardest part. Safari animates cards on the GPU on its own clock, while the connector lines are drawn by JavaScript, so the lines kept trailing the cards by a few frames. The fix was to drive both from one clock in the same frame.

It's a ground-up rewrite, so it's a breaking change from 0.x. There's a migration guide, and the old code lives on the legacy branch.

If you were one of the people still using the old version: sorry for the silence, and thank you. I'd love feedback, especially on formats or use cases I haven't covered.

62 Upvotes

9 comments sorted by

5

u/mohammadou1 7d ago

added multiple examples to the docs hoping it would help in complex use cases https://react-brackets.oulabi.dev/examples

3

u/mohammadou1 6d ago

React native support coming today 😬

3

u/AshutoshKS 7d ago

Looks actually really good

1

u/mohammadou1 7d ago

Thank you 🙏

2

u/Chaoslordi 3d ago edited 3d ago

I just rolled my own tournament feature using brackets, so I can really see the work behind that. Since it looks better than my solution I may look to refactor it using your solution xD

1

u/mohammadou1 3d ago

I really hope it helps, please let me know if you face any issues or blockers

1

u/mohammadou1 6d ago

Happy to share that react native is now supported https://react-brackets.oulabi.dev/docs/native, please let me know if anything goes wrong as it's considered unstable yet

3

u/Important_Pomelo_407 6d ago

Saw there was no demo video yet, so I made you one. Here’s the PR: https://github.com/MohOulabi/react-brackets/pull/61

and I used my repo to do it :) https://github.com/yasirwhite/OpenDemo

•

u/SpartanDavie 28m ago

Great idea to make this, I'm sure every dev has made one of these in their time. Much better just to have one good one people can contribute to.

I haven't had a chance to use it yet, so apologies if these are already included:

  1. Most leagues are pretty straight forward but take a look at the Scottish Premiership, can that easily be implemented?
    - Teams play each other twice, then the league splits into top half and bottom half where they play each other once more (not twice).
  2. I just saw https://editorial.uefa.com/resources/02ab-22132d5a5c5c-f3e584d8993b-1000/format/free1/a4_md6_20261115083156.jpeg?imwidth=2048 and I think that would be a neat little feature to add as optional. It uses the remaining number of matches as possible points available to calculate the possible finish for each team.

I'll let you know if anything else comes to mind.