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

Compatibility with styled-components #321

Closed
tpinne opened this issue Sep 21, 2020 · 11 comments
Closed

Compatibility with styled-components #321

tpinne opened this issue Sep 21, 2020 · 11 comments

Comments

@tpinne
Copy link

tpinne commented Sep 21, 2020

It would be nice to have direct compatibility with styled-component by accepting the standard className prop as alternative to the containerClassName prop. Otherwise styling with styled-components is only possible by wrapping the component in an extra wrapper component.

const StyledReactPaginate = styled(ReactPaginate)`
  a {
    cursor: pointer;
  }
  .selected {
    background: lime;
  }
`;
@definoob
Copy link

definoob commented Sep 21, 2020

Same here.
Tried the code below but doesn't work.

const Paginate = styled(ReactPaginate).attrs({
  containerClassName: "container",
  breakClassName: "break-me",
  activeClassName: "active"
})`
  &.container {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    list-style-type: none;
  }
  &.break-me {
    cursor: default;
  }
  &.active {
    background-color: #0366d6;
    border-color: transparent;
    color: white;
    min-width: 32px;
  }
`;

Anyway, classNames are applied.

@tpinne
Copy link
Author

tpinne commented Sep 21, 2020

Try break-me and active without the & because they are applied to elements further down the Dom. The container Styles should be applied though, as I guess from the couch.

@definoob
Copy link

Container is not applied.

@tpinne
Copy link
Author

tpinne commented Sep 22, 2020

My bad, has been late. The essential generated classname from styled components is still missing, of course.

@shadrech
Copy link

shadrech commented Oct 1, 2020

Any plans to make this compatible with styled-components?

@mikdatdogru
Copy link

I temporarily solved this problem by wrapping it with the styled component.

const StyledPaginateContainer = styled.div`
  .pagination {
    color: #0366d6;
  }
  .break-me {
    cursor: default;
  }
  .active {
    border-color: transparent;
    background-color: #0366d6;
    color: white;
  }
`;
<StyledPaginateContainer>
    <ReactPaginate
     previousLabel="previous"
     nextLabel="next"
     breakLabel="..."
     breakClassName="break-me"
     pageCount={20}
     marginPagesDisplayed={2}
     pageRangeDisplayed={5}
     onPageChange={pagination => {
        console.log(pagination);
     }}
     containerClassName="pagination"
     activeClassName="active"
        />
</StyledPaginateContainer>

image

@tpinne
Copy link
Author

tpinne commented Oct 1, 2020

I temporarily solved this problem by wrapping it with the styled component.

We use the same approach to work around that even before I opened this issue. But compatibility would be easily achieved with making (additional) use of the standard className prop.

Personally I don't like having to use a special prop just to assign the class name for the outer most container of a component.

@amantiwari1
Copy link

amantiwari1 commented Jan 4, 2021

I temporarily solved this problem by wrapping it with the styled component.

but it is not working for .pagination > .active > a any idea how to fix it?

@makotot
Copy link

makotot commented Jan 16, 2021

I was facing same issue and so have created headless pagination component like this.

@MonsieurV
Copy link
Collaborator

Hi,

We've added the className prop. Tell us if you still encounter any issue with styled-components.

Thanks for the reports and workarounds!

@MonsieurV
Copy link
Collaborator

You can find an example in demo with styled-components:

https://github.com/AdeleD/react-paginate/blob/master/demo/js/demo.js#L11

#397

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

7 participants