Skip to content

Instantly share code, notes, and snippets.

@snigo
Created October 5, 2023 15:08
Show Gist options
  • Save snigo/0f6ead039273d6a52330751983750fb6 to your computer and use it in GitHub Desktop.
Save snigo/0f6ead039273d6a52330751983750fb6 to your computer and use it in GitHub Desktop.
SOLID React article, code snippet 3: Button sub component
import { Button, ButtonProps } from './Button';
interface IconButtonProps extends Omit<ButtonProps, 'icon'> {
iconStart?: React.ReactNode;
iconEnd?: React.ReactNode;
}
export const IconButton: React.FunctionComponent<IconButtonProps> = ({
children,
iconStart,
iconEnd,
...props
}) => {
return (
<Button {...props}>
<span className="IconButtonContent">
{!!iconStart && (
<span className="IconButtonContentNode">{iconStart}</span>
)}
<span className="IconButtonContentNode">{children}</span>
{!!iconEnd && <span className="IconButtonContentNode">{iconEnd}</span>}
</span>
</Button>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment