@primer/view-components 0.30.0-rc.04c5c9c9 → 0.30.0-rc.1d16e534

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ declare class ToggleSwitchElement extends HTMLElement {
2
2
  switch: HTMLElement;
3
3
  loadingSpinner: HTMLElement;
4
4
  errorIcon: HTMLElement;
5
+ turbo: boolean;
5
6
  private toggling;
6
7
  get src(): string | null;
7
8
  get csrf(): string | null;
@@ -25,6 +26,9 @@ declare class ToggleSwitchElement extends HTMLElement {
25
26
  declare global {
26
27
  interface Window {
27
28
  ToggleSwitchElement: typeof ToggleSwitchElement;
29
+ Turbo: {
30
+ renderStreamMessage: (message: string) => void;
31
+ };
28
32
  }
29
33
  }
30
34
  export {};
@@ -4,10 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { controller, target } from '@github/catalyst';
7
+ import { controller, target, attr } from '@github/catalyst';
8
8
  let ToggleSwitchElement = class ToggleSwitchElement extends HTMLElement {
9
9
  constructor() {
10
10
  super(...arguments);
11
+ this.turbo = false;
11
12
  this.toggling = false;
12
13
  }
13
14
  get src() {
@@ -129,13 +130,17 @@ let ToggleSwitchElement = class ToggleSwitchElement extends HTMLElement {
129
130
  if (!this.src)
130
131
  throw new Error('invalid src');
131
132
  let response;
133
+ const requestHeaders = {
134
+ 'Requested-With': 'XMLHttpRequest',
135
+ };
136
+ if (this.turbo) {
137
+ requestHeaders['Accept'] = 'text/vnd.turbo-stream.html';
138
+ }
132
139
  try {
133
140
  response = await fetch(this.src, {
134
141
  credentials: 'same-origin',
135
142
  method: 'POST',
136
- headers: {
137
- 'Requested-With': 'XMLHttpRequest',
138
- },
143
+ headers: requestHeaders,
139
144
  body,
140
145
  });
141
146
  }
@@ -145,6 +150,10 @@ let ToggleSwitchElement = class ToggleSwitchElement extends HTMLElement {
145
150
  if (!response.ok) {
146
151
  throw new Error(await response.text());
147
152
  }
153
+ const contentType = response.headers.get('Content-Type');
154
+ if (window.Turbo && this.turbo && contentType?.startsWith('text/vnd.turbo-stream.html')) {
155
+ window.Turbo.renderStreamMessage(await response.text());
156
+ }
148
157
  }
149
158
  };
150
159
  __decorate([
@@ -156,6 +165,9 @@ __decorate([
156
165
  __decorate([
157
166
  target
158
167
  ], ToggleSwitchElement.prototype, "errorIcon", void 0);
168
+ __decorate([
169
+ attr
170
+ ], ToggleSwitchElement.prototype, "turbo", void 0);
159
171
  ToggleSwitchElement = __decorate([
160
172
  controller
161
173
  ], ToggleSwitchElement);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.30.0-rc.04c5c9c9",
3
+ "version": "0.30.0-rc.1d16e534",
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",
@@ -2986,6 +2986,12 @@
2986
2986
  "default": "`:start`",
2987
2987
  "description": "Which side of the toggle switch to render the status label. One of `:end` or `:start`."
2988
2988
  },
2989
+ {
2990
+ "name": "turbo",
2991
+ "type": "Boolean",
2992
+ "default": "`false`",
2993
+ "description": "Whether or not to request a turbo stream and render the response as such."
2994
+ },
2989
2995
  {
2990
2996
  "name": "system_arguments",
2991
2997
  "type": "Hash",
@@ -9334,6 +9334,12 @@
9334
9334
  "default": "`:start`",
9335
9335
  "description": "Which side of the toggle switch to render the status label. One of `:end` or `:start`."
9336
9336
  },
9337
+ {
9338
+ "name": "turbo",
9339
+ "type": "Boolean",
9340
+ "default": "`false`",
9341
+ "description": "Whether or not to request a turbo stream and render the response as such."
9342
+ },
9337
9343
  {
9338
9344
  "name": "system_arguments",
9339
9345
  "type": "Hash",
@@ -9501,6 +9507,20 @@
9501
9507
  "color-contrast"
9502
9508
  ]
9503
9509
  }
9510
+ },
9511
+ {
9512
+ "preview_path": "primer/alpha/toggle_switch/with_turbo",
9513
+ "name": "with_turbo",
9514
+ "snapshot": "false",
9515
+ "skip_rules": {
9516
+ "wont_fix": [
9517
+ "region",
9518
+ "button-name"
9519
+ ],
9520
+ "will_fix": [
9521
+ "color-contrast"
9522
+ ]
9523
+ }
9504
9524
  }
9505
9525
  ],
9506
9526
  "subcomponents": [
@@ -7213,6 +7213,20 @@
7213
7213
  "color-contrast"
7214
7214
  ]
7215
7215
  }
7216
+ },
7217
+ {
7218
+ "preview_path": "primer/alpha/toggle_switch/with_turbo",
7219
+ "name": "with_turbo",
7220
+ "snapshot": "false",
7221
+ "skip_rules": {
7222
+ "wont_fix": [
7223
+ "region",
7224
+ "button-name"
7225
+ ],
7226
+ "will_fix": [
7227
+ "color-contrast"
7228
+ ]
7229
+ }
7216
7230
  }
7217
7231
  ]
7218
7232
  },