vue-styled-components / core

A CSS tool similar to styled-components for Vue3.js. Help you to develop your apps quickly!
https://vue-styled-components.com
Apache License 2.0
65 stars 3 forks source link

【关于给styled.div等声明方式生成的组件,赋予class属性时,出现的bug,请详见描述和代码截图】 #32

Open panchaoco opened 6 days ago

panchaoco commented 6 days ago

bug描述

当我给styled.div等声明方式生成的组件,赋予class属性时,由插件自动生成的styled-xxxx类名被覆盖了而不是合并,导致样式失效

Reproduce link

No response

To reproduce

const GameHeaderLayout = styled.div`
  display: flex;
  align-items: center;
  gap: 0 4px;
  padding: 12px 0;
  position: relative;
  &.is-line {
    &::after {
      position: absolute;
      content: '';
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      background-color: ${props => props.theme.border100};
      transform: scaleY(0.5);
    }
  }
  .title {
    color: ${props => props.theme.primary};
    font-family: 'PingFang SC';
    font-size: 14px;
    font-style: normal;
    font-weight: 500;
    line-height: 16px; /* 114.286% */
  }
`

type StatisticsHeaderProps = {
  title: string
  icon: VNode
  isLine?: boolean
}

export const GameHeader: FunctionalComponent<StatisticsHeaderProps> = props => {
  const { isLine = true } = props
  return (
    <GameHeaderLayout
      className={classNames('game-header', {
        'is-line': isLine,
      })}
    >
      {props.icon}
      <div className="title">{props.title}</div>
    </GameHeaderLayout>
  )
}

以上的代码,如果给GameHeaderLayout复制一个class或者className, 会导致样式丢失, 经过排查,发现如下截图描述的问题:

image

Expected behavior

期望当我赋值类名给styled的组件时,类名是应该是合并而不是覆盖重置

Actual behavior

No response

Package version

No response

Framework version

No response

Node version

No response

Browsers version

No response

OS version

No response

Additional context

No response

akinoccc commented 6 days ago

className是会把原有的类名都覆盖掉,试下用class吧,class是没问题的

panchaoco commented 6 days ago

className是会把原有的类名都覆盖掉,试下用class吧,class是没问题的

好的,谢谢