mohux / react-brackets

Reusable and customizable react brackets component, you can use it to build components such as single elimination, or double elimination brackets
105 stars 47 forks source link

How to handle odd number of seeds? #5

Closed Tejp98 closed 3 years ago

Tejp98 commented 3 years ago
Screenshot 2021-05-05 at 7 20 14 PM

Can you please provide an approach on how to handle seeds with odd numbers or not in the power of 2? Please refer to the image.

mohux commented 3 years ago

@Tejp98 Hello buddy, You can update to latest version (4.6) which changes renderSeed to a new shape You still can make seed as custom as you want

import { ..., RenderSeedProps } from 'react-brackets';
const RenderSeed = ({ breakpoint, seed, roundIndex, seedIndex }: RenderSeedProps) => {}

Or you can use the current one and you can pass any additional data to the seed object and customize it as you like,

import { Bracket, Seed, SeedItem, SeedTeam, SeedTime } from 'react-brackets';

// You can reshape seed in rounds array and access the object here,
// you can pass index for example in seeds and access it here
const RenderSeed = (seed: any, breakpoint: number) => {
  return (
    <Seed mobileBreakpoint={breakpoint}>
      <SeedItem style={{ width: '100%' }}>
        <div>
          <SeedTeam>{seed.teams?.[0].name || '-----------'}</SeedTeam>
          <div style={{ height: 1, backgroundColor: '#707070' }}></div>
          <SeedTeam>{seed.teams?.[1]?.name || '-----------'}</SeedTeam>
        </div>
      </SeedItem>
      <SeedTime mobileBreakpoint={breakpoint} style={{ fontSize: 9 }}>
        {seed.date}
      </SeedTime>
    </Seed>
  );
};

<Bracket
      rounds={rounds}
      renderSeedComponent={RenderSeed}
    />