Skip to content

Commit e8cda9b

Browse files
authored
feat(entityemptystate): added appreance prop support [KHCP-14905] (#1919)
* feat(entityemptystate): added appreance prop support [KHCP-14905] * fix(entityemptystate): props docs, improvements [KHCP-14905] * fix: type imports * fix(entityemptystate): fixed all spacing issues [KHCP-14905] * fix: fixed computed naming * fix: type imports
1 parent 869c49f commit e8cda9b

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

packages/entities/entities-shared/docs/entity-empty-state.md

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Title for the empty state.
3838

3939
Description for the empty state.
4040

41+
#### `appearance`
42+
43+
- type: `String`
44+
- default: `'primary'`
45+
46+
Appearance of the empty state, component takes one of the following appearance values: `primary`, `secondary`
47+
4148
#### `pricing`
4249

4350
- type: `String`

packages/entities/entities-shared/sandbox/pages/EntityEmptyStatePage.vue

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
description="Lorem ipsum dolor sit amet consectetur adipisicing elit. Id quidem aperiam similique vitae beatae. Repellat quam voluptas vitae, maxime consequuntur praesentium suscipit. Numquam aliquid nulla vel esse accusantium reiciendis error?"
88
:features="features"
99
learn-more
10-
pricing="Lorem ipsum dolor sit amet consectetur adipisicing elit"
1110
title="Gateway Manager"
1211
@click:create="console.log('create button clicked')"
1312
@click:learn-more="console.log('learning hub button clicked')"

packages/entities/entities-shared/src/components/entity-empty-state/EntityEmptyState.vue

+35-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
v-if="title || $slots.title"
1313
class="entity-empty-state-title"
1414
>
15-
<h1>
15+
<h1 :class="emptyStateAppearance">
1616
<slot name="title">
1717
{{ title }}
1818
</slot>
@@ -78,7 +78,10 @@
7878
</slot>
7979
</div>
8080

81-
<div class="entity-empty-state-card-container">
81+
<div
82+
v-if="features.length"
83+
class="entity-empty-state-card-container"
84+
>
8285
<template
8386
v-for="(feature, idx) in features"
8487
:key="feature"
@@ -118,9 +121,17 @@ import { type PropType, computed, ref, onBeforeMount } from 'vue'
118121
import { KButton } from '@kong/kongponents'
119122
import { BookIcon, AddIcon } from '@kong/icons'
120123
import composables from '../../composables'
121-
import type { EmptyStateFeature } from 'src/types/entity-empty-state'
124+
import type { EmptyStateFeature, AppearanceTypes } from '../../types/entity-empty-state'
125+
import { Appearances } from '../../types/entity-empty-state'
122126
123127
const props = defineProps({
128+
appearance: {
129+
type: String as PropType<AppearanceTypes>,
130+
default: () => 'primary',
131+
validator: (value: AppearanceTypes): boolean => {
132+
return Appearances.includes(value)
133+
},
134+
},
124135
title: {
125136
type: String,
126137
default: '',
@@ -163,6 +174,16 @@ const { i18n: { t } } = composables.useI18n()
163174
const useCanCreate = ref(false)
164175
const showCreateButton = computed((): boolean => useCanCreate.value && !!props.actionButtonText)
165176
177+
const emptyStateAppearance = computed((): AppearanceTypes | [AppearanceTypes, string] => {
178+
// If the appearance is invalid, output both to keep backwards compatibility
179+
// in case some of the tests rely on the invalid appearance output
180+
if (!Appearances.includes(props.appearance)) {
181+
return ['primary', props.appearance]
182+
}
183+
184+
return props.appearance
185+
})
186+
166187
onBeforeMount(async () => {
167188
// Evaluate if the user has create permissions
168189
useCanCreate.value = await props.canCreate()
@@ -180,7 +201,7 @@ $entity-empty-state-max-width: calc(2 * #{$entity-empty-state-feature-card-width
180201
display: flex;
181202
flex-direction: column;
182203
font-family: $kui-font-family-text;
183-
gap: $kui-space-110;
204+
gap: $kui-space-80;
184205
padding: $kui-space-130 $kui-space-0;
185206
width: 100%;
186207
@@ -209,6 +230,10 @@ $entity-empty-state-max-width: calc(2 * #{$entity-empty-state-feature-card-width
209230
gap: $kui-space-40;
210231
line-height: $kui-line-height-60;
211232
margin: $kui-space-0;
233+
234+
&.secondary {
235+
font-size: $kui-font-size-50;
236+
}
212237
}
213238
}
214239
@@ -220,10 +245,14 @@ $entity-empty-state-max-width: calc(2 * #{$entity-empty-state-feature-card-width
220245
max-width: 640px; // limit width so the description stays readable if it is too long
221246
222247
p {
223-
margin: $kui-space-30;
248+
margin: $kui-space-0;
224249
}
225250
}
226251
252+
.entity-empty-state-pricing {
253+
margin-top: $kui-space-60;
254+
}
255+
227256
.entity-empty-state-action {
228257
align-items: center;
229258
display: flex;
@@ -235,6 +264,7 @@ $entity-empty-state-max-width: calc(2 * #{$entity-empty-state-feature-card-width
235264
flex-wrap: wrap;
236265
gap: $kui-space-60;
237266
justify-content: space-around;
267+
margin-top: $kui-space-40;
238268
/** single column on mobile */
239269
width: $entity-empty-state-feature-card-width;
240270

packages/entities/entities-shared/src/types/entity-empty-state.ts

+7
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ export interface EmptyStateFeature {
22
title: string,
33
description: string
44
}
5+
6+
export type AppearanceTypes = 'primary' | 'secondary'
7+
8+
export const Appearances = [
9+
'primary',
10+
'secondary',
11+
]

0 commit comments

Comments
 (0)