如何添加类型的样式组件
我正在使用antd
进行工具提示,并且想将Props 左
添加到样式的组件中。
当我将悬停在样式组件中留下的道具时,我会遇到以下错误:
Property 'left' does not exist on type 'ThemedStyledProps<(TooltipProps & RefAttributes<unknown>) & {}, DefaultTheme>'.
Property 'left' does not exist on type 'TooltipPropsWithTitle & RefAttributes<unknown> & ThemeProps<DefaultTheme>'.ts(2339)
import styled from 'styled-components';
import { Tooltip as TooltipAnt } from 'antd';
export const Children = styled.div`
position: relative;
display: inline;
> * {
position: relative;
display: inline;
}
`;
export const Tooltip = styled(TooltipAnt)`
.ant-tooltip-content {
position: relative;
overflow-x: hidden;
overflow-y: visible;
padding-bottom: 20px;
display: inline-block;
}
.ant-tooltip {
left: ${props => props.left || 0} !important;
}
.ant-tooltip-arrow {
display: none;
}
.ant-tooltip-inner {
padding: 10px 15px;
background: white;
display: inline-block;
border-radius: 10px;
border: 3px solid #D04A02;
border-bottom-right-radius: 0;
z-index: 2;
max-width: 200px;
color: #000;
box-shadow: none;
word-wrap: break-word;
}
.ant-tooltip-content:before {
content: '';
position: absolute;
width: 25px;
height: 25px;
background: white;
bottom: 14px;
right: -8px;
transform: rotate(25deg);
border-bottom: 3px solid #D04A02;
}
.ant-tooltip-content:after {
content: '';
width: 3px;
background: #D04A02;
height: 50%;
position: absolute;
right: -0.5px;
bottom: 12px;
}
`;
import * as Styled from './Tooltip.styles';
type Props = {
title: string;
children: React.ReactNode;
left?: string;
};
export const CustomTooltip = ({ title, children, left }: Props) => (
<Styled.Tooltip
title={title}
getPopupContainer={(triggerNode) => triggerNode}
left={left}
>
<Styled.Children>{children}</Styled.Children>
</Styled.Tooltip>
);
I am making tooltip using antd
and I would like to add props left
to styled components.
I am getting following error when I hover left prop in styled components:
Property 'left' does not exist on type 'ThemedStyledProps<(TooltipProps & RefAttributes<unknown>) & {}, DefaultTheme>'.
Property 'left' does not exist on type 'TooltipPropsWithTitle & RefAttributes<unknown> & ThemeProps<DefaultTheme>'.ts(2339)
import styled from 'styled-components';
import { Tooltip as TooltipAnt } from 'antd';
export const Children = styled.div`
position: relative;
display: inline;
> * {
position: relative;
display: inline;
}
`;
export const Tooltip = styled(TooltipAnt)`
.ant-tooltip-content {
position: relative;
overflow-x: hidden;
overflow-y: visible;
padding-bottom: 20px;
display: inline-block;
}
.ant-tooltip {
left: ${props => props.left || 0} !important;
}
.ant-tooltip-arrow {
display: none;
}
.ant-tooltip-inner {
padding: 10px 15px;
background: white;
display: inline-block;
border-radius: 10px;
border: 3px solid #D04A02;
border-bottom-right-radius: 0;
z-index: 2;
max-width: 200px;
color: #000;
box-shadow: none;
word-wrap: break-word;
}
.ant-tooltip-content:before {
content: '';
position: absolute;
width: 25px;
height: 25px;
background: white;
bottom: 14px;
right: -8px;
transform: rotate(25deg);
border-bottom: 3px solid #D04A02;
}
.ant-tooltip-content:after {
content: '';
width: 3px;
background: #D04A02;
height: 50%;
position: absolute;
right: -0.5px;
bottom: 12px;
}
`;
import * as Styled from './Tooltip.styles';
type Props = {
title: string;
children: React.ReactNode;
left?: string;
};
export const CustomTooltip = ({ title, children, left }: Props) => (
<Styled.Tooltip
title={title}
getPopupContainer={(triggerNode) => triggerNode}
left={left}
>
<Styled.Children>{children}</Styled.Children>
</Styled.Tooltip>
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我曾经遇到过一个类似的问题,唯一修复的是将符号更改为包括该元素的道具:
I ran to a similar problem once and the only thing that fixed it was changing the notation to include the prop on the element: