Skip to content

Commit

Permalink
feat(VBtn): add new readonly prop
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Apr 18, 2024
1 parent 4820347 commit 72f33dc
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/api-generator/src/locale/en/VBtn.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"flat": "Removes the button box shadow. This is different than using the 'flat' variant.",
"icon": "Apply a specific icon using the [v-icon](/components/icons/) component. The button will become _round_.",
"plain": "Removes the default background change applied when hovering over the button.",
"readonly": "Puts the button in a readonly state. Cannot be clicked or navigated to by keyboard.",
"stacked": "Displays the button as a flex-column.",
"slim": "Reduces padding to 0 8px."
},
Expand Down
74 changes: 74 additions & 0 deletions packages/docs/src/examples/v-btn/misc-readonly.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
<v-list-item
base-color="surface-light"
border="opacity-50 md"
lines="two"
max-width="796"
prepend-avatar="https://cdn.vuetifyjs.com/docs/images/one/logos/one.png"
rounded="lg"
variant="flat"
>
<v-list-item-title>
<span class="text-h6">Vuetify One Subscriber</span>
</v-list-item-title>

<v-list-item-subtitle :opacity="isSubscriber ? .8 : undefined">
<v-scroll-y-reverse-transition mode="out-in">
<div
v-if="isSubscriber"
key="subscribed"
class="text-success text-caption"
>
<v-icon icon="mdi-medal" size="1em"></v-icon>
$2.99 /month
</div>

<div
v-else
key="not-subscribed"
class="text-caption"
>
Support Vuetify by becoming a Subscriber
</div>
</v-scroll-y-reverse-transition>
</v-list-item-subtitle>

<template v-slot:append>
<v-fade-transition mode="out-in">
<v-btn
:key="`subscribe-${isSubscriber}`"
:border="`thin ${isSubscriber ? 'error' : 'success'}`"
:color="isSubscriber ? 'error' : 'success'"
:prepend-icon="isSubscriber ? 'mdi-close' : 'mdi-email'"
:slim="isSubscriber"
:text="isSubscriber ? 'Cancel' : 'Subscribe'"
:variant="isSubscriber ? 'plain' : 'tonal'"
class="me-2 text-none"
size="small"
flat
@click="isSubscriber = !isSubscriber"
></v-btn>
</v-fade-transition>

<v-fade-transition mode="out-in">
<v-btn
:key="`info-${isSubscriber}`"
:color="isSubscriber ? 'success' : 'primary'"
:prepend-icon="isSubscriber ? 'mdi-check' : 'mdi-open-in-new'"
:readonly="isSubscriber"
:text="isSubscriber ? 'Subscribed' : 'More Info'"
class="text-none"
size="small"
variant="flat"
flat
></v-btn>
</v-fade-transition>
</template>
</v-list-item>
</template>

<script setup>
import { shallowRef } from 'vue'
const isSubscriber = shallowRef(false)
</script>
6 changes: 6 additions & 0 deletions packages/docs/src/pages/en/components/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ In this example we use a [v-banner](/components/banners/) component to display a

<ExamplesExample file="v-btn/misc-cookie-settings" />

### Readonly buttons

In this example, we change the properties of the `v-btn` based upon a "subscription" state. When the user is subscribed, we want to disable interaction with the button, but not change its appearance; which is what occurs when using the **disabled** property.

<ExamplesExample file="v-btn/misc-readonly" />

## Global Configuration

Modify the default values and set a default style for all `v-btn` components using the [Global configuration](/features/global-configuration/). This helps keep your application consistent and allows you to change it in the future with minimal effort.
Expand Down
1 change: 1 addition & 0 deletions packages/docs/src/plugins/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export {
mdiMapMarkerOff,
mdiMapMarkerOutline,
mdiMaterialDesign,
mdiMedal,
mdiMenu,
mdiMenuDown,
mdiMenuLeft,
Expand Down
3 changes: 3 additions & 0 deletions packages/vuetify/src/components/VBtn/VBtn.sass
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
&--slim
padding: $button-slim-padding

&--readonly
pointer-events: none

&--rounded
@include tools.rounded($button-rounded-border-radius)

Expand Down
4 changes: 3 additions & 1 deletion packages/vuetify/src/components/VBtn/VBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const makeVBtnProps = propsFactory({
appendIcon: IconValue,

block: Boolean,
readonly: Boolean,
slim: Boolean,
stacked: Boolean,

Expand Down Expand Up @@ -184,6 +185,7 @@ export const VBtn = genericComponent<VBtnSlots>()({
'v-btn--flat': props.flat,
'v-btn--icon': !!props.icon,
'v-btn--loading': props.loading,
'v-btn--readonly': props.readonly,
'v-btn--slim': props.slim,
'v-btn--stacked': props.stacked,
},
Expand All @@ -209,7 +211,7 @@ export const VBtn = genericComponent<VBtnSlots>()({
aria-busy={ props.loading ? true : undefined }
disabled={ isDisabled.value || undefined }
href={ link.href.value }
tabindex={ props.loading ? -1 : undefined }
tabindex={ props.loading || props.readonly ? -1 : undefined }
onClick={ onClick }
value={ valueAttr.value }
>
Expand Down

0 comments on commit 72f33dc

Please sign in to comment.