@1024pix/pix-ui 46.4.2 → 46.5.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/addon/components/pix-filterable-and-searchable-select.hbs +0 -1
- package/addon/components/pix-filterable-and-searchable-select.js +28 -22
- package/addon/components/pix-pagination.hbs +1 -1
- package/addon/components/pix-pagination.js +0 -9
- package/addon/components/pix-select.hbs +0 -2
- package/addon/components/pix-select.js +24 -34
- package/addon/styles/_pix-toggle.scss +12 -4
- package/app/services/element-helper.js +32 -0
- package/app/stories/pix-toggle.stories.js +7 -7
- package/package.json +2 -3
- package/addon/common/add-dynamic-style-tag.js +0 -8
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
+
import { inject as service } from '@ember/service';
|
|
2
3
|
import { tracked } from '@glimmer/tracking';
|
|
3
4
|
import { action } from '@ember/object';
|
|
4
5
|
import { guidFor } from '@ember/object/internals';
|
|
5
|
-
import { createClass } from '../common/add-dynamic-style-tag';
|
|
6
6
|
|
|
7
7
|
export default class PixFilterableAndSearchableSelect extends Component {
|
|
8
|
+
@service elementHelper;
|
|
8
9
|
@tracked selectedCategories = [];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
constructor(...args) {
|
|
12
|
+
super(...args);
|
|
13
|
+
this.mainId = 'pix-pfass-' + guidFor(this);
|
|
14
|
+
this.pixSelectId = 'pix-pfass-select-' + guidFor(this);
|
|
15
|
+
this.pixMultiSelectId = 'pix-pfass-multi-select-' + guidFor(this);
|
|
16
|
+
|
|
17
|
+
this.elementHelper.waitForElement(this.pixSelectId).then(() => {
|
|
18
|
+
const baseFontRemRatio = Number(
|
|
19
|
+
getComputedStyle(document.querySelector('html')).fontSize.match(/\d+(\.\d+)?/)[0],
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const multiSelectWidth = document
|
|
23
|
+
.getElementById(this.pixMultiSelectId)
|
|
24
|
+
.getBoundingClientRect().width;
|
|
25
|
+
|
|
26
|
+
const selectWidth = Math.ceil(multiSelectWidth / baseFontRemRatio);
|
|
27
|
+
|
|
28
|
+
const className = `sizing-select-${this.pixSelectId}`;
|
|
29
|
+
this.elementHelper.createClass(`.${className}`, `width: calc(100% - ${selectWidth}rem);`);
|
|
30
|
+
|
|
31
|
+
const element = document.getElementById(`container-${this.pixSelectId}`);
|
|
32
|
+
|
|
33
|
+
element.className = element.className + ' ' + className;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
12
36
|
|
|
13
37
|
@action
|
|
14
38
|
selectCategories(categories) {
|
|
@@ -47,22 +71,4 @@ export default class PixFilterableAndSearchableSelect extends Component {
|
|
|
47
71
|
|
|
48
72
|
return selectableOptions;
|
|
49
73
|
}
|
|
50
|
-
|
|
51
|
-
@action
|
|
52
|
-
setSelectWidth(element) {
|
|
53
|
-
const baseFontRemRatio = Number(
|
|
54
|
-
getComputedStyle(document.querySelector('html')).fontSize.match(/\d+(\.\d+)?/)[0],
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const multiSelectWidth = document
|
|
58
|
-
.getElementById(this.pixMultiSelectId)
|
|
59
|
-
.getBoundingClientRect().width;
|
|
60
|
-
|
|
61
|
-
const selectWidth = Math.ceil(multiSelectWidth / baseFontRemRatio);
|
|
62
|
-
|
|
63
|
-
const className = `sizing-select-${this.pixSelectId}`;
|
|
64
|
-
createClass(`.${className}`, `width: calc(100% - ${selectWidth}rem);`);
|
|
65
|
-
|
|
66
|
-
element.className = element.className + ' ' + className;
|
|
67
|
-
}
|
|
68
74
|
}
|
|
@@ -118,13 +118,4 @@ export default class PixPagination extends Component {
|
|
|
118
118
|
goToPreviousPage() {
|
|
119
119
|
this.router.replaceWith({ queryParams: { pageNumber: this.previousPage } });
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
@action
|
|
123
|
-
checkCurrentPageAgainstPageCount() {
|
|
124
|
-
const pageCount = this.args.pagination.pageCount;
|
|
125
|
-
if (pageCount === 0) return;
|
|
126
|
-
if (this.currentPage > pageCount) {
|
|
127
|
-
this.router.replaceWith({ queryParams: { pageNumber: pageCount } });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
121
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
{{on-click-outside this.hideDropdown}}
|
|
5
5
|
{{on-arrow-down-up-action this.listId this.showDropdown this.isExpanded}}
|
|
6
6
|
{{on-escape-action this.hideDropdown this.selectId}}
|
|
7
|
-
{{did-insert this.setSelectWidth}}
|
|
8
7
|
{{on "keydown" this.lockTab}}
|
|
9
8
|
...attributes
|
|
10
9
|
>
|
|
@@ -47,7 +46,6 @@
|
|
|
47
46
|
<div
|
|
48
47
|
{{popover}}
|
|
49
48
|
class="pix-select__dropdown{{unless this.isExpanded ' pix-select__dropdown--closed'}}"
|
|
50
|
-
id={{this.dropDownId}}
|
|
51
49
|
{{on "transitionend" this.focus}}
|
|
52
50
|
>
|
|
53
51
|
{{#if @isSearchable}}
|
|
@@ -1,30 +1,47 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
2
|
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { inject as service } from '@ember/service';
|
|
3
4
|
import { action } from '@ember/object';
|
|
4
5
|
import { guidFor } from '@ember/object/internals';
|
|
5
|
-
import { createClass } from '../common/add-dynamic-style-tag';
|
|
6
6
|
|
|
7
7
|
export default class PixSelect extends Component {
|
|
8
|
+
@service elementHelper;
|
|
8
9
|
@tracked isExpanded = false;
|
|
9
10
|
@tracked searchValue = null;
|
|
10
|
-
searchId = 'search-input-' + guidFor(this);
|
|
11
11
|
|
|
12
12
|
constructor(...args) {
|
|
13
13
|
super(...args);
|
|
14
14
|
|
|
15
15
|
const categories = [];
|
|
16
|
+
|
|
17
|
+
this.searchId = 'search-input-' + guidFor(this);
|
|
18
|
+
this.selectId = this.args.id ? this.args.id : 'select-' + guidFor(this);
|
|
19
|
+
this.listId = `listbox-${this.selectId}`;
|
|
20
|
+
|
|
16
21
|
this.args.options.forEach((element) => {
|
|
17
22
|
if (!categories.includes(element.category) && element.category !== undefined) {
|
|
18
23
|
categories.push(element.category);
|
|
19
24
|
}
|
|
20
25
|
});
|
|
21
|
-
|
|
22
26
|
this.displayCategory = categories.length > 0;
|
|
23
|
-
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
if (!this.args.isComputeWidthDisabled) {
|
|
29
|
+
this.elementHelper.waitForElement(this.selectId).then((elementList) => {
|
|
30
|
+
const baseFontRemRatio = Number(
|
|
31
|
+
getComputedStyle(document.querySelector('html')).fontSize.match(/\d+(\.\d+)?/)[0],
|
|
32
|
+
);
|
|
33
|
+
const checkIconWidth = 1.125 * baseFontRemRatio;
|
|
34
|
+
const listWidth = elementList.getBoundingClientRect().width;
|
|
35
|
+
const selectWidth = (listWidth + checkIconWidth) / baseFontRemRatio;
|
|
36
|
+
|
|
37
|
+
const className = `sizing-select-${this.selectId}`;
|
|
38
|
+
this.elementHelper.createClass(`.${className}`, `width: ${selectWidth}rem;`);
|
|
39
|
+
|
|
40
|
+
const element = document.getElementById(`container-${this.selectId}`);
|
|
41
|
+
|
|
42
|
+
element.className = element.className + ' ' + className;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
get displayDefaultOption() {
|
|
@@ -51,14 +68,6 @@ export default class PixSelect extends Component {
|
|
|
51
68
|
return this.isExpanded ? 'true' : 'false';
|
|
52
69
|
}
|
|
53
70
|
|
|
54
|
-
get listId() {
|
|
55
|
-
return `listbox-${this.selectId}`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get dropDownId() {
|
|
59
|
-
return `dropdown-${this.selectId}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
71
|
get placeholder() {
|
|
63
72
|
if (!this.args.value) return this.args.placeholder;
|
|
64
73
|
const option = this.args.options.find((option) => option.value === this.args.value);
|
|
@@ -155,23 +164,4 @@ export default class PixSelect extends Component {
|
|
|
155
164
|
}
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
|
-
|
|
159
|
-
@action
|
|
160
|
-
setSelectWidth() {
|
|
161
|
-
if (!this.args.isComputeWidthDisabled) {
|
|
162
|
-
const baseFontRemRatio = Number(
|
|
163
|
-
getComputedStyle(document.querySelector('html')).fontSize.match(/\d+(\.\d+)?/)[0],
|
|
164
|
-
);
|
|
165
|
-
const checkIconWidth = 1.125 * baseFontRemRatio;
|
|
166
|
-
const listWidth = document.getElementById(this.listId).getBoundingClientRect().width;
|
|
167
|
-
const selectWidth = (listWidth + checkIconWidth) / baseFontRemRatio;
|
|
168
|
-
|
|
169
|
-
const className = `sizing-select-${this.selectId}`;
|
|
170
|
-
createClass(`.${className}`, `width: ${selectWidth}rem;`);
|
|
171
|
-
|
|
172
|
-
const element = document.getElementById(`container-${this.selectId}`);
|
|
173
|
-
|
|
174
|
-
element.className = element.className + ' ' + className;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
167
|
}
|
|
@@ -10,9 +10,13 @@
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
&__button {
|
|
13
|
+
@extend %pix-body-s;
|
|
14
|
+
|
|
13
15
|
width: fit-content;
|
|
14
16
|
padding: var(--pix-spacing-1x);
|
|
15
|
-
|
|
17
|
+
font-weight: var(--pix-font-bold);
|
|
18
|
+
line-height: 1.572;
|
|
19
|
+
background: var(--pix-neutral-20);
|
|
16
20
|
border: 1px solid var(--pix-neutral-500);
|
|
17
21
|
border-radius: 4px;
|
|
18
22
|
}
|
|
@@ -20,11 +24,13 @@
|
|
|
20
24
|
&__on,
|
|
21
25
|
&__off {
|
|
22
26
|
display: inline-block;
|
|
23
|
-
padding: var(--pix-spacing-2x);
|
|
24
|
-
color: var(--pix-neutral-800);
|
|
27
|
+
padding: var(--pix-spacing-1x) var(--pix-spacing-2x);
|
|
25
28
|
border-radius: 4px;
|
|
29
|
+
}
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
&__on {
|
|
32
|
+
color: var(--pix-neutral-800);
|
|
33
|
+
font-weight: var(--pix-font-normal);
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
&__off {
|
|
@@ -36,11 +42,13 @@
|
|
|
36
42
|
.pix-toggle {
|
|
37
43
|
&__on {
|
|
38
44
|
color: var(--pix-neutral-20);
|
|
45
|
+
font-weight: inherit;
|
|
39
46
|
background-color: var(--pix-neutral-800);
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
&__off {
|
|
43
50
|
color: inherit;
|
|
51
|
+
font-weight: var(--pix-font-normal);
|
|
44
52
|
background-color: transparent;
|
|
45
53
|
}
|
|
46
54
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Service from '@ember/service';
|
|
2
|
+
|
|
3
|
+
export default class ElementService extends Service {
|
|
4
|
+
waitForElement(id) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
if (document.getElementById(id)) {
|
|
7
|
+
return resolve(document.getElementById(id));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const observer = new MutationObserver(() => {
|
|
11
|
+
if (document.getElementById(id)) {
|
|
12
|
+
resolve(document.getElementById(id));
|
|
13
|
+
observer.disconnect();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
observer.observe(document.body, {
|
|
18
|
+
childList: true,
|
|
19
|
+
subtree: true,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
createClass(name, rules) {
|
|
25
|
+
var style = document.createElement('style');
|
|
26
|
+
style.type = 'text/css';
|
|
27
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
28
|
+
|
|
29
|
+
if (!(style.sheet || {}).insertRule) (style.styleSheet || style.sheet).addRule(name, rules);
|
|
30
|
+
else style.sheet.insertRule(name + '{' + rules + '}', 0);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -2,7 +2,7 @@ import { hbs } from 'ember-cli-htmlbars';
|
|
|
2
2
|
import { action } from '@storybook/addon-actions';
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
|
-
title: '
|
|
5
|
+
title: 'Basics/Toggle',
|
|
6
6
|
argTypes: {
|
|
7
7
|
label: {
|
|
8
8
|
name: 'label',
|
|
@@ -100,8 +100,8 @@ const TemplateWithYields = (args) => {
|
|
|
100
100
|
export const Default = Template.bind({});
|
|
101
101
|
Default.args = {
|
|
102
102
|
label: 'Mon toggle',
|
|
103
|
-
onLabel: '
|
|
104
|
-
offLabel: '
|
|
103
|
+
onLabel: 'Option A',
|
|
104
|
+
offLabel: 'Option B',
|
|
105
105
|
toggled: false,
|
|
106
106
|
onChange: action('onChange'),
|
|
107
107
|
};
|
|
@@ -110,8 +110,8 @@ export const Inline = Template.bind({});
|
|
|
110
110
|
Inline.args = {
|
|
111
111
|
inline: true,
|
|
112
112
|
label: 'Mon toggle',
|
|
113
|
-
onLabel: '
|
|
114
|
-
offLabel: '
|
|
113
|
+
onLabel: 'Option A',
|
|
114
|
+
offLabel: 'Option B',
|
|
115
115
|
toggled: false,
|
|
116
116
|
onChange: action('onChange'),
|
|
117
117
|
};
|
|
@@ -120,8 +120,8 @@ export const ScreenReaderOnly = Template.bind({});
|
|
|
120
120
|
ScreenReaderOnly.args = {
|
|
121
121
|
screenReaderOnly: true,
|
|
122
122
|
label: 'Mon toggle',
|
|
123
|
-
onLabel: '
|
|
124
|
-
offLabel: '
|
|
123
|
+
onLabel: 'Option A',
|
|
124
|
+
offLabel: 'Option B',
|
|
125
125
|
toggled: false,
|
|
126
126
|
onChange: action('onChange'),
|
|
127
127
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1024pix/pix-ui",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.5.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"
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"@babel/eslint-parser": "^7.19.1",
|
|
65
65
|
"@babel/plugin-proposal-decorators": "^7.20.5",
|
|
66
66
|
"@ember/optional-features": "^2.0.0",
|
|
67
|
-
"@ember/render-modifiers": "^2.0.5",
|
|
68
67
|
"@ember/string": "^3.0.1",
|
|
69
68
|
"@ember/test-helpers": "^3.0.0",
|
|
70
69
|
"@embroider/macros": "^1.11.0",
|
|
@@ -106,7 +105,7 @@
|
|
|
106
105
|
"ember-sinon": "^5.0.0",
|
|
107
106
|
"ember-source": "^4.0.1",
|
|
108
107
|
"ember-source-channel-url": "^3.0.0",
|
|
109
|
-
"ember-template-lint": "^
|
|
108
|
+
"ember-template-lint": "^6.0.0",
|
|
110
109
|
"ember-template-lint-plugin-prettier": "^5.0.0",
|
|
111
110
|
"ember-try": "^3.0.0-beta",
|
|
112
111
|
"eslint": "^8.28.0",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export function createClass(name, rules) {
|
|
2
|
-
var style = document.createElement('style');
|
|
3
|
-
style.type = 'text/css';
|
|
4
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
5
|
-
|
|
6
|
-
if (!(style.sheet || {}).insertRule) (style.styleSheet || style.sheet).addRule(name, rules);
|
|
7
|
-
else style.sheet.insertRule(name + '{' + rules + '}', 0);
|
|
8
|
-
}
|