Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

A lot of extra props being shown despite proper interface #65

Open
kvedantmahajan opened this issue Sep 30, 2019 · 1 comment
Open

A lot of extra props being shown despite proper interface #65

kvedantmahajan opened this issue Sep 30, 2019 · 1 comment

Comments

@kvedantmahajan
Copy link

kvedantmahajan commented Sep 30, 2019

Read the docs and I see that I've done everything right. Have a typed functional component with named export and can see somehow a lot more entries in prop table apart from normal props.

Below is my component which renders a whole lot of extra props. I mean a lot of extra hrefLang, download, draggable , lang, tabIndex and what not. I see propFilter options under Loader Options but again not sure how to use it if it all it can help in my case. Docs can be more clear.

import * as React from "react";
import styled from "styled-components";
import {
	ButtonProps,
	ButtonStyles,
	LinkStyles
} from "@turtlemint/tm-components-shared/src/components/button";

const StyledButton = styled.button<ButtonProps>`
	${ButtonStyles};
`;
const StyledLink = styled.a<ButtonProps>`
	${LinkStyles};
`;

export const Button: React.FC<ButtonProps> = ({
	btnType = "primary",
	size = "sm",
	disabled = false,
	block = false,
	icon = "",
	loading = false,
	className = "",
	prefixCls = "tm-button",
	onClick = function() {},
	href = "#",
	target = "blank",
	htmlType = "button",
	children = <></>,
	...rest
}: ButtonProps) => {
	const handleClick: React.MouseEventHandler<
		HTMLButtonElement | HTMLAnchorElement
	> = e => {
		if (btnType === "link") {
			e.preventDefault();
		}
		onClick(e);
	};
	return (
		<>
			{loading ? (
				<StyledButton
					btnType={btnType}
					size={size}
					block={block}
					disabled={disabled}
				>
					Loading...
				</StyledButton>
			) : (
				<>
					{btnType === "link" ? (
						<StyledLink
							href={href}
							target={target}
							disabled={disabled}
							{...rest}
						>
							{children}
						</StyledLink>
					) : (
						<StyledButton
							onClick={handleClick}
							btnType={btnType}
							size={size}
							block={block}
							disabled={disabled}
							type={htmlType}
							className={`${prefixCls}-${className} `}
							{...rest}
						>
							<span
								style={{
									verticalAlign: "middle",
									marginLeft: icon ? "8px" : "0px"
								}}
							>
								{children}
							</span>
						</StyledButton>
					)}
				</>
			)}
		</>
	);
};

export default Button;

Notes - Docs can also be updated for the fact that I can use different name for add("AnyName") when my component is <Button>

@beckerei
Copy link

beckerei commented Jan 3, 2020

#20 (comment)

is a good start, but it needs some more tweaks now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants