Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
feat: introduce UiPopover component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeanjones committed Dec 29, 2022
1 parent b287187 commit a5d7fcf
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
47 changes: 47 additions & 0 deletions addon/components/ui-popover/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import UiContextualContainer, {
SelectorStrategies,
TriggerEvents,
} from '../-internals/contextual-container/component';

/**
*
*/
export default class UiPopoverContextContainer extends UiContextualContainer {
/**
* The amount of time, in milliseconds, between the triggering interaction
* and when the tooltip is displayed.
*/
delay = 150;

distance = 11;

/** @hidden */
ariaAttachAs = 'aria-controls';

/** @hidden */
closeOnOutsideClick = false;

/** @hidden */
triggerEvents = TriggerEvents.CLICK;

/** @hidden */
triggerSelector = SelectorStrategies.PARENT;

/** @hidden */
readonly overlayComponent = 'ui-popover/element';

public didInsertElement() {
super.didInsertElement();
this.getAriaElement()?.setAttribute('aria-expanded', 'false');
}

/** @hidden */
onShow = () => {
this.getAriaElement()?.setAttribute('aria-expanded', 'true');
};

/** @hidden */
onHide = () => {
this.getAriaElement()?.setAttribute('aria-expanded', 'false');
};
}
27 changes: 27 additions & 0 deletions addon/components/ui-popover/element/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import UiContextualElement from '@nsf-open/ember-ui-foundation/components/-internals/contextual-container/element/component';
import { computed } from '@ember/object';

export default class UiPopoverContextElement extends UiContextualElement {
arrowClassName = 'arrow';

innerClassName = 'popover-content';

titleTextClassName = 'popover-title';

ariaRole = 'region';

@computed('fade', 'actualPlacement', 'showContent')
public get popperClassNames() {
const classNames = ['popover', this.actualPlacement];

if (this.fade) {
classNames.push('fade');
}

if (this.showContent) {
classNames.push('in');
}

return classNames;
}
}
35 changes: 35 additions & 0 deletions addon/components/ui-popover/ui-popover.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { hbs } from 'ember-cli-htmlbars';

export default {
title: 'Elements/ui-popover',
component: 'components/ui-popover/component',

parameters: {
layout: 'centered',
},

args: {
textContent: 'Hello World',
},
};

const Template = (context: unknown) => {
return {
context: Object.assign({}, context),

// language=handlebars
template: hbs`
<div class="text-center">
<UiButton @variant="primary">
Log In
<UiPopover @title="Hello World">
Username and password go here
</UiPopover>
</UiButton>
</div>
`,
};
};

export const Default = Template.bind({});
Default.storyName = 'ui-popover';
11 changes: 11 additions & 0 deletions addon/styles/addon.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ nice with other libraries/tools. */
border-bottom-left-radius: 0;
border-left: 0;
}

.popover {
display: block;
}

.popover.top .arrow,
.popover.bottom .arrow,
.popover.left .arrow,
.popover.right .arrow {
margin: 0;
}
1 change: 1 addition & 0 deletions app/components/ui-popover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@nsf-open/ember-ui-foundation/components/ui-popover/component';
1 change: 1 addition & 0 deletions app/components/ui-popover/element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@nsf-open/ember-ui-foundation/components/ui-popover/element/component';

0 comments on commit a5d7fcf

Please sign in to comment.