【问题标题】:react-step-progress bar styling customizationreact-step-progress 栏样式自定义
【发布时间】:2021-12-06 06:35:58
【问题描述】:

我正在使用 react 中提供的 react-step-progress[enter link description here][1] 库创建一个进度条。它已经从react-step-progress/dist/index.css 获取了自己的样式参考。但是,我想覆盖它们提供的颜色。我试图通过创建自己的 sass 文件并引用这些类来覆盖,但它们似乎没有覆盖现有样式。

有人可以帮我改写这些样式吗?

我参考了以下链接。 https://www.npmjs.com/package/react-step-progress?activeTab=readme

我尝试通过以下方式覆盖。 我在我的 tsx 文件中导入了我自己的 scss 文件,其中包含我想要的所需样式。 然后我像这样在进度条标签中引用了我各自的类。

iconStyles.module.scss

.ProgressBar {
.stepColor {
    color:#ffffff;
    background-color: #26890D;
  } 
}

我已经通过以下方式将这个类导入到我的 tsx 文件中:

Progressbar.tsx

import styles from './iconStyles.module.scss';
import * as React from 'react';
import StepProgressBar from 'react-step-progress';

const step2Content = <h1>Step1</h1>;
const step3Content = <h1> Step 2</h1>;
const step4Content = <h1> Step3 </h1>;

export default function ProgressBar() {
  // setup step validators, will be called before proceeding to the next step

  function step2Validator() {
    // return a boolean
  }

  function step3Validator() {
    // return a boolean
  }

  // render the progress bar
  return (
    <div>
      <StepProgressBar
       className={styles.stepColor}
        startingStep={0}
        steps={[
          {
            label: 'Step1',
            name: 'Step1',
            content: step1Content
          },
          {
            label: 'Step2',
            name: 'Step2',
            content: step2Content,
            validator: step2Validator
          },
          {
            label: 'Step3',
            name: 'Step3',
            content: step3Content,
            validator: step3Validator
          }
        ]} onSubmit={undefined} />
    </div>
  );
}

【问题讨论】:

  • 如果你能提供你迄今为止尝试过的代码的相关部分,那将有很大帮助:)
  • 是的,我相应地添加了它:)

标签: css reactjs sass


【解决方案1】:

要控制用于每个步骤的类,您需要使用stepClass 属性而不是className 属性:

  [...]
  return (
    <div>
      <StepProgressBar
        stepClass={styles.stepColor}
        startingStep={0}
        steps={ [...] }
        onSubmit={undefined} />
    </div>
  );

【讨论】:

  • 现在这是一个进度条,对于已完成的、活动的和下一步正确的步骤会有不同的颜色。您能否让我知道如何实现这一点,因为我们将只使用一个元素 。我们可以在 stepClass 属性中给出多个类名吗?
  • 这实际上并没有覆盖 提供的原始颜色。
  • 提供了一些自定义样式的道具,但它们似乎没有起到作用
  • @DSR 我看到你已经嵌套了你的 CSS 选择器。通过确保.stepColor 不包含在.ProgressBar 中来尝试展平结构
  • 是的,我会试试这个,谢谢!
猜你喜欢
  • 2021-08-05
  • 2016-09-25
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-16
  • 2021-04-02
  • 1970-01-01
相关资源
最近更新 更多