Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty state component #476

Merged
merged 8 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions addon/components/o-s-s/empty-state.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="fx-1 fx-col fx-xalign-center fx-gap-px-18">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should include splattributes here just to be safe

Aside from the classes, it will allow us to define a data-control-name in the parent if needed

{{#if (has-block "image")}}
<span class="">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the span here? as it's a named block, let's just let the caller handle the content here. same below for the actions

{{yield to="image"}}
</span>
{{else if @image}}
<OSS::Badge @icon={{@image}} @size="lg" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badgeIcon instead of @image would be better imo

{{/if}}
<div class="fx-col fx-xalign-center fx-gap-px-6">
<div class="font-color-gray-900 font-size-{{this.titleSize}} font-weight-semibold">
{{@title}}
</div>
<div class="font-color-gray-500 font-size-{{this.subtitleSize}}">
{{@subtitle}}
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title & subtitle are marked as optional in the TS but there is no check on their presence here, leading to empty divs.

I think we can remove the optional side in the TS and make both mandatory for now (i don't remember seeing an empty state w/ only a subtitle, or only a title)

Also, i think the div can be span instead.

</div>
{{#if (has-block "actions")}}
<span class="">
{{yield to="actions"}}
</span>
{{/if}}
</div>
71 changes: 71 additions & 0 deletions addon/components/o-s-s/empty-state.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { hbs } from 'ember-cli-htmlbars';

export default {
title: 'Components/OSS::EmptyState',
component: 'empty state',
argTypes: {
image: {
description: 'a font-awesome icon to be displayed in a badge',
table: {
type: {
summary: 'string'
},
defaultValue: { summary: 'undefined' }
},
control: { type: 'text' }
},
title: {
description: 'The title of the state',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would remove "state" alone because it can have loads of definitions which are not in this context.

How about
title: "A title displayed below the icon or badge in the component" ?
subtitle: "A subtitle displayed under the title in the component"

table: {
type: {
summary: 'string'
},
defaultValue: { summary: 'undefined' }
},
control: { type: 'text' }
},
subtitle: {
description: 'More information about the state',
table: {
type: {
summary: 'string'
},
defaultValue: { summary: 'undefined' }
},
control: { type: 'text' }
},
size: {
description: 'The size of the state',
table: {
type: {
summary: 'string'
},
defaultValue: { summary: 'undefined' }
},
control: { type: 'select' },
options: ['sm', 'md']
}
},
parameters: {
docs: {
description: {
component: 'An component used when there is nothing to display on a page'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo here, should be A component instead of an :)

}
}
}
};

const defaultArgs = {
image: 'fa-thumbs-up',
title: 'Empty State Title',
subtitle: 'Additional information here',
size: 'md'
};

const Template = (args) => ({
template: hbs`<OSS::EmptyState @image={{this.image}} @title={{this.title}} @subtitle={{this.subtitle}} @size={{this.size}} />`,
context: args
});

export const Default = Template.bind({});
Default.args = defaultArgs;
19 changes: 19 additions & 0 deletions addon/components/o-s-s/empty-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { htmlSafe } from '@ember/template';
import Component from '@glimmer/component';

interface OSSEmptyStateComponentSignature {
image?: string;
title?: ReturnType<typeof htmlSafe>;
subtitle?: ReturnType<typeof htmlSafe>;
size?: 'sm' | 'md';
}

export default class OSSEmptyStateComponent extends Component<OSSEmptyStateComponentSignature> {
get titleSize(): string {
return this.args.size === 'sm' ? 'md' : 'lg';
}

get subtitleSize(): string {
return this.args.size || 'md';
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could add a size getter that returns this.args.size ?? 'md' and use it locally. or even:

get size(): string {
  return ['sm', 'md'].includes(this.args.size) ? this.args.size : 'md';
}

(so we properly handle invalid sizes)

1 change: 1 addition & 0 deletions app/components/o-s-s/empty-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@upfluence/oss-components/components/o-s-s/empty-state';
40 changes: 40 additions & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,44 @@
</div>
</div>

<div
class="fx-col fx-1 background-color-white border border-color-default border-radius-md padding-px-12 fx-gap-px-12"
>
<div class="font-size-md font-weight-semibold">
Empty state
</div>
<div class="fx-row fx-gap-px-36 fx-xalign-start">
<OSS::EmptyState @title="Title" @subtitle="Subtitle">
<:image>
<OSS::Illustration @src="/@upfluence/oss-components/assets/images/no-records.svg" />
</:image>
<:actions>
<OSS::Button @label="Button" />
<OSS::Button @skin="primary" @label="Button" />
</:actions>
</OSS::EmptyState>
<OSS::EmptyState @title="Title" @subtitle="Subtitle" @image="fa-thumbs-up">
<:actions>
<OSS::Button @label="Button" />
<OSS::Button @skin="primary" @label="Button" />
</:actions>
</OSS::EmptyState>
<OSS::EmptyState @title="Title" @subtitle="Subtitle" @size="sm">
<:image>
<OSS::Illustration @src="/@upfluence/oss-components/assets/images/no-records.svg" />
</:image>
<:actions>
<OSS::Button @label="Button" />
<OSS::Button @skin="primary" @label="Button" />
</:actions>
</OSS::EmptyState>
<OSS::EmptyState @title="Title" @subtitle="Subtitle" @size="sm" @image="fa-thumbs-up">
<:actions>
<OSS::Button @label="Button" />
<OSS::Button @skin="primary" @label="Button" />
</:actions>
</OSS::EmptyState>
</div>
</div>

</div>
59 changes: 59 additions & 0 deletions tests/integration/components/o-s-s/empty-state-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | o-s-s/empty-state', function (hooks) {
setupRenderingTest(hooks);

test('it renders with default properties', async function (assert) {
await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" />`);

assert.dom('div.font-color-gray-900').hasText('No Data');
assert.dom('div.font-color-gray-500').hasText('Try again later');
assert.dom('span').doesNotExist();
});

test('it renders with an image', async function (assert) {
this.set('image', 'fa-thumbs-up');
await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @image={{this.image}} />`);

assert.dom('div.font-color-gray-900').hasText('No Data');
assert.dom('div.font-color-gray-500').hasText('Try again later');
assert.dom('.upf-badge').exists();
});

test('it supports block usage for image', async function (assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: named-block instead of just block, same at line 39

await render(hbs`
<OSS::EmptyState @title="No Data" @subtitle="Try again later">
<:image>
<img src="/test-image.png" alt="Test Image" />
</:image>
</OSS::EmptyState>
`);

assert.dom('div.font-color-gray-900').hasText('No Data');
assert.dom('div.font-color-gray-500').hasText('Try again later');
assert.dom('span img').exists();
});

test('it supports block usage for actions', async function (assert) {
await render(hbs`
<OSS::EmptyState @title="No Data" @subtitle="Try again later">
<:actions>
<button type="button">Retry</button>
</:actions>
</OSS::EmptyState>
`);

assert.dom('div.font-color-gray-900').hasText('No Data');
assert.dom('div.font-color-gray-500').hasText('Try again later');
assert.dom('span button').hasText('Retry');
});

test('it applies size-based styles', async function (assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test for MD size ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing not allowed size like random

await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @size="sm" />`);
assert.dom('div.font-color-gray-900').hasClass('font-size-md');
assert.dom('div.font-color-gray-500').hasClass('font-size-sm');
});
});
Loading