Skip to content

Commit

Permalink
feat: update v-avatar to v3 (#13265)
Browse files Browse the repository at this point in the history
Co-authored-by: John Leider <john.j.leider@gmail.com>
  • Loading branch information
nekosaur and johnleider committed Mar 16, 2021
1 parent edc2db9 commit 18ef431
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 137 deletions.
2 changes: 1 addition & 1 deletion packages/docs/src/examples/v-avatar/misc-profile-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class="profile"
color="grey"
size="164"
tile
rounded="0"
>
<v-img src="https://cdn.vuetifyjs.com/images/profiles/marcus.jpg"></v-img>
</v-avatar>
Expand Down
17 changes: 8 additions & 9 deletions packages/docs/src/examples/v-avatar/prop-size.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<template>
<v-row justify="space-around">
<v-avatar
color="indigo"
size="36"
color="primary"
size="x-small"
>
<span class="white--text headline">36</span>
<span class="headline">32</span>
</v-avatar>

<v-avatar
color="teal"
size="48"
color="secondary"
>
<span class="white--text headline">48</span>
<span class="headline">48</span>
</v-avatar>

<v-avatar
color="orange"
size="62"
color="info"
size="x-large"
>
<span class="white--text headline">62</span>
<span class="headline">64</span>
</v-avatar>
</v-row>
</template>
4 changes: 2 additions & 2 deletions packages/docs/src/examples/v-avatar/prop-tile.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="text-center">
<v-avatar
tile
rounded="0"
color="blue"
>
<v-icon dark>
<v-icon>
mdi-alarm
</v-icon>
</v-avatar>
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/examples/v-avatar/slot-default.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-row justify="space-around">
<v-avatar color="indigo">
<v-icon dark>
<v-avatar color="info">
<v-icon>
mdi-account-circle
</v-icon>
</v-avatar>
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/pages/en/components/avatars.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ Avatars in their simplest form display content within a circular container.

#### Size

The `size` prop allows you to define the height and width of `v-avatar`. This prop scales both evenly with an aspect ratio of 1. `height` and `width` props will override this prop.
The `size` prop allows you to change the height and width of `v-avatar`.

<example file="v-avatar/prop-size" />

#### Tile

The `tile` prop removes the border radius from v-avatar leaving you with a simple square avatar.
The `rounded` prop can be used to remove the border radius from v-avatar leaving you with a simple square avatar.

<example file="v-avatar/prop-tile" />

### Slots

#### Default

The `v-avatar` default slot will accept the `v-icon` component, an image, or text. Mix and match these with other props to create something unique.
The `v-avatar` default slot allows you to render content such as `v-icon` components, images, or text. Mix and match these with other props to create something unique.

<example file="v-avatar/slot-default" />

Expand Down
19 changes: 9 additions & 10 deletions packages/vuetify/src/components/VAvatar/VAvatar.sass
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
border-radius: $avatar-border-radius
display: inline-flex
justify-content: center
line-height: normal
line-height: $avatar-line-height
overflow: hidden
position: relative
text-align: center
vertical-align: middle
overflow: hidden
vertical-align: $avatar-vertical-align

img,
svg,
.v-icon,
.v-image,
.v-responsive__content
> *
border-radius: inherit
display: inline-flex
height: inherit
width: inherit

@each $name in $sizes
&--size-#{$name}
height: map-get($avatar-sizes, $name)
width: map-get($avatar-sizes, $name)
63 changes: 0 additions & 63 deletions packages/vuetify/src/components/VAvatar/VAvatar.ts

This file was deleted.

51 changes: 51 additions & 0 deletions packages/vuetify/src/components/VAvatar/VAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Styles
import './VAvatar.sass'

// Composables
import { makeBorderRadiusProps, useBorderRadius } from '@/composables/border-radius'
import { makeSizeProps, useSize } from '@/composables/size'
import { makeTagProps } from '@/composables/tag'
import { useBackgroundColor } from '@/composables/color'

// Utilities
import { defineComponent, toRef } from 'vue'

export default defineComponent({
name: 'VAvatar',

props: {
...makeBorderRadiusProps(),
...makeSizeProps(),
...makeTagProps(),
color: String,
left: Boolean,
right: Boolean,
},

setup (props, { slots }) {
const { backgroundColorClasses, backgroundColorStyles } = useBackgroundColor(toRef(props, 'color'))
const { borderRadiusClasses } = useBorderRadius(props)
const { sizeClasses, sizeStyles } = useSize(props, 'v-avatar')

return () => (
<props.tag
class={[
'v-avatar',
{
'v-avatar--left': props.left,
'v-avatar--right': props.right,
},
backgroundColorClasses.value,
borderRadiusClasses.value,
sizeClasses.value,
]}
style={[
backgroundColorStyles.value,
sizeStyles.value,
]}
>
{ slots.default?.() }
</props.tag>
)
},
})
47 changes: 17 additions & 30 deletions packages/vuetify/src/components/VAvatar/__tests__/VAvatar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
// @ts-nocheck
/* eslint-disable */

// Libraries
// import Vue from 'vue'

// Components
// import VAvatar from '../VAvatar'
import { VAvatar } from '..'

// Utilities
import {
createLocalVue,
mount,
Wrapper,
} from '@vue/test-utils'

describe.skip('VAvatar', () => {
let mountFunction: (options?: object) => Wrapper<Vue>
let localVue: typeof Vue

beforeEach(() => {
localVue = createLocalVue()

mountFunction = (options = {}) => {
return mount(VAvatar, {
localVue,
...options,
})
}
})

it('should have an v-avatar class', () => {
import { createVuetify } from '@/framework'
import { mount } from '@vue/test-utils'

describe('VAvatar', () => {
const vuetify = createVuetify()

function mountFunction (options = {}) {
return mount(VAvatar, {
global: {
plugins: [vuetify],
},
...options,
})
}

it('should match a snapshot', () => {
const wrapper = mountFunction()

expect(wrapper.classes()).toContain('v-avatar')
expect(wrapper.html()).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`VAvatar should have an v-avatar class 1`] = `
<div class="v-avatar"
style="height: 48px; min-width: 48px; width: 48px;"
>
exports[`VAvatar should match a snapshot 1`] = `
<div class="v-avatar v-avatar--size-default">
</div>
`;
14 changes: 14 additions & 0 deletions packages/vuetify/src/components/VAvatar/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
@import '../../styles/styles.sass';

$avatar-border-radius: 50% !default;
$avatar-line-height: normal !default;
$avatar-vertical-align: middle !default;

$avatar-sizes: () !default;
$avatar-sizes: map-deep-merge(
(
'x-small': 32px,
'small': 40px,
'default': 48px,
'large': 56px,
'x-large': 64px,
),
$avatar-sizes
);
5 changes: 1 addition & 4 deletions packages/vuetify/src/components/VAvatar/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import VAvatar from './VAvatar'

export { VAvatar }
export default VAvatar
export { default as VAvatar } from './VAvatar'
12 changes: 6 additions & 6 deletions packages/vuetify/src/components/VIcon/VIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Styles
import './VIcon.sass'

// Utilities
import { computed, ComputedRef, defineComponent, toRef } from 'vue'
import { convertToUnit, flattenFragments } from '@/util'
import makeProps from '@/util/makeProps'

// Composables
import { makeSizeProps, useSize } from '@/composables/size'
import { useIcon } from '@/composables/icons'
import { makeTagProps } from '@/composables/tag'
import { useIcon } from '@/composables/icons'
import { useTextColor } from '@/composables/color'

// Utilities
import { computed, ComputedRef, defineComponent, toRef } from 'vue'
import { convertToUnit, flattenFragments } from '@/util'
import makeProps from '@/util/makeProps'

// Types
import type { IconValue } from '@/composables/icons'
import type { PropType } from 'vue'
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './VApp'
// export * from './VAppBar'
// export * from './VAlert'
// export * from './VAutocomplete'
// export * from './VAvatar'
export * from './VAvatar'
// export * from './VBadge'
export * from './VBanner'
// export * from './VBottomNavigation'
Expand Down
16 changes: 16 additions & 0 deletions packages/vuetify/src/composables/__tests__/size.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@ describe('size', () => {
[{ size: 'x-large' }, 'test--size-x-large'],
[{ size: '100px' }, null],
[{ size: 100 }, null],
[{ size: undefined }, null],
] as const)('should return the correct class given value %p', (input, expected) => {
const { sizeClasses } = useSize(input, 'test')

expect(sizeClasses.value).toStrictEqual(expected)
})

it.each([
[{ size: 'x-small' }, null],
[{ size: 'small' }, null],
[{ size: 'default' }, null],
[{ size: 'large' }, null],
[{ size: 'x-large' }, null],
[{ size: '100px' }, { width: '100px', height: '100px' }],
[{ size: 50 }, { width: '50px', height: '50px' }],
[{ size: undefined }, null],
] as const)('should return the correct styles given value %p', (input, expected) => {
const { sizeStyles } = useSize(input, 'test')

expect(sizeStyles.value).toStrictEqual(expected)
})
})

0 comments on commit 18ef431

Please sign in to comment.