-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="fx-1 fx-col fx-xalign-center fx-gap-px-18"> | ||
{{#if (has-block "image")}} | ||
{{yield to="image"}} | ||
{{else if @badgeIcon}} | ||
<OSS::Badge @icon={{@badgeIcon}} @size="lg" /> | ||
{{/if}} | ||
<span 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.size}}"> | ||
{{@subtitle}} | ||
</div> | ||
</span> | ||
{{#if (has-block "actions")}} | ||
{{yield to="actions"}} | ||
{{/if}} | ||
</div> |
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: { | ||
badgeIcon: { | ||
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small typo here, should be |
||
} | ||
} | ||
} | ||
}; | ||
|
||
const defaultArgs = { | ||
badgeIcon: 'fa-thumbs-up', | ||
title: 'Empty State Title', | ||
subtitle: 'Additional information here', | ||
size: 'md' | ||
}; | ||
|
||
const Template = (args) => ({ | ||
template: hbs`<OSS::EmptyState @badgeIcon={{this.badgeIcon}} @title={{this.title}} @subtitle={{this.subtitle}} @size={{this.size}} />`, | ||
context: args | ||
}); | ||
Miexil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const Default = Template.bind({}); | ||
Default.args = defaultArgs; |
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 { | ||
badgeIcon?: string; | ||
title: ReturnType<typeof htmlSafe>; | ||
subtitle: ReturnType<typeof htmlSafe>; | ||
Miexil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size?: 'sm' | 'md'; | ||
} | ||
|
||
export default class OSSEmptyStateComponent extends Component<OSSEmptyStateComponentSignature> { | ||
get titleSize(): string { | ||
return this.size === 'sm' ? 'md' : 'lg'; | ||
} | ||
|
||
get size(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about this because it's also used for invalid values handling |
||
return this.args.size && ['sm', 'md'].includes(this.args.size) ? this.args.size : 'md'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can set |
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could add a
(so we properly handle invalid sizes) |
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'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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'); | ||
}); | ||
|
||
test('it renders with a badge icon', async function (assert) { | ||
this.set('image', 'fa-thumbs-up'); | ||
await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @badgeIcon={{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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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('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('button').hasText('Retry'); | ||
}); | ||
|
||
test('it applies size-based styles', async function (assert) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing test for MD size ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing not allowed size like |
||
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'); | ||
}); | ||
}); |
There was a problem hiding this comment.
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