question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to style using Styled Components (Doc: https://fkhadra.github.io/react-toastify/how-to-style/#how-to-style-with-styled-components)

See original GitHub issue

Are there any examples where <ToastContainer /> can be styled using styled-components?

Currently doing this:

const ReactToastAdapter = ({ className, bodyClassName, progressClassName, ...props }) => {
  return  (
    <ToastContainer
      className={className}
      bodyClassName={bodyClassName}
      progressClassName={progressClassName}
      {...props}
    />
  )
};

const StyledToastContainer = styled(ReactToastAdapter).attrs({
  bodyClassName: 'body',
  progressClassName: 'progress',
})`
  /* .Toastify__toast-container */
  bottom: 0;
  left: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  .Toastify__close-button {
    display: none;
  }
  .Toastify__toast {
    background-color: var(--color-black);
    margin: 0;
    cursor: auto;
  }
  .toast {
    background-color: var(--color-black);
  }
  .body {
    background-color: var(--color-black);
    color: var(--color-white);
    font-family: var(--default-font-family);
  }
`;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

39reactions
alextileycommented, Jul 19, 2019

For those interested, you can work-around the warning mentioned in @ezeikel last comment by creating a wrapper component and applying the className to that instead:

import React from 'react';
import styled from 'styled-components';
import { ToastContainer, ToastContainerProps } from 'react-toastify';

export const WrappedToastContainer = ({ className, ...rest }: ToastContainerProps & { className?: string }) => (
  <div className={className}>
    <ToastContainer {...rest} />
  </div>
);

export default styled(WrappedToastContainer).attrs({
  // custom props
})`
  .Toastify__toast-container {}
  .Toastify__toast {}
  .Toastify__toast--error {}
  .Toastify__toast--warning {}
  .Toastify__toast--success {}
  .Toastify__toast-body {}
  .Toastify__progress-bar {}
`;
10reactions
JrFariascommented, May 17, 2019

Yeah, I’ll fork this project and send a PR with the modification asap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled Components - GitHub
Use the best bits of ES6 and CSS to style your apps without stress - GitHub - styled-components/styled-components: Visual primitives for the component ......
Read more >
styled-components/tips-and-tricks.md at main - GitHub
A collection of useful tips and tricks when working with styled-components ! Component adjustments. Say you have a <Button> that has a padding...
Read more >
VSCode Styled Components - GitHub
Syntax Highlighting is specifically made to work with styled so make sure your default import is styled and nothing else. ... Secondly make...
Read more >
styled-components - GitHub
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress - styled-components.
Read more >
A curated list of awesome styled-components resources - GitHub
Components. react-data-table-component - Data Table with built in sorting, pagination, selection, expandable rows and customizable styling.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found