F
Filament2w ago
Xavi

Custom field button color

I create a custom form field to record voice. How to change <x-filament::button> color when i click on it. This is my button code:
<div>
<x-filament::button
type="button"
x-on:click="isRecording ? stopRecording() : startRecording()"
x-text="isRecording ? 'Detener grabación' : 'Iniciar grabación'"
></x-filament::button>
</div>
<div>
<x-filament::button
type="button"
x-on:click="isRecording ? stopRecording() : startRecording()"
x-text="isRecording ? 'Detener grabación' : 'Iniciar grabación'"
></x-filament::button>
</div>
Thanks!
9 Replies
Lara Zeus
Lara Zeus2w ago
something like this: :color="isRecording ? 'primary' : 'secondary'"
Xavi
Xavi2w ago
Thanks @Lara Zeus, but it doesn't works. It throws Undefined constant "isRecording" error when i add color condition (isRecording works fine on "x-on:click and x-text")
Lara Zeus
Lara Zeus2w ago
what is isRecording? is it a php thing or js? 🙂 you can add custom classes using alpine js: :class="open ? '' : 'hidden'"
Xavi
Xavi2w ago
isRecording its a js variable. I share all custom field here
LeandroFerreira
maybe
x-data="{
...
buttonStyle(color) {
return `--c-400:var(--${color}-400);--c-500:var(--${color}-500);--c-600:var(--${color}-600)`;
}
x-data="{
...
buttonStyle(color) {
return `--c-400:var(--${color}-400);--c-500:var(--${color}-500);--c-600:var(--${color}-600)`;
}
<x-filament::button
type="button"
x-bind:style="buttonStyle(isRecording ? 'danger' : 'success')"
...
<x-filament::button
type="button"
x-bind:style="buttonStyle(isRecording ? 'danger' : 'success')"
...
Xavi
Xavi2w ago
@Leandro Ferreira it works!!! I don't understand the code but it works 😅
LeandroFerreira
These CSS variables define the button colors. I set them based on the isRecording value.. Maybe this can be better, but I think this works 🙂
Xavi
Xavi2w ago
Yes, it works… thanks!! 😉
Want results from more Discord servers?
Add your server