From a2bc406bde282caaabdc4c0cf06e8bec36a427a6 Mon Sep 17 00:00:00 2001 From: Rijk van Zanten Date: Thu, 23 Apr 2020 18:39:03 -0400 Subject: [PATCH] Add block style to radio button (#463) --- src/components/v-radio/v-radio.story.ts | 24 +++++++++++- src/components/v-radio/v-radio.vue | 51 ++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/components/v-radio/v-radio.story.ts b/src/components/v-radio/v-radio.story.ts index 2cb4dc9df6..08b2e30869 100644 --- a/src/components/v-radio/v-radio.story.ts +++ b/src/components/v-radio/v-radio.story.ts @@ -25,7 +25,7 @@ export const basic = () => return { value }; }, template: ` -
+
@@ -33,3 +33,25 @@ export const basic = () =>
`, }); + +export const blockStyle = () => + defineComponent({ + components: { RawValue }, + props: { + disabled: { + default: boolean('Disabled', false), + }, + }, + setup() { + const value = ref(null); + return { value }; + }, + template: ` +
+ + + + {{ value }} +
+ `, + }); diff --git a/src/components/v-radio/v-radio.vue b/src/components/v-radio/v-radio.vue index 7709646c96..ba8f7332c6 100644 --- a/src/components/v-radio/v-radio.vue +++ b/src/components/v-radio/v-radio.vue @@ -4,7 +4,7 @@ type="button" :aria-pressed="isChecked ? 'true' : 'false'" :disabled="disabled" - :class="{ checked: isChecked }" + :class="{ checked: isChecked, block }" @click="emitValue" > @@ -39,6 +39,18 @@ export default defineComponent({ type: Boolean, default: false, }, + iconOn: { + type: String, + default: 'radio_button_checked', + }, + iconOff: { + type: String, + default: 'radio_button_unchecked', + }, + block: { + type: Boolean, + default: false, + }, }, setup(props, { emit }) { const isChecked = computed(() => { @@ -46,7 +58,7 @@ export default defineComponent({ }); const icon = computed(() => { - return isChecked.value ? 'radio_button_checked' : 'radio_button_unchecked'; + return isChecked.value ? props.iconOn : props.iconOff; }); return { isChecked, emitValue, icon }; @@ -95,6 +107,28 @@ export default defineComponent({ } } + &.block { + position: relative; + width: 100%; + height: var(--input-height); + padding: 10px; // 14 - 4 (border) + background-color: var(--page-background); + border: 2px solid var(--background-subdued); + border-radius: var(--border-radius); + + &::before { + position: absolute; + top: 0; + left: 0; + z-index: -1; + width: 100%; + height: 100%; + background-color: var(--background-subdued); + border-radius: var(--border-radius); + content: ''; + } + } + &:not(:disabled):hover { .v-icon { --v-icon-color: var(--foreground-subdued); @@ -105,6 +139,19 @@ export default defineComponent({ .v-icon { --v-icon-color: var(--v-radio-color); } + + &.block { + border-color: var(--v-radio-color); + + .label { + color: var(--v-radio-color); + } + + &::before { + background-color: var(--v-radio-color); + opacity: 0.1; + } + } } }