Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit c7c93f6

Browse files
authored
Merge pull request #369 from ovh-ux/develop
Develop
2 parents cee63cd + 9269a99 commit c7c93f6

File tree

12 files changed

+122
-18
lines changed

12 files changed

+122
-18
lines changed

packages/oui-header-tabs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@
8484
</oui-page-header>
8585
```
8686

87+
88+
### With action click
89+
90+
```html:preview
91+
<oui-header-tabs>
92+
<oui-header-tabs-item text="Home" href="/#" on-click="$ctrl.onActionClick()"></oui-header-tabs-item>
93+
<oui-header-tabs-item text="Page Header" href="/#!/oui-angular/page-header"></oui-header-tabs-item>
94+
<oui-header-tabs-item text="Header Tabs" href="/#!/oui-angular/header-tabs" active></oui-header-tabs-item>
95+
<oui-header-tabs-item text="Pagination" href="/#!/oui-angular/pagination"></oui-header-tabs-item>
96+
<oui-header-tabs-item text="Datagrid" href="/#!/oui-angular/datagrid" on-click="$ctrl.onActionClick()"></oui-header-tabs-item>
97+
</oui-header-tabs>
98+
```
99+
87100
## API
88101

89102
### oui-header-tabs-item
@@ -97,6 +110,7 @@
97110
| `active` | boolean | <? | no | `true`, `false` | `false` | manual active flag
98111
| `disabled` | boolean | <? | yes | `true`, `false` | `false` | disabled flag
99112
| `external` | boolean | <? | yes | `true`, `false` | `false` | external link flag
113+
| `on-click` | function | & | no | n/a | n/a | click handler
100114

101115
**Note**: `ui-router` is needed for the attributes `state` and `state-params`.
102116

packages/oui-header-tabs/src/header-tabs-item.component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
stateParams: "<?",
1212
external: "<?",
1313
active: "<?",
14-
disabled: "<?"
14+
disabled: "<?",
15+
onClick: "&"
1516
}
1617
};

packages/oui-header-tabs/src/header-tabs-item.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
<a ng-attr-rel="{{::$ctrl.linkRel}}"
55
ng-attr-target="{{::$ctrl.linkTarget}}"
66
ng-href="{{::$ctrl.href}}"
7-
ng-if="!!$ctrl.href && !$ctrl.disabled">
7+
ng-if="!!$ctrl.href && !$ctrl.disabled"
8+
ng-click="$ctrl.onClick()">
89
<span ng-bind="::$ctrl.text"></span>
910
<span class="oui-icon oui-icon-external_link" aria-hidden="true"
1011
ng-if="::$ctrl.external">
1112
</span>
1213
</a>
1314
<a ng-bind="::$ctrl.text"
15+
ng-click="$ctrl.onClick()"
1416
ng-if="!!$ctrl.state && !$ctrl.disabled"
1517
ui-sref="{{::$ctrl.getFullSref()}}">
1618
</a>

packages/oui-header-tabs/src/index.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,21 @@ describe("ouiHeaderTabs", () => {
126126
expect($separator.hasClass("oui-dropdown-menu__divider")).toBe(true);
127127
expect($separator.attr("role")).toBe("separator");
128128
});
129+
130+
it("should call function of onClick attribute, when header tab item is clicked", () => {
131+
const clickSpy = jasmine.createSpy("spy");
132+
const element = TestUtils.compileTemplate(`
133+
<oui-header-tabs>
134+
<oui-header-tabs-item text="Tab" href="/#" on-click="$ctrl.clickHandler()"></oui-header-tabs-item>
135+
</oui-header-tabs>`, {
136+
clickHandler: clickSpy
137+
}
138+
);
139+
140+
const item = element[0].querySelector(".oui-header-tabs__item a");
141+
angular.element(item).triggerHandler("click");
142+
expect(clickSpy).toHaveBeenCalled();
143+
expect(clickSpy.calls.count()).toEqual(1);
144+
});
129145
});
130146
});

packages/oui-popover/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,29 @@
2727

2828
### Using a template with `oui-popover-template` attribute
2929

30+
<oui-message type="warning">
31+
This method use <code class="oui-doc-codespan">ngInclude</code> to add the template in a popover and create an <strong>isolated</strong> scope.<br />
32+
Use <code class="oui-doc-codespan">oui-popover-scope</code> to extend the isolated scope and <code class="oui-doc-codespan">$ctrl</code> to access thoses values.
33+
</oui-message>
34+
3035
```html:preview
31-
<button type="button"
36+
<input type="text" class="oui-input oui-input_inline"
37+
ng-init="$ctrl.awesome = 'awesome'"
38+
ng-model="$ctrl.awesome">
39+
<button type="button"
3240
class="oui-button oui-button_primary"
3341
oui-popover
42+
oui-popover-scope="$ctrl"
3443
oui-popover-template="popover.html">
3544
Click to toggle popover
3645
</button>
3746
3847
<script type="text/ng-template" id="popover.html">
39-
<p ng-init="$ctrl.awesome = 'awesome'">This is an <strong ng-bind="$ctrl.awesome"></strong> popover content.</p>
48+
<p>This is an <strong ng-bind="$ctrl.awesome"></strong> popover content.</p>
4049
<p><a href="#">The quick brown fox jumps over the lazy dog</a></p>
4150
</script>
4251
```
4352

44-
**Note**: This method use `ngInclude` to add the template in a popover. The content of your template will be compiled with a **new** scope. See [ngInclude](https://docs.angularjs.org/api/ng/directive/ngInclude).
45-
4653
### Using `oui-popover` component
4754

4855
```html:preview
@@ -120,8 +127,9 @@
120127
| Attribute | Type | Binding | One-time Binding | Values | Default | Description
121128
| ---- | ---- | ---- | ---- | ---- | ---- | ----
122129
| `oui-popover` | string | @ | no | n/a | `title` attribute | popover content
123-
| `oui-popover-template` | string | @? | no | n/a | n/a | popover content template
124130
| `oui-popover-placement` | string | @? | yes | See [Popper placements](https://popper.js.org/popper-documentation.html#Popper.placements) | `right` | modifier for alignment
131+
| `oui-popover-scope` | string | <? | no | n/a | n/a | scope of the popover template
132+
| `oui-popover-template` | string | @? | no | n/a | n/a | id of the popover template
125133

126134
## Deprecated
127135

packages/oui-popover/src/index.spec.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,33 @@ describe("ouiPopover", () => {
6060
});
6161

6262
it("should create a popover, next to the trigger, with the content of the template", () => {
63+
const foo = "bar";
6364
const component = testUtils.compileTemplate(`<div>
64-
<button class="trigger" oui-popover="foo" oui-popover-template="popover.html"></button>
65-
<script type="text/ng-template" id="popover.html">foo</script>
65+
<button class="trigger" oui-popover oui-popover-template="popover.html"></button>
66+
<script type="text/ng-template" id="popover.html">${foo}</script>
6667
</div>`);
6768

6869
$timeout.flush();
6970

7071
const popover = angular.element(component[0].querySelector(".trigger")).next();
7172

72-
expect(popover.text().trim()).toBe("foo");
73+
expect(popover.text().trim()).toBe(foo);
74+
});
75+
76+
it("should extend the scope of the template", () => {
77+
const foo = "bar";
78+
const component = testUtils.compileTemplate(`<div>
79+
<button class="trigger" oui-popover oui-popover-template="popover.html" oui-popover-scope="$ctrl"></button>
80+
<script type="text/ng-template" id="popover.html"><span ng-bind="$ctrl.foo"></span></script>
81+
</div>`, {
82+
foo
83+
});
84+
85+
$timeout.flush();
86+
87+
const popover = angular.element(component[0].querySelector(".trigger")).next();
88+
89+
expect(popover.text().trim()).toBe(foo);
7390
});
7491

7592
it("should set aria-expanded when trigger is clicked", () => {

packages/oui-popover/src/popover.controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export default class PopoverController {
5050

5151
// Support for attribute `oui-popover`
5252
// Create a new scope to compile the popover next to the trigger
53-
const popoverScope = angular.extend(this.$scope.$new(true), { $popoverCtrl: this });
53+
const popoverScope = angular.extend(this.$scope.$new(true), {
54+
$popoverCtrl: this,
55+
$ctrl: this.scope
56+
});
5457
const popoverTemplate = this.$compile(template)(popoverScope);
5558

5659
// Add compiled template after $element

packages/oui-popover/src/popover.directive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default () => {
99
text: "@ouiPopover",
1010
title: "@?",
1111
placement: "@?ouiPopoverPlacement",
12+
scope: "<?ouiPopoverScope",
1213
template: "@?ouiPopoverTemplate"
1314
},
1415
controller,

packages/oui-slideshow/README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,40 @@
7878
</div>
7979
```
8080

81+
### Panel change event
82+
**Note**: If you want to access the parameters inside `on-panel-change` callback, you need to use `direction` and `index` variables as below.
83+
84+
* `direction` returns string of `prev` or `next`
85+
* `index` returns index of current slide
86+
87+
```html:preview
88+
<div class="oui-doc-preview-only-keep-children" style="padding:50px 35px;background-color:rgba(0,0,0,0.3)">
89+
<oui-slideshow on-panel-change="$ctrl.onPanelChange(direction, index)">
90+
<oui-slideshow-panel heading="New feature"
91+
picture="https://upload.wikimedia.org/wikipedia/commons/4/4a/Cercle_rouge_100%25.svg">
92+
Display your infrastructure as a list
93+
</oui-slideshow-panel>
94+
<oui-slideshow-panel heading="Introducing Ad-Sync"
95+
picture="https://upload.wikimedia.org/wikipedia/commons/4/4a/Cercle_rouge_100%25.svg"
96+
href="http://www.ovh.com/"
97+
label="Discover">
98+
Designed to help you synchronize your local Active Directory with your OVH Active Directory.
99+
</oui-slideshow-panel>
100+
</oui-slideshow>
101+
</div>
102+
```
103+
81104
## API
82105

83106
### oui-slideshow
84107

85-
| Attribute | Type | Binding | One-time Binding | Values | Default | Description
86-
| ---- | ---- | ---- | ---- | ---- | ---- | ----
87-
| `theme` | string | @? | yes | n/a | `default` | add specific theme to component
88-
| `loading` | boolean | <? | no | `true`, `false` | `false` | display loader flag
89-
| `loop` | boolean | <? | no | `true`, `false` | `false` | whether the component should cycle continuously
90-
| `on-dismiss` | function | & | no | n/a | n/a | dismiss callback
108+
| Attribute | Type | Binding | One-time Binding | Values | Default | Description
109+
| ---- | ---- | ---- | ---- | ---- | ---- | ----
110+
| `theme` | string | @? | yes | n/a | `default` | add specific theme to component
111+
| `loading` | boolean | <? | no | `true`, `false` | `false` | display loader flag
112+
| `loop` | boolean | <? | no | `true`, `false` | `false` | whether the component should cycle continuously
113+
| `on-dismiss` | function | & | no | n/a | n/a | dismiss callback
114+
| `on-panel-change` | function | & | no | direction, index | n/a | handler triggered when on click of next slide
91115

92116
### oui-slideshow-panel
93117

packages/oui-slideshow/src/index.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ describe("ouiSlideshow", () => {
142142
$timeout.flush();
143143
expect($firstPanel.hasClass("active")).toBe(false);
144144
});
145+
146+
it("should call function of event with attributes", () => {
147+
const onPanelChangeSpy = jasmine.createSpy("onPanelChangeSpy");
148+
const element = TestUtils.compileTemplate(`
149+
<oui-slideshow on-panel-change="$ctrl.onPanelChangeSpy(direction, index)">
150+
<oui-slideshow-panel></oui-slideshow-panel>
151+
<oui-slideshow-panel></oui-slideshow-panel>
152+
</oui-slideshow>`, {
153+
onPanelChangeSpy
154+
});
155+
const direction = "next";
156+
const index = 1;
157+
$timeout.flush();
158+
getNextButton(element).triggerHandler("click");
159+
expect(onPanelChangeSpy).toHaveBeenCalledWith(direction, index);
160+
});
145161
});
146162
});
147163
});

0 commit comments

Comments
 (0)