@primer/view-components 0.0.94 → 0.0.95
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/app/assets/javascripts/primer_view_components.js +1 -1
- package/app/assets/javascripts/primer_view_components.js.map +1 -1
- package/app/components/primer/alpha/toggle_switch.js +3 -0
- package/app/components/primer/alpha/tool_tip.js +17 -2
- package/app/components/primer/experimental/action_bar.d.ts +14 -0
- package/app/components/primer/experimental/action_bar.js +141 -0
- package/package.json +6 -7
- package/static/arguments.json +2042 -0
- package/static/audited_at.json +84 -0
- package/static/constants.json +978 -0
- package/static/statuses.json +84 -0
|
@@ -102,6 +102,9 @@ let ToggleSwitchElement = class ToggleSwitchElement extends HTMLElement {
|
|
|
102
102
|
const response = await fetch(this.src, {
|
|
103
103
|
credentials: 'same-origin',
|
|
104
104
|
method: 'POST',
|
|
105
|
+
headers: {
|
|
106
|
+
'Requested-With': 'XMLHttpRequest'
|
|
107
|
+
},
|
|
105
108
|
body
|
|
106
109
|
});
|
|
107
110
|
if (response.ok) {
|
|
@@ -247,7 +247,12 @@ class ToolTipElement extends HTMLElement {
|
|
|
247
247
|
if (this.type === 'label') {
|
|
248
248
|
let labelledBy = this.control.getAttribute('aria-labelledby');
|
|
249
249
|
if (labelledBy) {
|
|
250
|
-
|
|
250
|
+
if (!labelledBy.split(' ').includes(this.id)) {
|
|
251
|
+
labelledBy = `${labelledBy} ${this.id}`;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
labelledBy = `${labelledBy}`;
|
|
255
|
+
}
|
|
251
256
|
}
|
|
252
257
|
else {
|
|
253
258
|
labelledBy = this.id;
|
|
@@ -258,7 +263,17 @@ class ToolTipElement extends HTMLElement {
|
|
|
258
263
|
}
|
|
259
264
|
else {
|
|
260
265
|
let describedBy = this.control.getAttribute('aria-describedby');
|
|
261
|
-
|
|
266
|
+
if (describedBy) {
|
|
267
|
+
if (!describedBy.split(' ').includes(this.id)) {
|
|
268
|
+
describedBy = `${describedBy} ${this.id}`;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
describedBy = `${describedBy}`;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
describedBy = this.id;
|
|
276
|
+
}
|
|
262
277
|
this.control.setAttribute('aria-describedby', describedBy);
|
|
263
278
|
}
|
|
264
279
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class ActionBarElement extends HTMLElement {
|
|
2
|
+
#private;
|
|
3
|
+
items: HTMLElement[];
|
|
4
|
+
menuItems: HTMLElement[];
|
|
5
|
+
itemContainer: HTMLElement;
|
|
6
|
+
moreMenu: HTMLElement;
|
|
7
|
+
connectedCallback(): void;
|
|
8
|
+
disconnectedCallback(): void;
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
ActionBarElement: typeof ActionBarElement;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
15
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
16
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
17
|
+
};
|
|
18
|
+
var _ActionBarElement_instances, _ActionBarElement_observer, _ActionBarElement_initialBarWidth, _ActionBarElement_previousBarWidth, _ActionBarElement_itemGap, _ActionBarElement_focusController, _ActionBarElement_focusSettings, _ActionBarElement_availableSpace, _ActionBarElement_shrinking, _ActionBarElement_growing;
|
|
19
|
+
import { controller, targets, target } from '@github/catalyst';
|
|
20
|
+
import { focusZone, FocusKeys } from '@primer/behaviors';
|
|
21
|
+
let ActionBarElement = class ActionBarElement extends HTMLElement {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
_ActionBarElement_instances.add(this);
|
|
25
|
+
_ActionBarElement_observer.set(this, void 0);
|
|
26
|
+
_ActionBarElement_initialBarWidth.set(this, void 0);
|
|
27
|
+
_ActionBarElement_previousBarWidth.set(this, void 0);
|
|
28
|
+
_ActionBarElement_itemGap.set(this, void 0);
|
|
29
|
+
_ActionBarElement_focusController.set(this, void 0);
|
|
30
|
+
_ActionBarElement_focusSettings.set(this, {
|
|
31
|
+
bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
connectedCallback() {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
__classPrivateFieldSet(this, _ActionBarElement_initialBarWidth, this.offsetWidth, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _ActionBarElement_previousBarWidth, this.offsetWidth, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _ActionBarElement_itemGap, parseInt((_a = window.getComputedStyle(this.itemContainer)) === null || _a === void 0 ? void 0 : _a.columnGap, 10) || 0, "f");
|
|
39
|
+
// Calculate the width of all the items before hiding anything
|
|
40
|
+
for (const item of this.items) {
|
|
41
|
+
const width = item.getBoundingClientRect().width;
|
|
42
|
+
const marginLeft = parseInt((_b = window.getComputedStyle(item)) === null || _b === void 0 ? void 0 : _b.marginLeft, 10);
|
|
43
|
+
const marginRight = parseInt((_c = window.getComputedStyle(item)) === null || _c === void 0 ? void 0 : _c.marginRight, 10);
|
|
44
|
+
item.setAttribute('data-offset-width', `${width + marginLeft + marginRight}`);
|
|
45
|
+
}
|
|
46
|
+
__classPrivateFieldSet(this, _ActionBarElement_focusController, focusZone(this, __classPrivateFieldGet(this, _ActionBarElement_focusSettings, "f")), "f");
|
|
47
|
+
this.style.maxWidth = `${this.itemContainer.offsetWidth}px`;
|
|
48
|
+
// Calculate visible items on page load until there is enough space
|
|
49
|
+
// to show all items or the first item is hidden
|
|
50
|
+
while (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) < this.moreMenu.offsetWidth + __classPrivateFieldGet(this, _ActionBarElement_itemGap, "f") * 0.5 && !this.items[0].hidden) {
|
|
51
|
+
__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_shrinking).call(this);
|
|
52
|
+
}
|
|
53
|
+
this.style.overflow = 'visible';
|
|
54
|
+
__classPrivateFieldSet(this, _ActionBarElement_observer, new ResizeObserver(entries => {
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
// Only recalculate if the bar width changed
|
|
57
|
+
if (__classPrivateFieldGet(this, _ActionBarElement_initialBarWidth, "f") !== entry.contentRect.width) {
|
|
58
|
+
if (entry.contentRect.width < __classPrivateFieldGet(this, _ActionBarElement_previousBarWidth, "f")) {
|
|
59
|
+
__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_shrinking).call(this);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_growing).call(this);
|
|
63
|
+
}
|
|
64
|
+
__classPrivateFieldSet(this, _ActionBarElement_previousBarWidth, entry.contentRect.width, "f");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}), "f");
|
|
68
|
+
__classPrivateFieldGet(this, _ActionBarElement_observer, "f").observe(this);
|
|
69
|
+
}
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = __classPrivateFieldGet(this, _ActionBarElement_focusController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
73
|
+
__classPrivateFieldGet(this, _ActionBarElement_observer, "f").unobserve(this);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
_ActionBarElement_observer = new WeakMap(), _ActionBarElement_initialBarWidth = new WeakMap(), _ActionBarElement_previousBarWidth = new WeakMap(), _ActionBarElement_itemGap = new WeakMap(), _ActionBarElement_focusController = new WeakMap(), _ActionBarElement_focusSettings = new WeakMap(), _ActionBarElement_instances = new WeakSet(), _ActionBarElement_availableSpace = function _ActionBarElement_availableSpace() {
|
|
77
|
+
// Get the offset of the item container from the container edge
|
|
78
|
+
return this.offsetWidth - this.itemContainer.offsetWidth;
|
|
79
|
+
}, _ActionBarElement_shrinking = function _ActionBarElement_shrinking() {
|
|
80
|
+
var _a;
|
|
81
|
+
if (this.items[0].hidden) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const gapSpace = __classPrivateFieldGet(this, _ActionBarElement_itemGap, "f") * 0.5;
|
|
85
|
+
if (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) < this.moreMenu.offsetWidth + gapSpace) {
|
|
86
|
+
const visibleItems = this.items.filter(item => !item.hidden);
|
|
87
|
+
const hiddenMenuItems = this.menuItems.filter(item => item.hidden);
|
|
88
|
+
visibleItems[visibleItems.length - 1].hidden = true;
|
|
89
|
+
hiddenMenuItems[hiddenMenuItems.length - 1].hidden = false;
|
|
90
|
+
if (this.moreMenu.hidden) {
|
|
91
|
+
this.moreMenu.hidden = false;
|
|
92
|
+
}
|
|
93
|
+
// Reset focus controller
|
|
94
|
+
(_a = __classPrivateFieldGet(this, _ActionBarElement_focusController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
95
|
+
__classPrivateFieldSet(this, _ActionBarElement_focusController, focusZone(this, __classPrivateFieldGet(this, _ActionBarElement_focusSettings, "f")), "f");
|
|
96
|
+
}
|
|
97
|
+
}, _ActionBarElement_growing = function _ActionBarElement_growing() {
|
|
98
|
+
var _a;
|
|
99
|
+
if (this.moreMenu.hidden) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const gapSpace = __classPrivateFieldGet(this, _ActionBarElement_itemGap, "f") * 0.5;
|
|
103
|
+
const hiddenItems = this.items.filter(item => item.hidden);
|
|
104
|
+
if (hiddenItems.length === 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const hiddenItemWidth = Number(hiddenItems[0].getAttribute('data-offset-width'));
|
|
108
|
+
if (__classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_availableSpace).call(this) >= this.moreMenu.offsetWidth + hiddenItemWidth + gapSpace) {
|
|
109
|
+
const visibleMenuItems = this.menuItems.filter(item => !item.hidden);
|
|
110
|
+
hiddenItems[0].hidden = false;
|
|
111
|
+
visibleMenuItems[0].hidden = true;
|
|
112
|
+
if (hiddenItems.length === 2) {
|
|
113
|
+
hiddenItems[1].hidden = false;
|
|
114
|
+
visibleMenuItems[1].hidden = true;
|
|
115
|
+
}
|
|
116
|
+
// If there was only one item left, hide the more menu
|
|
117
|
+
if (hiddenItems.length <= 2) {
|
|
118
|
+
this.moreMenu.hidden = true;
|
|
119
|
+
}
|
|
120
|
+
// Reset focus controller
|
|
121
|
+
(_a = __classPrivateFieldGet(this, _ActionBarElement_focusController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
122
|
+
__classPrivateFieldSet(this, _ActionBarElement_focusController, focusZone(this, __classPrivateFieldGet(this, _ActionBarElement_focusSettings, "f")), "f");
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
__decorate([
|
|
126
|
+
targets
|
|
127
|
+
], ActionBarElement.prototype, "items", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
targets
|
|
130
|
+
], ActionBarElement.prototype, "menuItems", void 0);
|
|
131
|
+
__decorate([
|
|
132
|
+
target
|
|
133
|
+
], ActionBarElement.prototype, "itemContainer", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
target
|
|
136
|
+
], ActionBarElement.prototype, "moreMenu", void 0);
|
|
137
|
+
ActionBarElement = __decorate([
|
|
138
|
+
controller
|
|
139
|
+
], ActionBarElement);
|
|
140
|
+
export { ActionBarElement };
|
|
141
|
+
window.ActionBarElement = ActionBarElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/view-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.95",
|
|
4
4
|
"description": "ViewComponents for the Primer Design System",
|
|
5
5
|
"main": "app/assets/javascripts/primer_view_components.js",
|
|
6
6
|
"module": "app/components/primer/primer.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"url": "https://github.com/primer/view_components/issues"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
+
"static/*.json",
|
|
23
24
|
"app/assets/**/*",
|
|
24
25
|
"app/components/primer/**/*.js",
|
|
25
26
|
"app/components/primer/**/*.css",
|
|
@@ -30,8 +31,8 @@
|
|
|
30
31
|
"build:docs": "cd docs && yarn gatsby build --prefix-paths",
|
|
31
32
|
"build:docs:preview": "cd docs && yarn gatsby build",
|
|
32
33
|
"prepare": "rm -rf docs/static && mkdir -p docs/static && yarn build:js && yarn build:css && cp app/assets/**/primer_view_components.* docs/static/",
|
|
33
|
-
"lint": "eslint 'app/components/**/*.ts'
|
|
34
|
-
"lint:fix": "eslint 'app/components/**/*.ts'
|
|
34
|
+
"lint": "eslint 'app/components/**/*.ts'",
|
|
35
|
+
"lint:fix": "eslint 'app/components/**/*.ts' --fix",
|
|
35
36
|
"changeset:version": "changeset version && script/version",
|
|
36
37
|
"build:js": "tsc && rollup -c",
|
|
37
38
|
"build:css": "postcss -o app/assets/styles/primer_view_components.css app/components/primer/primer.pcss"
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
"@rollup/plugin-typescript": "^8.3.3",
|
|
58
59
|
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
59
60
|
"@typescript-eslint/parser": "^5.31.0",
|
|
61
|
+
"chokidar-cli": "^3.0.0",
|
|
60
62
|
"cssnano": "^5.1.13",
|
|
61
63
|
"eslint": "^8.20.0",
|
|
62
64
|
"eslint-plugin-custom-elements": "^0.0.6",
|
|
@@ -75,8 +77,5 @@
|
|
|
75
77
|
"tslib": "^2.4.0",
|
|
76
78
|
"typescript": "^4.7.4"
|
|
77
79
|
},
|
|
78
|
-
"prettier": "@github/prettier-config"
|
|
79
|
-
"storybook": {
|
|
80
|
-
"url": "https://primer.style/view-components/stories/"
|
|
81
|
-
}
|
|
80
|
+
"prettier": "@github/prettier-config"
|
|
82
81
|
}
|