Skip to content

Instantly share code, notes, and snippets.

@snigo
Last active October 5, 2023 14:46
Show Gist options
  • Save snigo/9c722e502b98dd5ef91937fb63146a67 to your computer and use it in GitHub Desktop.
Save snigo/9c722e502b98dd5ef91937fb63146a67 to your computer and use it in GitHub Desktop.
SOLID React article, code snippet 2: Button component with iconStart and iconEnd
interface ButtonProps
extends React.PropsWithChildren,
React.HTMLAttributes<HTMLButtonElement> {
/**
* @deprecated Use `iconStart` instead
*/
icon?: React.ReactNode;
iconStart?: React.ReactNode;
iconEnd?: React.ReactNode;
}
export const Button: React.FunctionComponent<ButtonProps> = ({
children,
icon,
iconStart = icon, // Fallback to `icon` if not provided
iconEnd,
...props
}) => {
return (
<button {...props} className="Button">
<span className="ButtonContent">
{iconStart && <span className="ButtonContentNode">{iconStart}</span>}
<span className="ButtonContentNode">{children}</span>
{iconEnd && <span className="ButtonContentNode">{iconEnd}</span>}
</span>
</button>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment