Extend existing component with additional prop for styling

PHOTO EMBED

Thu Feb 03 2022 15:15:52 GMT+0000 (Coordinated Universal Time)

Saved by @avivdaniel #javascript

// Note the $ prefix in the prop name             👇
const StyledToggleButton = styled(ToggleButton)<{ $hasMargin?: boolean }>`
  && {
    color: red;

    // Just use the prop as normal
    ${(props) =>
      props.$hasMargin &&
      css`
        margin: 10px;
      `}
  }
`;

<StyledToggleButton
  value={""}
  size={"small"}
  {/* Assign the prop as normal */}
  $hasMargin={true}
>
  click
</StyledToggleButton>;
content_copyCOPY

https://stackoverflow.com/questions/66170184/styled-components-extend-existing-component-with-additional-prop-for-styling