All Projects → mohux → react-brackets

mohux / react-brackets

Licence: other
Reusable and customizable react brackets component, you can use it to build components such as single elimination, or double elimination brackets

Programming Languages

typescript
32286 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-brackets

Brackets Beautify
Beautify HTML, CSS, and Javascript in Adobe Brackets
Stars: ✭ 606 (+982.14%)
Mutual labels:  brackets
Brackets Extension Rating
Brackets extension used to display other extensions rating
Stars: ✭ 72 (+28.57%)
Mutual labels:  brackets
OpenSCAD connectors
Simple, parametric APIs for connectors such as corner brackets and t-joints. Specializing on connectors for aluminum extrusion connectors.
Stars: ✭ 29 (-48.21%)
Mutual labels:  brackets
New Moon Brackets
New Moon Theme for Brackets.
Stars: ✭ 19 (-66.07%)
Mutual labels:  brackets
Swackets
Empowers your brackets with colours.
Stars: ✭ 69 (+23.21%)
Mutual labels:  brackets
Lh Cpp
C&C++ ftplugins suite for Vim
Stars: ✭ 108 (+92.86%)
Mutual labels:  brackets
Jquery Bracket
jQuery Bracket library for organizing single and double elimination tournaments
Stars: ✭ 427 (+662.5%)
Mutual labels:  brackets
brackets-light-pro
🌄 Brackets Light Pro Theme for VSCode
Stars: ✭ 86 (+53.57%)
Mutual labels:  brackets
Brackets Documents Toolbar
Extension that adds new toolbar with a list of all open documents.
Stars: ✭ 69 (+23.21%)
Mutual labels:  brackets
React Tournament Bracket
React components for rendering a tournament bracket
Stars: ✭ 181 (+223.21%)
Mutual labels:  brackets
Brackets Tree Icons
Brackets icons with folder icon
Stars: ✭ 28 (-50%)
Mutual labels:  brackets
Bughunt
A weekly challenge where we share some code and you find a bug in it.
Stars: ✭ 68 (+21.43%)
Mutual labels:  brackets
Brackets Portable
Windows portable version of adobe brackets web development editor.
Stars: ✭ 124 (+121.43%)
Mutual labels:  brackets
Dreamphp
A dream theme for Brackets IDE that simulates PHP coloring scheme of Dreamweaver
Stars: ✭ 6 (-89.29%)
Mutual labels:  brackets
bracketstoix
Brackets Utility Belt
Stars: ✭ 46 (-17.86%)
Mutual labels:  brackets
Highlightbracketpair
🔆 Highlight bracket pair plugin for intellij
Stars: ✭ 428 (+664.29%)
Mutual labels:  brackets
Brackets Outline List
Brackets Extension to display a list of the functions or definitions in the currently opened document.
Stars: ✭ 77 (+37.5%)
Mutual labels:  brackets
Cake
Yummy syntax theme for Atom, Brackets, Sublime Text and Visual Studio Code
Stars: ✭ 47 (-16.07%)
Mutual labels:  brackets
doorboy.vim
Vim plugin for auto closing brackets ( => (|) and quotations " => "|" , and more
Stars: ✭ 19 (-66.07%)
Mutual labels:  brackets
Custom Work For Brackets
<involuntarily lost source code> ____ Adds toolbar it include buttons show/hide with tabs of active documents on the top of the editor.
Stars: ✭ 126 (+125%)
Mutual labels:  brackets

react-brackets

Dynamic bracket component, usable for brackets such as single elimination and double elimination

NPM JavaScript Style Guide

react-brackets react-brackets

Install

via npm

npm install --save react-brackets

via yarn

yarn add --save react-brackets

Usage

The simplest usage of this component is

import { Bracket, RoundProps } from 'react-brackets';

const rounds: RoundProps[] = [
  {
    title: 'Round one',
    seeds: [
      {
        id: 1,
        date: new Date().toDateString(),
        teams: [{ name: 'Team A' }, { name: 'Team B' }],
      },
      {
        id: 2,
        date: new Date().toDateString(),
        teams: [{ name: 'Team C' }, { name: 'Team D' }],
      },
    ],
  },
  {
    title: 'Round one',
    seeds: [
      {
        id: 3,
        date: new Date().toDateString(),
        teams: [{ name: 'Team A' }, { name: 'Team C' }],
      },
    ],
  },
];

const Component = () => {
  return <Bracket rounds={rounds} />;
};

The core shape is similar to the above, since we can customize seeds and titles, you can pass any additional data to a seed or treat the title as a component.

modifying a title of the round is so simple,

import { Bracket, RoundProps } from 'react-brackets';
import React from 'react';

const Component = () => {
  //....
  return (
    <Bracket
      rounds={rounds}
      roundTitleComponent={(title: React.ReactNode, roundIndex: number) => {
        return <div style={{ textAlign: 'center', color: 'red' }}>{title}</div>;
      }}
    />
  );
};

Customizing a seed on the other hand is a little bit more complicated, yet still easy, because we need to let the bracket tree to have a consitent design

Any additional data you pass inside a seed object is accessibile via renderSeedComponent

import { Bracket, RoundProps, Seed, SeedItem, SeedTeam, RenderSeedProps } from 'react-brackets';
import React from 'react';

const CustomSeed = ({seed, breakpoint, roundIndex, seedIndex}: RenderSeedProps) => {
  // breakpoint passed to Bracket component
  // to check if mobile view is triggered or not

  // mobileBreakpoint is required to be passed down to a seed
  return (
    <Seed mobileBreakpoint={breakpoint} style={{ fontSize: 12 }}>
      <SeedItem>
        <div>
          <SeedTeam style={{ color: 'red' }}>{seed.teams[0]?.name || 'NO TEAM '}</SeedTeam>
          <SeedTeam>{seed.teams[1]?.name || 'NO TEAM '}</SeedTeam>
        </div>
      </SeedItem>
    </Seed>
  );
};

const Component = () => {
  //....
  return <Bracket rounds={rounds} renderSeedComponent={CustomSeed} />;
};

How about if I want to use this component for double elimination losing bracket? the current Seed component only works on single elimination, the answer is fairly simple as well.

import { Bracket, RoundProps, Seed, SingleLineSeed, SeedItem, SeedTeam, RenderSeedProps } from 'react-brackets';
import React from 'react';

const CustomSeed = ({seed, breakpoint, roundIndex, seedIndex}: RenderSeedProps) => {
  // ------ assuming rounds is the losers brackets rounds ------
  // losers rounds usually got some identical seeds amount like (2 - 2 - 1 - 1)

  const isLineConnector = rounds[roundIndex].seeds.length === rounds[roundIndex + 1]?.seeds.length;

  const Wrapper = isLineConnector ? SingleLineSeed : Seed;

  // mobileBreakpoint is required to be passed down to a seed
  return (
    <Wrapper mobileBreakpoint={breakpoint} style={{ fontSize: 12 }}>
      <SeedItem>
        <div>
          <SeedTeam style={{ color: 'red' }}>{seed.teams[0]?.name || 'NO TEAM '}</SeedTeam>
          <SeedTeam>{seed.teams[1]?.name || 'NO TEAM '}</SeedTeam>
        </div>
      </SeedItem>
    </Wrapper>
  );
};

const Component = () => {
  //....
  return <Bracket rounds={rounds} renderSeedComponent={CustomSeed} />;
};

Bracket Props

Prop Type Description
rounds RoundProps[] Array of rounds, each round has {title,array of seeds}, if you're not using a custom seed render, each seed needs an array of teams, each team should have a name
mobileBreakpoint number This bracket supports responsive design, on window reaching this size, it will trigger mobile swipable view, if you want to disable it, you can pass 0, (default is 992)
rtl boolean Direction of the bracket as RTL (default is LTR)
roundClassName string Round wrapper className
bracketClassName string The bracket className
renderSeedComponent functional component Custom render for every seed
roundTitleComponent functional component Custom render for every round title
swipeableProps SwipeableProps Please check this React Swipeable Views

For detailed examples, you can clone this repo then:

you can skip starting the root folder, but if you want to modify the library you have to run it.

yarn

then

yarn start

then open a new terminal

cd example

then

yarn

lastly

yarn start

License

MIT © mohammadou1

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].