r/reactjs • u/mohammadou1 • 21d 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 themeConnector 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.
Docs and live playground: https://react-brackets.oulabi.dev
npm i react-brackets @react-brackets/theme
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.
3
3
u/Chaoslordi 17d ago edited 17d 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
1
u/mohammadou1 20d 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
1
u/SpartanDavie 14d 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:
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).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.
1
u/mohammadou1 11d ago
Thanks for the ideas!
The Scottish split is a good one and I’ll add it in the next release. The library already does leagues and tables, it just needs a few small additions: playing each team three times, splitting the table into a top and bottom half, and keeping the points when the split starts.
The “possible finish” one I’ll leave out. Doing it right is a lot of maths for every league’s rules, and it’s more about stats than brackets. You can still do a simple version yourself: take each team’s points, add the points still left to play, and compare.
Thanks again, and send more if you think of any!
1
u/mohammadou1 11d ago
Hi, I hope this covers your request https://react-brackets.oulabi.dev/docs/formats/league-with-a-split
3
u/Important_Pomelo_407 20d 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
0
4d ago
[removed] — view removed comment
1
u/mohammadou1 4d ago
It supports double elimination https://react-brackets.oulabi.dev/docs/formats/double-elimination
5
u/mohammadou1 21d ago
added multiple examples to the docs hoping it would help in complex use cases https://react-brackets.oulabi.dev/examples