2

我尝试通过样式颜色设置颜色,但它仅在未禁用时更改颜色。是否有可能使用或不使用 Fulma?

Button.button
    [
        Button.Disabled true
        Button.Props [
            Style [ Color "#000000" ] ]
        //if … then
        Button.OnClick (fun _ -> dispatch Msg)
    ]
    [ str "Text here" ]

作为最后的手段,我会使用带有调度功能的 if 条件,这样按钮就没有用了。

提前致谢。

4

2 回答 2

3

@nilekirk 解决方案确实是使用内联样式的正确方法。

但是如果你的应用程序中有很多按钮,它会使代码变得非常冗长。

另一种解决方案是将一些 CSS 直接应用于所有禁用的按钮,或者如果您不希望所有按钮都具有这种行为,则可以添加自定义类。

适用于应用程序的所有按钮

CSS 代码:

.button[disabled] {
    background-color: black !important;
}

F#代码:

Button.button
    [
        Button.Disabled true
        Button.OnClick (fun _ -> dispatch Msg)
    ]
    [ str "Text here" ]

使用自定义类来选择哪个按钮应该具有此行为

CSS 代码

.button.custom-disabled[disabled] {
    background-color: black !important;
}

F# 代码

Button.button
    [
        Button.CustomClass "custom-disabled"    
        Button.Disabled true
        Button.OnClick (fun _ -> dispatch Msg)
    ]
    [ str "Text here" ]
于 2019-07-27T06:45:56.060 回答
2

如果您只想为禁用的情况更改字体颜色,您可以为此生成一个新样式:

Button.button
    [
        Button.Disabled isDisabled
        Button.Props [
            if isDisabled then yield Style [ Color "#000000" ] ]
        Button.OnClick (fun _ -> dispatch Increment)
    ]
    [ str "Text here" ]

如果你想根据禁用状态有不同的颜色,你可以使用一个if-then-else表达式:

Button.button
    [
        Button.Disabled isDisabled
        Button.Props [
            Style [ (if isDisabled then Color "#000000" else Color "#ffffff") ] ]
        Button.OnClick (fun _ -> dispatch Increment)
    ]
    [ str "Text here" ]
于 2019-07-26T17:32:46.947 回答