@1024pix/pix-ui 13.1.0 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/addon/components/pix-dropdown.hbs +85 -0
- package/addon/components/pix-dropdown.js +181 -0
- package/addon/styles/_pix-dropdown.scss +149 -0
- package/addon/styles/addon.scss +1 -0
- package/app/components/pix-dropdown.js +1 -0
- package/app/stories/form.stories.js +13 -0
- package/app/stories/pix-dropdown.stories.js +180 -0
- package/app/stories/pix-dropdown.stories.mdx +69 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<div class="pix-dropdown">
|
|
2
|
+
{{#if this.label}}
|
|
3
|
+
<label id={{@id}} class="pix-dropdown__label">{{this.label}}</label>
|
|
4
|
+
{{/if}}
|
|
5
|
+
<div class="pix-dropdown__controller">
|
|
6
|
+
<button
|
|
7
|
+
type="button"
|
|
8
|
+
class="pix-dropdown__controller--placeholder{{if this.isExpanded ' expanded'}}"
|
|
9
|
+
aria-label={{if this.isExpanded @collapseLabel @expandLabel}}
|
|
10
|
+
{{on "click" this.toggleDropdown}}
|
|
11
|
+
{{on "keyup" this.navigateThroughOptions}}
|
|
12
|
+
>
|
|
13
|
+
<p
|
|
14
|
+
title={{this.placeholder}}
|
|
15
|
+
class="pix-dropdown__controller--placeholder-text{{unless
|
|
16
|
+
this.hasSelectedOption
|
|
17
|
+
' default'
|
|
18
|
+
}}"
|
|
19
|
+
>{{this.placeholder}}</p>
|
|
20
|
+
</button>
|
|
21
|
+
{{#if this.hasSelectedOption}}
|
|
22
|
+
<button
|
|
23
|
+
type="button"
|
|
24
|
+
class="pix-dropdown__controller--clear"
|
|
25
|
+
{{on "click" this.clearSelection}}
|
|
26
|
+
aria-label={{@clearLabel}}
|
|
27
|
+
>
|
|
28
|
+
<FaIcon @icon="times" />
|
|
29
|
+
</button>
|
|
30
|
+
{{/if}}
|
|
31
|
+
<FaIcon
|
|
32
|
+
class="pix-dropdown__controller--chevron"
|
|
33
|
+
@icon={{if this.isExpanded "chevron-up" "chevron-down"}}
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
<div
|
|
37
|
+
role="listbox"
|
|
38
|
+
id={{this.menuId}}
|
|
39
|
+
tabindex="-1"
|
|
40
|
+
class="pix-dropdown__menu{{if this.isExpanded ' expanded'}}"
|
|
41
|
+
aria-labelledby={{if this.label @id}}
|
|
42
|
+
aria-label={{unless this.label @placeholder}}
|
|
43
|
+
aria-hidden={{if this.isExpanded "false" "true"}}
|
|
44
|
+
aria-activedescendant={{if this.selectedOption this.selectedOption.value}}
|
|
45
|
+
{{on "keyup" this.navigateThroughOptions}}
|
|
46
|
+
{{on "scroll" this.incrementPage}}
|
|
47
|
+
>
|
|
48
|
+
{{#if @isSearchable}}
|
|
49
|
+
<div class="pix-dropdown__menu--search">
|
|
50
|
+
<FaIcon class="pix-dropdown__menu--search-icon" @icon="search" />
|
|
51
|
+
<label
|
|
52
|
+
class="pix-dropdown__menu--search-input-label"
|
|
53
|
+
for={{this.searchInputId}}
|
|
54
|
+
>{{@searchPlaceholder}}</label>
|
|
55
|
+
<input
|
|
56
|
+
class="pix-dropdown__menu--search-input"
|
|
57
|
+
id={{this.searchInputId}}
|
|
58
|
+
autocomplete="off"
|
|
59
|
+
tabindex={{unless this.isExpanded "-1"}}
|
|
60
|
+
placeholder={{@searchPlaceholder}}
|
|
61
|
+
{{on "input" this.filterOptions}}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
{{/if}}
|
|
65
|
+
{{#each this.options as |opt index|}}
|
|
66
|
+
{{#if (lt index this.showLimit)}}
|
|
67
|
+
<div
|
|
68
|
+
role="option"
|
|
69
|
+
id={{opt.value}}
|
|
70
|
+
tabindex="-1"
|
|
71
|
+
class="pix-dropdown__menu--option{{if
|
|
72
|
+
(eq this.selectedOption.value opt.value)
|
|
73
|
+
' selected'
|
|
74
|
+
}}"
|
|
75
|
+
aria-selected={{if (eq this.selectedOption.value opt.value) "true"}}
|
|
76
|
+
{{on "click" (fn this.selectOption opt)}}
|
|
77
|
+
{{on "mouseover" this.resetPreviouslyFocused}}
|
|
78
|
+
{{on "keypress" (fn this.onOptionKeyPress opt)}}
|
|
79
|
+
>
|
|
80
|
+
{{opt.label}}
|
|
81
|
+
</div>
|
|
82
|
+
{{/if}}
|
|
83
|
+
{{/each}}
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
|
|
5
|
+
export default class PixDropdown extends Component {
|
|
6
|
+
defaultId = Math.floor(Math.random() * 100);
|
|
7
|
+
focusedOption = null;
|
|
8
|
+
focusedIndex = null;
|
|
9
|
+
@tracked page = 1;
|
|
10
|
+
@tracked selectedOption = null;
|
|
11
|
+
@tracked isExpanded = false;
|
|
12
|
+
@tracked options = this.args.options;
|
|
13
|
+
@tracked menuId = `menu-${this.defaultId}`;
|
|
14
|
+
@tracked searchInputId = `search-input-${this.defaultId}`;
|
|
15
|
+
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
|
|
19
|
+
if (!this.args.label && !this.args.placeholder) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'ERROR in PixDropdown component, you need to provide a label and/or a placeholder'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (this.args.selectedOption) {
|
|
26
|
+
this.selectedOption = this.args.options.find(
|
|
27
|
+
({ value }) => value === this.args.selectedOption
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get hasSelectedOption() {
|
|
33
|
+
return !!this.selectedOption;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get placeholder() {
|
|
37
|
+
return this.selectedOption?.label || this.args.placeholder;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get label() {
|
|
41
|
+
const labelIsDefined = this.args.label?.trim();
|
|
42
|
+
const idIsNotDefined = !this.args.id?.trim();
|
|
43
|
+
|
|
44
|
+
if (labelIsDefined && idIsNotDefined) {
|
|
45
|
+
throw new Error('ERROR in PixDropdown component, @id param is necessary when giving @label');
|
|
46
|
+
}
|
|
47
|
+
return this.args.label || null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get showLimit() {
|
|
51
|
+
if (!this.args.pageSize) return this.options.length;
|
|
52
|
+
|
|
53
|
+
const numberOfOptionsAccordingToPage = this.args.pageSize * this.page;
|
|
54
|
+
return Math.min(this.options.length, numberOfOptionsAccordingToPage);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@action
|
|
58
|
+
resetPreviouslyFocused() {
|
|
59
|
+
if (!this.focusedOption) return;
|
|
60
|
+
|
|
61
|
+
const previouslyFocusedElement = document.getElementById(this.focusedOption.value);
|
|
62
|
+
previouslyFocusedElement?.blur();
|
|
63
|
+
this.focusedOption = undefined;
|
|
64
|
+
this.focusedIndex = undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_navigateToOption(option, index) {
|
|
68
|
+
if (!option) return;
|
|
69
|
+
|
|
70
|
+
this.resetPreviouslyFocused();
|
|
71
|
+
this.focusedOption = option;
|
|
72
|
+
this.focusedIndex = index;
|
|
73
|
+
const focusedElement = document.getElementById(option.value);
|
|
74
|
+
focusedElement?.scrollIntoView({ block: 'nearest' });
|
|
75
|
+
focusedElement?.focus();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_computeNextIndex(isArrowDown, index) {
|
|
79
|
+
const length = this.showLimit;
|
|
80
|
+
let nextIndex;
|
|
81
|
+
if (index === undefined || index === null) {
|
|
82
|
+
nextIndex = isArrowDown ? 0 : length - 1;
|
|
83
|
+
} else {
|
|
84
|
+
const delta = isArrowDown ? 1 : -1;
|
|
85
|
+
nextIndex = index + delta;
|
|
86
|
+
}
|
|
87
|
+
// navigate through array in a circle
|
|
88
|
+
// (i.e. go back to first after last or last after first)
|
|
89
|
+
return ((nextIndex % length) + length) % length;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@action
|
|
93
|
+
navigateThroughOptions(event) {
|
|
94
|
+
const isArrowDown = event.code === 'ArrowDown';
|
|
95
|
+
if (event.code !== 'ArrowUp' && !isArrowDown) return;
|
|
96
|
+
const nextIndex = this._computeNextIndex(isArrowDown, this.focusedIndex);
|
|
97
|
+
this._navigateToOption(this.options[nextIndex], nextIndex);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@action
|
|
101
|
+
toggleDropdown() {
|
|
102
|
+
this.isExpanded = !this.isExpanded;
|
|
103
|
+
|
|
104
|
+
if (this.isExpanded) {
|
|
105
|
+
this.resetPreviouslyFocused();
|
|
106
|
+
const searchInput = document.getElementById(this.searchInputId);
|
|
107
|
+
if (searchInput) {
|
|
108
|
+
searchInput.focus();
|
|
109
|
+
} else {
|
|
110
|
+
this._navigateToOption(this.options[0], 0);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const menu = document.getElementById(this.menuId);
|
|
115
|
+
menu.scrollTop = 0;
|
|
116
|
+
this.page = 1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@action
|
|
120
|
+
selectOption(option) {
|
|
121
|
+
if (this.selectedOption?.value !== option.value) {
|
|
122
|
+
this.args.onSelect?.(option.value);
|
|
123
|
+
this.selectedOption = option;
|
|
124
|
+
}
|
|
125
|
+
this.isExpanded = false;
|
|
126
|
+
|
|
127
|
+
const searchInput = document.getElementById(this.searchInputId);
|
|
128
|
+
if (searchInput) {
|
|
129
|
+
searchInput.value = '';
|
|
130
|
+
this.options = this.args.options;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@action
|
|
135
|
+
onOptionKeyPress(option, event) {
|
|
136
|
+
if (event.code === 'Enter' || event.code === 'Space') this.selectOption(option);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@action
|
|
140
|
+
clearSelection(event) {
|
|
141
|
+
event.stopPropagation();
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
this.selectedOption = null;
|
|
144
|
+
this._navigateToOption(this.options[0], 0);
|
|
145
|
+
this.args.onSelect?.();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@action
|
|
149
|
+
onClearKeyPress(event) {
|
|
150
|
+
if (event.code === 'Enter' || event.code === 'Space') this.clearSelection(event);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@action
|
|
154
|
+
filterOptions(event) {
|
|
155
|
+
this.resetPreviouslyFocused();
|
|
156
|
+
const filterValue = event.target?.value.toLowerCase();
|
|
157
|
+
this.page = 1;
|
|
158
|
+
this.options = filterValue
|
|
159
|
+
? this.args.options.filter(({ label }) => label.toLowerCase().includes(filterValue))
|
|
160
|
+
: this.args.options;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
_isLastOptionVisible(option) {
|
|
164
|
+
const lastVisibleOption = document.getElementById(option.value);
|
|
165
|
+
const menu = document.getElementById(this.menuId);
|
|
166
|
+
|
|
167
|
+
const { bottom, height, top } = lastVisibleOption.getBoundingClientRect();
|
|
168
|
+
const menuRect = menu.getBoundingClientRect();
|
|
169
|
+
|
|
170
|
+
return top <= menuRect.top ? menuRect.top - top <= height : bottom - menuRect.bottom <= height;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@action
|
|
174
|
+
incrementPage() {
|
|
175
|
+
if (!this.args.pageSize) return;
|
|
176
|
+
|
|
177
|
+
if (this._isLastOptionVisible(this.options[this.showLimit - 1])) {
|
|
178
|
+
this.page += 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
.pix-dropdown {
|
|
2
|
+
@import 'reset-css';
|
|
3
|
+
width: 100%;
|
|
4
|
+
position: relative;
|
|
5
|
+
|
|
6
|
+
button {
|
|
7
|
+
background: transparent;
|
|
8
|
+
margin: 0;
|
|
9
|
+
text-align: left;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&__label {
|
|
14
|
+
@include label();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&__controller {
|
|
18
|
+
width: 100%;
|
|
19
|
+
position: relative;
|
|
20
|
+
|
|
21
|
+
&--placeholder {
|
|
22
|
+
@include hoverFormElement();
|
|
23
|
+
@include focusFormElement();
|
|
24
|
+
width: 100%;
|
|
25
|
+
min-width: 250px;
|
|
26
|
+
min-height: 34px;
|
|
27
|
+
border: 1px solid $grey-40;
|
|
28
|
+
border-radius: $spacing-xxs;
|
|
29
|
+
padding: 0;
|
|
30
|
+
background: white;
|
|
31
|
+
|
|
32
|
+
&.expanded {
|
|
33
|
+
border-bottom-left-radius: 0;
|
|
34
|
+
border-bottom-right-radius: 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&--placeholder-text {
|
|
39
|
+
margin: 0;
|
|
40
|
+
font-size: 0.875rem;
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
text-overflow: ellipsis;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
padding: 8px 68px 8px 16px;
|
|
45
|
+
|
|
46
|
+
&.default {
|
|
47
|
+
color: $grey-60;
|
|
48
|
+
padding-right: 36px;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&--clear {
|
|
53
|
+
font-size: 1rem;
|
|
54
|
+
color: $grey-50;
|
|
55
|
+
position: absolute;
|
|
56
|
+
padding: 8px 8px 6px;
|
|
57
|
+
border: none;
|
|
58
|
+
border-right: 2px solid $grey-40;
|
|
59
|
+
right: 38px;
|
|
60
|
+
top: 1px;
|
|
61
|
+
width: fit-content;
|
|
62
|
+
|
|
63
|
+
&:hover {
|
|
64
|
+
color: $grey-70;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&--chevron {
|
|
69
|
+
position: absolute;
|
|
70
|
+
z-index: -1;
|
|
71
|
+
top: 9px;
|
|
72
|
+
right: 12px;
|
|
73
|
+
color: $grey-50;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&__menu {
|
|
78
|
+
background: white;
|
|
79
|
+
position: absolute;
|
|
80
|
+
top: 100%;
|
|
81
|
+
width: 100%;
|
|
82
|
+
max-height: 0;
|
|
83
|
+
transition: max-height ease-in 0.5s;
|
|
84
|
+
overflow: hidden;
|
|
85
|
+
overflow-y: auto;
|
|
86
|
+
z-index: 1;
|
|
87
|
+
|
|
88
|
+
&.expanded {
|
|
89
|
+
max-height: 300px;
|
|
90
|
+
border: 1px solid $grey-40;
|
|
91
|
+
border-top: none;
|
|
92
|
+
border-radius: 0 0 $spacing-xxs $spacing-xxs;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&--search {
|
|
96
|
+
display: flex;
|
|
97
|
+
position: relative;
|
|
98
|
+
|
|
99
|
+
&-icon {
|
|
100
|
+
color: $grey-30;
|
|
101
|
+
margin: 4px;
|
|
102
|
+
position: absolute;
|
|
103
|
+
left: 16px;
|
|
104
|
+
top: 12px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&-input {
|
|
108
|
+
border: none;
|
|
109
|
+
border-bottom: 1px solid $grey-40;
|
|
110
|
+
font-size: 0.875rem;
|
|
111
|
+
flex-grow: 1;
|
|
112
|
+
margin: 12px 12px 8px;
|
|
113
|
+
padding: 4px 4px 4px 32px;
|
|
114
|
+
outline: none;
|
|
115
|
+
|
|
116
|
+
&:hover {
|
|
117
|
+
box-shadow: inset 0 -0.7px 0 0 $grey-40;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&:focus {
|
|
121
|
+
box-shadow: inset 0 -0.7px 0 0 $blue;
|
|
122
|
+
border-color: $blue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
&-label {
|
|
126
|
+
height: 0;
|
|
127
|
+
width: 0;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&--option {
|
|
134
|
+
padding: 8px 12px;
|
|
135
|
+
font-size: 0.875rem;
|
|
136
|
+
cursor: pointer;
|
|
137
|
+
|
|
138
|
+
&.selected {
|
|
139
|
+
color: $grey-70;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
&:focus,
|
|
143
|
+
&:hover {
|
|
144
|
+
outline: none;
|
|
145
|
+
background: $grey-15;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
package/addon/styles/addon.scss
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@1024pix/pix-ui/components/pix-dropdown';
|
|
@@ -33,6 +33,19 @@ export const form = (args) => {
|
|
|
33
33
|
/>
|
|
34
34
|
<br>
|
|
35
35
|
|
|
36
|
+
<PixDropdown
|
|
37
|
+
@id="form__searchable-pix-dropdown"
|
|
38
|
+
@options={{selectOptions}}
|
|
39
|
+
@placeholder="Choisir votre fruit"
|
|
40
|
+
@isSearchable={{true}}
|
|
41
|
+
@searchPlaceholder="Rechercher"
|
|
42
|
+
@label="Votre fruit préféré est : "
|
|
43
|
+
@clearLabel="Supprimer la sélection"
|
|
44
|
+
@expandLabel="Ouvrir la liste"
|
|
45
|
+
@collapseLabel="Réduire la liste"
|
|
46
|
+
/>
|
|
47
|
+
<br>
|
|
48
|
+
|
|
36
49
|
<PixTextarea
|
|
37
50
|
@id="form__pix-textarea"
|
|
38
51
|
@value=""
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { hbs } from 'ember-cli-htmlbars';
|
|
2
|
+
import { action } from '@storybook/addon-actions';
|
|
3
|
+
|
|
4
|
+
export const Template = (args) => {
|
|
5
|
+
return {
|
|
6
|
+
template: hbs`
|
|
7
|
+
<div style="width: 300px;">
|
|
8
|
+
<PixDropdown
|
|
9
|
+
@id={{id}}
|
|
10
|
+
@options={{options}}
|
|
11
|
+
@onSelect={{onSelect}}
|
|
12
|
+
@placeholder={{placeholder}}
|
|
13
|
+
@selectedOption={{selectedOption}}
|
|
14
|
+
@isSearchable={{isSearchable}}
|
|
15
|
+
@searchPlaceholder={{searchPlaceholder}}
|
|
16
|
+
@label={{label}}
|
|
17
|
+
@clearLabel={{clearLabel}}
|
|
18
|
+
@expandLabel={{expandLabel}}
|
|
19
|
+
@collapseLabel={{collapseLabel}}
|
|
20
|
+
@pageSize={{pageSize}}
|
|
21
|
+
/>
|
|
22
|
+
</div>
|
|
23
|
+
`,
|
|
24
|
+
context: args,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Default = Template.bind({});
|
|
29
|
+
Default.args = {
|
|
30
|
+
options: [
|
|
31
|
+
{ value: '1', label: 'Figues' },
|
|
32
|
+
{ value: '2', label: 'Bananes' },
|
|
33
|
+
{ value: '3', label: 'Noix' },
|
|
34
|
+
{ value: '4', label: 'Papayes' },
|
|
35
|
+
{ value: '5', label: 'Fèves de chocolat' },
|
|
36
|
+
{ value: '6', label: 'Dattes' },
|
|
37
|
+
{ value: '7', label: 'Mangues' },
|
|
38
|
+
{ value: '8', label: 'Jujube' },
|
|
39
|
+
{ value: '9', label: 'Avocat' },
|
|
40
|
+
{ value: '10', label: 'Fraises' },
|
|
41
|
+
{ value: '11', label: 'Kaki' },
|
|
42
|
+
{ value: '12', label: 'Asiminier trilobé oblong vert (à ne pas confondre avec la papaye)' },
|
|
43
|
+
],
|
|
44
|
+
placeholder: 'Choisissez une option',
|
|
45
|
+
onSelect: action('onSelect'),
|
|
46
|
+
id: 'default-dropdown',
|
|
47
|
+
clearLabel: 'Supprimer la sélection',
|
|
48
|
+
expandLabel: 'Ouvrir la liste',
|
|
49
|
+
collapseLabel: 'Réduire la liste',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const withLabel = Template.bind({});
|
|
53
|
+
withLabel.args = {
|
|
54
|
+
...Default.args,
|
|
55
|
+
id: 'dropdown-with-label',
|
|
56
|
+
label: 'Ton fruit préféré: ',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const searchableDropdown = Template.bind({});
|
|
60
|
+
searchableDropdown.args = {
|
|
61
|
+
...Default.args,
|
|
62
|
+
isSearchable: true,
|
|
63
|
+
id: 'searchable-dropdown',
|
|
64
|
+
placeholder: 'Fraises, Mangues...',
|
|
65
|
+
searchPlaceholder: 'Rechercher',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const paginatedDropdown = Template.bind({});
|
|
69
|
+
paginatedDropdown.args = {
|
|
70
|
+
...Default.args,
|
|
71
|
+
id: 'paginated-dropdown',
|
|
72
|
+
placeholder: 'Quel est ton fruit préféré ?',
|
|
73
|
+
pageSize: 10,
|
|
74
|
+
isSearchable: true,
|
|
75
|
+
searchPlaceholder: 'Rechercher',
|
|
76
|
+
options: Array.from({ length: 100 }, (_, index) => ({
|
|
77
|
+
value: `${index}`,
|
|
78
|
+
label: `${index}abc`,
|
|
79
|
+
})),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const argTypes = {
|
|
83
|
+
options: {
|
|
84
|
+
name: 'options',
|
|
85
|
+
description:
|
|
86
|
+
'Les options sont représentées par un tableau d‘objet contenant les propriétés ``value`` et ``label``.',
|
|
87
|
+
type: { name: 'array', required: true },
|
|
88
|
+
},
|
|
89
|
+
selectedOption: {
|
|
90
|
+
name: 'selectedOption',
|
|
91
|
+
description: 'Option sélectionnée',
|
|
92
|
+
options: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
|
|
93
|
+
control: { type: 'select' },
|
|
94
|
+
type: { name: 'string', required: false },
|
|
95
|
+
table: {
|
|
96
|
+
type: { summary: 'string' },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
onSelect: {
|
|
100
|
+
name: 'onSelect',
|
|
101
|
+
description: 'Fonction à appeler quand une option est sélectionnée.',
|
|
102
|
+
type: { required: true },
|
|
103
|
+
control: { disable: true },
|
|
104
|
+
},
|
|
105
|
+
isSearchable: {
|
|
106
|
+
name: 'isSearchable',
|
|
107
|
+
description:
|
|
108
|
+
"Rend le champ cherchable, le paramètre @searchPlaceholder devient requis pour l'accessibilité.",
|
|
109
|
+
control: { type: 'boolean' },
|
|
110
|
+
type: { name: 'boolean', required: false },
|
|
111
|
+
table: {
|
|
112
|
+
type: { summary: 'boolean' },
|
|
113
|
+
defaultValue: { summary: false },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
searchPlaceholder: {
|
|
117
|
+
name: 'searchPlaceholder',
|
|
118
|
+
description: 'Placeholder du champ de recherche. Requis si le menu est cherchable.',
|
|
119
|
+
type: { name: 'string', required: false },
|
|
120
|
+
table: {
|
|
121
|
+
type: { summary: 'string' },
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
placeholder: {
|
|
125
|
+
name: 'placeholder',
|
|
126
|
+
description: "Un texte donnant une indication a l'utilisateur sur le choix des options.",
|
|
127
|
+
type: { name: 'string', required: false },
|
|
128
|
+
table: {
|
|
129
|
+
type: { summary: 'string' },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
label: {
|
|
133
|
+
name: 'label',
|
|
134
|
+
description: 'Label du menu déroulant, le paramètre @id devient obligatoire avec ce paramètre.',
|
|
135
|
+
type: { name: 'string', required: false },
|
|
136
|
+
table: {
|
|
137
|
+
type: { summary: 'string' },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
id: {
|
|
141
|
+
name: 'id',
|
|
142
|
+
description: "L'id du label",
|
|
143
|
+
type: { name: 'string', required: false },
|
|
144
|
+
table: {
|
|
145
|
+
type: { summary: 'string' },
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
pageSize: {
|
|
149
|
+
name: 'pageSize',
|
|
150
|
+
description: "Le nombre d'élément à afficher dans la liste.",
|
|
151
|
+
type: { name: 'number', required: false },
|
|
152
|
+
table: {
|
|
153
|
+
type: { summary: 'number' },
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
clearLabel: {
|
|
157
|
+
name: 'clearLabel',
|
|
158
|
+
description: "Label de l'icône pour éliminer la sélection. Requis pour l'accessibilité.",
|
|
159
|
+
type: { name: 'string', required: false },
|
|
160
|
+
table: {
|
|
161
|
+
type: { summary: 'string' },
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
expandLabel: {
|
|
165
|
+
name: 'expandLabel',
|
|
166
|
+
description: "Label de l'icône pour ouvrir le menu déroulant. Requis pour l'accessibilité.",
|
|
167
|
+
type: { name: 'string', required: false },
|
|
168
|
+
table: {
|
|
169
|
+
type: { summary: 'string' },
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
collapseLabel: {
|
|
173
|
+
name: 'collapseLabel',
|
|
174
|
+
description: "Label de l'icône pour réduire le menu déroulant. Requis pour l'accessibilité.",
|
|
175
|
+
type: { name: 'string', required: false },
|
|
176
|
+
table: {
|
|
177
|
+
type: { summary: 'string' },
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import centered from '@storybook/addon-centered/ember';
|
|
3
|
+
|
|
4
|
+
import * as stories from './pix-dropdown.stories.js';
|
|
5
|
+
|
|
6
|
+
<Meta
|
|
7
|
+
title='Form/Dropdown'
|
|
8
|
+
component='PixDropdown'
|
|
9
|
+
argTypes={stories.argTypes}
|
|
10
|
+
/>
|
|
11
|
+
|
|
12
|
+
# Pix Dropdown
|
|
13
|
+
|
|
14
|
+
Affiche un menu déroulant avec la liste des options fournies.
|
|
15
|
+
|
|
16
|
+
Les options sont représentées par un tableau d'objet contenant les propriétés value et label.
|
|
17
|
+
|
|
18
|
+
> **⚠️** __Il est nécessaire d'avoir au moins un label ou un placeholder !__
|
|
19
|
+
|
|
20
|
+
> **⚠️** __N'oubliez pas de rajouter un searchLabel dans le cas ou le menu déroulant est cherchable pour le rendre accessible !__
|
|
21
|
+
|
|
22
|
+
> Pour aider l'utilisateur, rajoutez un placeholder cohérent !
|
|
23
|
+
|
|
24
|
+
## Default
|
|
25
|
+
|
|
26
|
+
<Canvas>
|
|
27
|
+
<Story name='Dropdown' story={stories.Default} height={200} />
|
|
28
|
+
</Canvas>
|
|
29
|
+
|
|
30
|
+
## With label
|
|
31
|
+
|
|
32
|
+
<Canvas>
|
|
33
|
+
<Story story={stories.withLabel} height={200} />
|
|
34
|
+
</Canvas>
|
|
35
|
+
|
|
36
|
+
## Searchable
|
|
37
|
+
|
|
38
|
+
<Canvas>
|
|
39
|
+
<Story name="Searchable" story={stories.searchableDropdown} height={200} />
|
|
40
|
+
</Canvas>
|
|
41
|
+
|
|
42
|
+
## Infinite scroll
|
|
43
|
+
|
|
44
|
+
<Canvas>
|
|
45
|
+
<Story name="Paginated" story={stories.paginatedDropdown} height={200} />
|
|
46
|
+
</Canvas>
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<PixDropdown
|
|
52
|
+
@id={{id}}
|
|
53
|
+
@options={{options}}
|
|
54
|
+
@onSelect={{onSelect}}
|
|
55
|
+
@selectedOption="1"
|
|
56
|
+
@isSearchable={{false}}
|
|
57
|
+
@placeholder="Choisissez une option"
|
|
58
|
+
@searchPlaceholder="Rechercher"
|
|
59
|
+
@label="Mon menu déroulant"
|
|
60
|
+
@clearLabel="Supprimer la sélection"
|
|
61
|
+
@expandLabel="Ouvrir le menu déroulant"
|
|
62
|
+
@collapseLabel="Réduire le menu déroulant"
|
|
63
|
+
@pageSize={{10}}
|
|
64
|
+
/>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Arguments
|
|
68
|
+
|
|
69
|
+
<ArgsTable story="Dropdown" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1024pix/pix-ui",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"description": "Pix-UI is the implementation of Pix design principles and guidelines for its products.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -50,8 +50,9 @@
|
|
|
50
50
|
"ember-truth-helpers": "^3.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"@1024pix/ember-testing-library": "^0.5.0",
|
|
53
54
|
"@ember/optional-features": "^2.0.0",
|
|
54
|
-
"@ember/test-helpers": "^2.
|
|
55
|
+
"@ember/test-helpers": "^2.6.0",
|
|
55
56
|
"@fortawesome/ember-fontawesome": "^0.2.3",
|
|
56
57
|
"@fortawesome/free-regular-svg-icons": "^5.15.4",
|
|
57
58
|
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|