feat: 🎸 add dropdown section component with optional title

This commit is contained in:
Randall Morey committed 2020-11-04 16:24:02 -05:00
1 parent 6ca9e5c6f2
commit 8df002a73b
9 files changed
+83 -1

No files matched your search

@@ -28,6 +28,7 @@
button=(component "rose/dropdown/button" style=this.style)
item=(component "rose/anonymous" class="rose-dropdown-item")
separator=(component "rose/anonymous" tagName="hr" class="rose-dropdown-separator")
section=(component "rose/dropdown/section" style=this.style)
)}}
</div>
@@ -9,13 +9,17 @@ import { boolean } from '@storybook/addon-knobs';
A simple dropdown component with support for links and buttons.
<Preview>
<Story name="Basic Dropdown" height="5rem">{{
<Story name="Basic Dropdown" height="7rem">{{
template: hbs`
<Rose::Dropdown @text="Choose One&hellip;" @icon="user-organization" @showCaret={{showCaret}} as |dropdown|>
<dropdown.link @route="index">Menu item</dropdown.link>
<dropdown.link @route="about">Menu item</dropdown.link>
<dropdown.separator />
<dropdown.button>Button menu item</dropdown.button>
<dropdown.separator />
<dropdown.section @title="Dropdown Section Title">
<dropdown.link @route="index">Menu item</dropdown.link>
</dropdown.section>
</Rose::Dropdown>
`,
context: {
@@ -65,6 +69,10 @@ A simple dropdown component with support for links and buttons.
<dropdown.link @route="index">Menu item</dropdown.link>
<dropdown.link @route="about">Menu item</dropdown.link>
<dropdown.button>Button menu item</dropdown.button>
<dropdown.separator />
<dropdown.section @title="Dropdown Section Title">
<dropdown.link @route="index">Menu item</dropdown.link>
</dropdown.section>
</Rose::Dropdown>
```
@@ -0,0 +1,12 @@
<section class="rose-dropdown-section" aria-labelledby={{concat "dropdown-section-title-" this.id}}>
{{#if @title}}
<h2
id={{concat "dropdown-section-title-" this.id}}
class="rose-dropdown-section-title"
>
{{@title}}
</h2>
{{/if}}
{{yield}}
</section>
@@ -0,0 +1,14 @@
import Component from '@glimmer/component';
import { generateComponentID } from '../../../../utilities/component-auto-id';
import { action } from '@ember/object';
export default class RoseDialogComponent extends Component {
// =attributes
/**
* @type {string}
*/
id = generateComponentID();
}
@@ -2,3 +2,4 @@
@import 'button';
@import 'link';
@import 'item';
@import 'section';
@@ -0,0 +1,13 @@
@use '../../variables/sizing';
@use '../../utilities/type';
.rose-dropdown-section {
.rose-dropdown-section-title {
@include type.type(s, bold);
padding: 0 sizing.rems(s);
margin: 0;
$line-height: 36 / 14;
line-height: $line-height;
color: var(--ui-gray)
}
}
@@ -0,0 +1 @@
export { default } from 'rose/components/rose/dropdown/section';
@@ -35,6 +35,11 @@
<dropdown.button>Button menu item</dropdown.button>
<dropdown.button @style="danger">Button - danger</dropdown.button>
<dropdown.separator />
<dropdown.section @title="Dropdown Section Title">
<dropdown.link @route="index">Menu item</dropdown.link>
</dropdown.section>
</Rose::Dropdown>
<Rose::Dropdown @showCaret={{false}} @icon="more-horizontal" as |dropdown|>
@@ -0,0 +1,27 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | rose/dropdown/section', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
await render(hbs`
<Rose::Dropdown::Section>
template block text
</Rose::Dropdown::Section>
`);
assert.ok(find('.rose-dropdown-section'));
assert.equal(this.element.textContent.trim(), 'template block text');
});
test('it renders with optional @title', async function(assert) {
await render(hbs`
<Rose::Dropdown::Section @title="Section Title">
template block text
</Rose::Dropdown::Section>
`);
assert.equal(find('.rose-dropdown-section-title').textContent.trim(), 'Section Title');
});
});