-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(VEmptyState): add new component
closes #4610
- Loading branch information
1 parent
c0f061b
commit 1c6a836
Showing
8 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<ExamplesUsageExample | ||
v-model="model" | ||
:code="code" | ||
:name="name" | ||
:options="options" | ||
> | ||
<v-empty-state | ||
v-bind="props" | ||
></v-empty-state> | ||
</ExamplesUsageExample> | ||
</template> | ||
|
||
<script setup> | ||
const name = 'v-empty-state' | ||
const model = ref('default') | ||
const options = [] | ||
const props = computed(() => { | ||
return { | ||
title: 'Whoops, 404', | ||
subtitle: 'Page not found', | ||
text: 'The page you were looking for does not exist', | ||
avatar: 'https://vuetifyjs.b-cdn.net/docs/images/logos/v.png' | ||
} | ||
}) | ||
const slots = computed(() => { | ||
return '' | ||
}) | ||
const code = computed(() => { | ||
return `<${name}${propsToString(props.value)}>${slots.value}</${name}>` | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
emphasized: true | ||
meta: | ||
title: Empty states | ||
description: The empty state component is used to indicate that a list is empty or that no search results were found. | ||
keywords: empty state, no results, no data, no items, no content, no records, no information, no search results | ||
related: | ||
- /components/buttons/ | ||
- /components/icons/ | ||
- /components/avatars/ | ||
features: | ||
report: true | ||
spec: https://m2.material.io/design/communication/empty-states.html | ||
--- | ||
|
||
# Empty states | ||
|
||
The `v-empty-state` component is used to indicate that a list is empty or that no search results were found. | ||
|
||
<PageFeatures /> | ||
|
||
## Usage | ||
|
||
A basic empty state is composed of a title and a description. It can also include an icon and a button. | ||
|
||
<ExamplesUsage name="v-empty-state" /> | ||
|
||
<PromotedEntry /> | ||
|
||
## API | ||
|
||
| Component | Description | | ||
| - | - | | ||
| [v-empty-state](/api/v-empty-state/) | Primary Component | | ||
|
||
<ApiInline hide-links /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@use './variables' as * | ||
|
||
.v-empty-state | ||
min-height: 100% | ||
display: flex | ||
align-items: center | ||
justify-content: center | ||
flex-direction: column | ||
|
||
.v-empty-state__title | ||
font-size: $empty-state-title-font-size | ||
|
||
.v-empty-state__subtitle | ||
font-size: $empty-state-subtitle-font-size | ||
|
||
.v-empty-state__text | ||
font-size: $empty-state-text-font-size | ||
|
||
.v-empty-state__content | ||
padding: $empty-state-content-padding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Styles | ||
import './VEmptyState.sass' | ||
|
||
// Components | ||
import { VAvatar } from '@/components/VAvatar' | ||
import { VDefaultsProvider } from '@/components/VDefaultsProvider' | ||
import { VIcon } from '@/components/VIcon' | ||
|
||
// Composables | ||
import { makeSizeProps } from '@/composables/size' | ||
import { makeComponentProps } from '@/composables/component' | ||
import { makeThemeProps, provideTheme } from '@/composables/theme' | ||
import { IconValue } from '@/composables/icons' | ||
|
||
// Utility | ||
import { genericComponent, propsFactory, useRender } from '@/util' | ||
import { useBackgroundColor } from '@/composables/color' | ||
import { toRef } from 'vue' | ||
|
||
// Types | ||
|
||
export type VEmptyStateSlots = { | ||
default: void | ||
media: void | ||
} | ||
|
||
export const makeVEmptyStateProps = propsFactory({ | ||
avatar: String, | ||
color: String, | ||
icon: IconValue, | ||
title: String, | ||
subtitle: String, | ||
text: String, | ||
|
||
...makeComponentProps(), | ||
...makeSizeProps({ size: '25%' }), | ||
...makeThemeProps(), | ||
}, 'VEmptyState') | ||
|
||
export const VEmptyState = genericComponent<VEmptyStateSlots>()({ | ||
name: 'VEmptyState', | ||
|
||
props: makeVEmptyStateProps(), | ||
|
||
setup (props, { slots }) { | ||
const { themeClasses } = provideTheme(props) | ||
const { backgroundColorClasses, backgroundColorStyles } = useBackgroundColor(toRef(props, 'color')) | ||
|
||
useRender(() => ( | ||
<div | ||
class={[ | ||
'v-empty-state', | ||
themeClasses.value, | ||
backgroundColorClasses.value, | ||
props.class, | ||
]} | ||
style={[ | ||
backgroundColorStyles.value, | ||
props.style, | ||
]} | ||
> | ||
{ !slots.media ? ( | ||
<> | ||
{ props.avatar ? ( | ||
<VAvatar | ||
key="avatar" | ||
image={ props.avatar } | ||
size={ props.size } | ||
tile | ||
/> | ||
) : props.icon ? ( | ||
<VIcon | ||
key="icon" | ||
size={ props.size } | ||
icon={ props.icon } | ||
/> | ||
) : undefined } | ||
</> | ||
) : ( | ||
<VDefaultsProvider | ||
key="media-defaults" | ||
defaults={{ | ||
VAvatar: { | ||
image: props.avatar, | ||
icon: props.icon, | ||
}, | ||
}} | ||
> | ||
{ slots.media() } | ||
</VDefaultsProvider> | ||
)} | ||
|
||
|
||
{ props.title && ( | ||
<div key="title" class="v-empty-state__title"> | ||
{ props.title } | ||
</div> | ||
)} | ||
|
||
{ props.subtitle && ( | ||
<div key="subtitle" class="v-empty-state__subtitle"> | ||
{ props.subtitle } | ||
</div> | ||
)} | ||
|
||
{ props.text && ( | ||
<div key="text" class="v-empty-state__text"> | ||
{ props.text } | ||
</div> | ||
)} | ||
|
||
{ slots.default && ( | ||
<div key="content" class="v-empty-state__content"> | ||
{ slots.default() } | ||
</div> | ||
)} | ||
</div> | ||
)) | ||
|
||
return {} | ||
}, | ||
}) | ||
|
||
export type VEmptyState = InstanceType<typeof VEmptyState> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
$empty-state-title-font-size: 4rem !default; | ||
$empty-state-subtitle-font-size: 2rem !default; | ||
$empty-state-text-font-size: .875rem !default; | ||
$empty-state-content-padding: 24px 0 !default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { VEmptyState } from './VEmptyState' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters