Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unequal columns with bootstrap. #138

Open
jonathanpuc opened this issue Sep 12, 2018 · 4 comments
Open

Unequal columns with bootstrap. #138

jonathanpuc opened this issue Sep 12, 2018 · 4 comments

Comments

@jonathanpuc
Copy link

When trying to use unequal columns of a width with bootstrap and a column is of 7 columns or higher, all the elements in the masonry layout just sit on their own row and no longer next to each other.

E.g trying to achieve a layout with some divs being 8 columns wide and others 4 columns wide (12 column grid) but they don't sit on one line together.

The closest thing that works is something like 6 column wide with 4 column wide elements.

@afram
Copy link
Collaborator

afram commented Sep 14, 2018

do you have an example I can take a look at please?

@jonathanpuc
Copy link
Author

jonathanpuc commented Sep 17, 2018

Attached an image of what it looks like, notice how they don't sit next to each other? This is with col-sm-8 and col-sm-4 bootstrap classes. If I try with col-sm-7 and col-sm-4 they still don't sit next to each other. col-sm-6 and col-sm-4 is fine though.

This only happens when the elements are wrapped by the Masonry HOC. If I remove it, the grid system is all okay and col-sm-8 next to col-sm-4 works fine.

screen shot 2018-09-17 at 9 55 50 am

const masonryOptions = {
  transitionDuration: 0
}

class Factoids extends React.Component<IProps, {}> {


  public render() {
    // factoids that are relevant based on the current class assets selected.
    const activeFactoids: any[] = this.props.factoidData.filter(factoid =>
      this.props.classSelections.some((classId: number) =>
        factoid.classes.includes(classId)
      )
    )

    // elements to render in masonry
    const elements = activeFactoids.map((factoid: any) => {

      const width =
        factoid.acf.factoid_width === 'Double'
          ? 'col-xs-12 col-sm-8'
          : 'col-xs-12 col-sm-4'

      if (factoid.acf.factoid_content[0].acf_fc_layout === 'simple') {
        return (
          <div
            className={width}
            key={factoid.id}
            style={{ marginBottom: '20px', transition: 'all 0.5s' }}
          >
            <Simple
              item={factoid}
              onSelect={this.handleFactoidSelect}
              onRemove={this.handleFactoidRemove}
            />
          </div>
        )
      } else {
        return (
          <div
            className={width}
            key={factoid.id}
            style={{ marginBottom: '20px', transition: 'all 0.5s' }}
          >
            <Double
              item={factoid}
              onSelect={this.handleFactoidSelect}
              onRemove={this.handleFactoidRemove}
            />
          </div>
        )
      }
    })
    return (
      <Outer>
        <h2>
          To help us make the right recomendations, select the relevant class
          assets.
        </h2>
        <ClassChips />
        <div className="container-fluid">
          <div className="row">
            <Masonry
              options={masonryOptions}
              disableImagesLoaded={false}
              updateOnEachImageLoad={false}
            >
              {elements}
            </Masonry>
          </div>
        </div>
        <Button
          variant="fab"
          aria-label="next"
          style={{
            backgroundColor: '#92D1DB',
            position: 'absolute',
            right: 0,
            bottom: '20px'
          }}
          onClick={this.next}
        >
          <ArrowForwardIcon style={{ color: '#fff' }} />
        </Button>
      </Outer>
    )
  }
}

const mapStateToProps = (state: IStoreState) => ({
  classSelections: state.views.new.selections.classes,
  factoidData: state.data.factoids
})

export default withRouter(
  connect(
    mapStateToProps,
    { addFactoid, removeFactoid }
  )(Factoids)
)

const Outer = styled.div`
  position: relative;
  width: 95%;
  margin: 0 auto;
  h2 {
    color: #717271;
    font-weight: 400;
  }

  .masonry {
    display: flex;
    flex-direction: row;
  }

@jonathanpuc
Copy link
Author

@afram any updates?

@mayteio
Copy link

mayteio commented Nov 8, 2018

@afram I have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants