This repository was archived by the owner on Aug 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(oui-dual-list): add dual-list component #311
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Dual List | ||
|
|
||
| <component-status cx-design="complete" ux="rc"></component-status> | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Basic | ||
|
|
||
| #### Array of strings | ||
|
|
||
| ```html:preview | ||
| <oui-dual-list | ||
| source="$ctrl.sourceStrings" | ||
| target="$ctrl.targetStrings"> | ||
| <oui-dual-list-source searchable></oui-dual-list-source> | ||
| <oui-dual-list-target></oui-dual-list-target> | ||
| </oui-dual-list> | ||
| ``` | ||
|
|
||
| #### Array of objects | ||
|
|
||
| ```html:preview | ||
| <oui-dual-list | ||
| source="$ctrl.sourceObjects" | ||
| target="$ctrl.targetObjects" | ||
| property="name"> | ||
| <oui-dual-list-source searchable></oui-dual-list-source> | ||
| <oui-dual-list-target></oui-dual-list-target> | ||
| </oui-dual-list> | ||
| ``` | ||
|
|
||
| #### Array of objects (deep nested property) | ||
|
|
||
| ```html:preview | ||
| <oui-dual-list | ||
| source="$ctrl.sourceNestedObjects" | ||
| target="$ctrl.targetNestedObjects" | ||
| property="name.firstName"> | ||
| <oui-dual-list-source searchable></oui-dual-list-source> | ||
| <oui-dual-list-target></oui-dual-list-target> | ||
| </oui-dual-list> | ||
| ``` | ||
|
|
||
| ### Loading state | ||
|
|
||
| **Note**: If `source` or `target` attribute are undefined, the loading will be automatically active. | ||
|
|
||
| ```html:preview | ||
| <div class="oui-doc-preview-only"> | ||
| <p> | ||
| <button class="oui-button oui-button_primary" type="button" ng-class="{ | ||
| 'oui-button_primary': $ctrl.togglerSourceLoading, | ||
| 'oui-button_secondary': !$ctrl.togglerSourceLoading | ||
| }" ng-click="$ctrl.togglerSourceLoading = !$ctrl.togglerSourceLoading"> | ||
| Toggle source loading | ||
| </button> | ||
| <button class="oui-button oui-button_primary" type="button" ng-class="{ | ||
| 'oui-button_primary': $ctrl.togglerTargetLoading, | ||
| 'oui-button_secondary': !$ctrl.togglerTargetLoading | ||
| }" ng-click="$ctrl.togglerTargetLoading = !$ctrl.togglerTargetLoading"> | ||
| Toggle target loading | ||
| </button> | ||
| </p> | ||
| </div> | ||
| <oui-dual-list | ||
| source="$ctrl.sourceLoading" | ||
| target="$ctrl.targetLoading"> | ||
| <oui-dual-list-source loading="$ctrl.togglerSourceLoading" searchable></oui-dual-list-source> | ||
| <oui-dual-list-target loading="$ctrl.togglerTargetLoading"></oui-dual-list-target> | ||
| </oui-dual-list> | ||
| ``` | ||
|
|
||
| ### Events | ||
|
|
||
| **Note**: Bulk actions `Add all` and `Remove all` will trigger callbacks for each moved items. | ||
|
|
||
| ```html:preview | ||
| <oui-dual-list | ||
| source="$ctrl.sourceEvents" | ||
| target="$ctrl.targetEvents" | ||
| on-add="$ctrl.onAdd(item)" | ||
| on-remove="$ctrl.onRemove(item)" | ||
| on-change="$ctrl.onChange(item)"> | ||
| <oui-dual-list-source searchable></oui-dual-list-source> | ||
| <oui-dual-list-target></oui-dual-list-target> | ||
| </oui-dual-list> | ||
| <div class="oui-doc-preview-only" style="margin-top: 15px;"> | ||
| <p><strong>onAdd ({{$ctrl.onAddCount}}):</strong> {{$ctrl.onAddItem | json}}</p> | ||
| <p><strong>onRemove ({{$ctrl.onRemoveCount}}):</strong> {{$ctrl.onRemoveItem | json}}</p> | ||
| <p><strong>onChange ({{$ctrl.onChangeCount}}):</strong> {{$ctrl.onChangeItem | json}}</p> | ||
| </div> | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| ### oui-dual-list | ||
|
|
||
| | Attribute | Type | Binding | One-time binding | Values | Default | Description | ||
| | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ||
| | `source` | array | = | no | n/a | n/a | source model bound to component | ||
| | `target` | array | = | no | n/a | n/a | target model bound to component | ||
| | `property` | string | @? | no | n/a | n/a | property path used to get value from item | ||
| | `on-add` | function | & | no | n/a | n/a | handler triggered when an item is added | ||
| | `on-remove` | function | & | no | n/a | n/a | handler triggered when an item is removed | ||
| | `on-change` | function | & | no | n/a | n/a | handler triggered when items have changed | ||
|
|
||
| ### oui-dual-list-source | ||
|
|
||
| | Attribute | Type | Binding | One-time binding | Values | Default | Description | ||
| | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ||
| | `heading` | string | @? | yes | n/a | n/a | heading text | ||
| | `placeholder` | string | @? | yes | n/a | n/a | placeholder text | ||
| | `loading` | boolean | <? | no | `true`, `false` | `false` | loading flag | ||
| | `searchable` | boolean | <? | no | `true`, `false` | `false` | searchbale flag | ||
|
|
||
| ### oui-dual-list-target | ||
|
|
||
| | Attribute | Type | Binding | One-time binding | Values | Default | Description | ||
| | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ||
| | `heading` | string | @? | yes | n/a | n/a | heading text | ||
| | `placeholder` | string | @? | yes | n/a | n/a | placeholder text | ||
| | `loading` | boolean | <? | no | `true`, `false` | `false` | loading flag | ||
| | `searchable` | boolean | <? | no | `true`, `false` | `false` | searchbale flag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "@ovh-ui/oui-dual-list", | ||
| "version": "1.0.0", | ||
| "main": "./src/index.js", | ||
| "license": "BSD-3-Clause", | ||
| "author": "OVH SAS" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import controller from "./dual-list.controller"; | ||
|
|
||
| export default { | ||
| controller, | ||
| bindings: { | ||
| source: "=", | ||
| target: "=", | ||
| property: "@?", | ||
| onAdd: "&", | ||
| onRemove: "&", | ||
| onChange: "&" | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import get from "lodash/get"; | ||
| import remove from "lodash/remove"; | ||
|
|
||
| export default class { | ||
| constructor ($attrs, $element, $filter, $timeout) { | ||
| "ngInject"; | ||
|
|
||
| this.$attrs = $attrs; | ||
| this.$element = $element; | ||
| this.$filter = $filter; | ||
| this.$timeout = $timeout; | ||
| } | ||
|
|
||
| $postLink () { | ||
| this.$timeout(() => | ||
| this.$element.addClass("oui-dual-list") | ||
| ); | ||
| } | ||
|
|
||
| getProperty (item) { | ||
| return get(item, this.property, item); | ||
| } | ||
|
|
||
| moveToSource (item) { | ||
| if (angular.isArray(this.source)) { | ||
| remove(this.target, (source) => source === item); | ||
| this.source.push(item); | ||
|
|
||
| // Callbacks | ||
| this.onChange({ item }); | ||
| this.onRemove({ item }); | ||
| } | ||
| } | ||
|
|
||
| moveAllToSource (searchQuery) { | ||
| // Need to do a while for the callbacks | ||
| while (angular.isArray(this.source) && this.$filter("filter")(this.target, searchQuery).length) { | ||
| this.moveToSource(this.$filter("filter")(this.target, searchQuery)[0]); | ||
| } | ||
| } | ||
|
|
||
| moveToTarget (item) { | ||
| if (angular.isArray(this.target)) { | ||
| remove(this.source, (source) => source === item); | ||
| this.target.push(item); | ||
|
|
||
| // Callbacks | ||
| this.onChange({ item }); | ||
| this.onAdd({ item }); | ||
| } | ||
| } | ||
|
|
||
| moveAllToTarget (searchQuery) { | ||
| // Need to do a while for the callbacks | ||
| while (angular.isArray(this.target) && this.$filter("filter")(this.source, searchQuery).length) { | ||
| this.moveToTarget(this.$filter("filter")(this.source, searchQuery)[0]); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import merge from "lodash/merge"; | ||
|
|
||
| export default class { | ||
| constructor () { | ||
| this.translations = { | ||
| source: { | ||
| heading: "Items to select", | ||
| placeholder: "No item to select", | ||
| move: "Add", | ||
| moveAll: "Add all", | ||
| search: "Search in source content" | ||
| }, | ||
| target: { | ||
| heading: "Selected items", | ||
| placeholder: "No selected item", | ||
| move: "Remove", | ||
| moveAll: "Remove all", | ||
| search: "Search in target content" | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Set the translations | ||
| * @param {Object} translations a map of translations | ||
| */ | ||
| setTranslations (translations) { | ||
| this.translations = merge(this.translations, translations); | ||
| return this; | ||
| } | ||
|
|
||
| $get () { | ||
| return { | ||
| translations: this.translations | ||
| }; | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import DualList from "./dual-list.component"; | ||
| import DualListProvider from "./dual-list.provider"; | ||
| import DualListSource from "./source/dual-list-source.component"; | ||
| import DualListTarget from "./target/dual-list-target.component"; | ||
|
|
||
| export default angular | ||
| .module("oui.dual-list", []) | ||
| .component("ouiDualList", DualList) | ||
| .component("ouiDualListSource", DualListSource) | ||
| .component("ouiDualListTarget", DualListTarget) | ||
| .provider("ouiDualListConfiguration", DualListProvider) | ||
| .name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| { | ||
| "string": { | ||
| "source": ["Lorem"], | ||
| "target": ["Ipsum"] | ||
| }, | ||
| "strings": { | ||
| "source": [ | ||
| "Andrew", | ||
| "Red", | ||
| "Lila", | ||
| "Marie", | ||
| "Robert", | ||
| "Hope", | ||
| "Alexis", | ||
| "Madison", | ||
| "Vanessa" | ||
| ], | ||
| "target": [ | ||
| "Kevin", | ||
| "Mark" | ||
| ] | ||
| }, | ||
| "object": { | ||
| "source": [{ "name": "Lorem", "age": 15 }], | ||
| "target": [{ "name": "Ipsum", "age": 25 }] | ||
| }, | ||
| "objects": { | ||
| "source" : [ | ||
| { "name": "Andrew", "age": 15 }, | ||
| { "name": "Red", "age": 25 }, | ||
| { "name": "Lila", "age": 34 }, | ||
| { "name": "Marie", "age": 12 }, | ||
| { "name": "Robert", "age": 64 }, | ||
| { "name": "Hope", "age": 15 }, | ||
| { "name": "Alexis", "age": 25 }, | ||
| { "name": "Madison", "age": 34 }, | ||
| { "name": "Vanessa", "age": 12 } | ||
| ], | ||
| "target" : [ | ||
| { "name": "Kevin", "age": 12 }, | ||
| { "name": "Mark", "age": 64 } | ||
| ] | ||
| }, | ||
| "nestedObject": { | ||
| "source": [{ "name": { "firstName": "Lorem" }, "age": 15 }], | ||
| "target": [{ "name": { "firstName": "Ipsum" }, "age": 25 }] | ||
| }, | ||
| "nestedObjects" : { | ||
| "source": [ | ||
| { "name": { "firstName": "Andrew" }, "age": 15 }, | ||
| { "name": { "firstName": "Red" }, "age": 25 }, | ||
| { "name": { "firstName": "Lila" }, "age": 34 }, | ||
| { "name": { "firstName": "Marie" }, "age": 12 }, | ||
| { "name": { "firstName": "Robert" }, "age": 64 }, | ||
| { "name": { "firstName": "Hope" }, "age": 15 }, | ||
| { "name": { "firstName": "Alexis" }, "age": 25 }, | ||
| { "name": { "firstName": "Madison" }, "age": 34 }, | ||
| { "name": { "firstName": "Vanessa" }, "age": 12 } | ||
| ], | ||
| "target" : [ | ||
| { "name": { "firstName": "Kevin" }, "age": 12 }, | ||
| { "name": { "firstName": "Mark" }, "age": 64 } | ||
| ] | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.