Skip to content

Commit

Permalink
[5.x] Radio Fieldtype gets custom button icons (#10453)
Browse files Browse the repository at this point in the history
Radio Fieldtype gets custom button icons

This gives us better control over contrast, dark/light, and disabled states — something native HTML cannot do, sadly. Closes #10427.
  • Loading branch information
jackmcdade authored Jul 15, 2024
1 parent 9b3ff54 commit 558cd4f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions resources/css/components/fieldtypes/radio.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.radio-fieldtype label {
@apply flex;
}

.radio-fieldtype input[type="radio"] {
@apply m-0 min-w-0 absolute opacity-0 -z-1 w-1 h-px w-px overflow-hidden;
}

.radio-fieldtype .radio-icon {
@apply cursor-pointer h-4 w-4 ltr:mr-2 rtl:ml-2 block;
}

.radio-fieldtype .option.disabled {
.radio-icon {
@apply cursor-not-allowed opacity-25;
}
label {
@apply cursor-text;
}
}

1 change: 1 addition & 0 deletions resources/css/cp.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
@import "components/fieldtypes/hidden";
@import "components/fieldtypes/markdown";
@import "components/fieldtypes/partial";
@import "components/fieldtypes/radio";
@import "components/fieldtypes/relationship";
@import "components/fieldtypes/replicator";
@import "components/fieldtypes/section";
Expand Down
20 changes: 20 additions & 0 deletions resources/js/components/fieldtypes/RadioFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@
v-for="(option, $index) in options"
:key="$index"
class="option"
:class="{
'selected': value === option.value,
'disabled': isReadOnly
}"
>
<label>
<svg-icon
name="regular/radio-deselected"
class="radio-icon"
:aria-hidden="value === option.value"
@click="update($event.target.value)"
v-show="value !== option.value"
v-cloak
/>
<svg-icon
name="regular/radio-selected"
class="radio-icon"
:aria-hidden="value !== option.value"
@click="update($event.target.value)"
v-show="value === option.value"
v-cloak
/>
<input type="radio"
ref="radio"
:name="name"
Expand Down
1 change: 1 addition & 0 deletions resources/svg/icons/regular/radio-deselected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/svg/icons/regular/radio-selected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 558cd4f

Please sign in to comment.