Skip to content

Commit 364ae64

Browse files
authored
Merge pull request #230 from GleapSDK/fix-setstyles-types
fix: declare Gleap.setStyles with its positional arguments
2 parents d291043 + c3aa2aa commit 364ae64

4 files changed

Lines changed: 56 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Unreleased
4+
Fixed: `index.d.ts` declared `Gleap.setStyles` with one object, but the SDK takes positional arguments: `setStyles(primaryColor, headerColor, buttonColor, backgroundColor?, borderRadius?, buttonX?, buttonY?, buttonStyle?, headerColor2?, headerColor3?)`. A call in the declared object form threw an error on the page and injected no styles. TypeScript projects that call `setStyles` with an object now get a compile error pointing at that call, which never worked; pass the values as arguments instead. No runtime change.
5+
36
## 19.9.0
47
Changed: the feedback form's **Record screen** uses the microphone only when **Developer options → Microphone** is on, and then it starts muted until the user turns it on. Until this version, form recordings asked for the microphone whenever the browser had one, regardless of that setting, and on a site that already had microphone permission the browser gave it without a prompt. The mic button is hidden when the setting is off. Projects that want sound in form recordings turn the setting on.
58
Added: product tours and tooltips can point at elements inside open shadow roots. A selector continues into a shadow root with `host >>> inner`, the element picker stores such selectors, and the highlight, the interaction lockout and click-to-continue work for those elements.

‎index.d.ts‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,36 @@ export namespace Gleap {
170170
function trackEvent(name: string, data?: any): void;
171171
function setAppBuildNumber(buildNumber: string): void;
172172
function setAppVersionCode(versionCode: string): void;
173-
function setStyles(styles: {
174-
primaryColor: string;
175-
headerColor: string;
176-
buttonColor: string;
177-
backgroundColor: string;
178-
borderRadius?: number;
179-
buttonX?: number;
180-
buttonY?: number;
181-
buttonStyle?: string;
182-
}): void;
173+
/**
174+
* Replaces the widget's stylesheet: colors, corner radius and the launcher's offsets.
175+
* Takes positional arguments. The SDK applies the dashboard's look the same way
176+
* whenever the project's config loads, which replaces an earlier call.
177+
* Colors are six-digit hex colors such as "#485BFF".
178+
* @param primaryColor UI color.
179+
* @param headerColor Header color.
180+
* @param buttonColor Launcher color.
181+
* @param backgroundColor Widget background. Default "#ffffff".
182+
* @param borderRadius Corner radius in px. Default 20.
183+
* @param buttonX Distance of the launcher and widget from the page's side, in px. Default 20.
184+
* @param buttonY Distance of the launcher from the page's bottom, in px. Default 20.
185+
* @param buttonStyle The launcher's position ("BOTTOM_LEFT", "BOTTOM_RIGHT", "BUTTON_CLASSIC",
186+
* "BUTTON_CLASSIC_LEFT", "BUTTON_CLASSIC_BOTTOM" or "BUTTON_NONE"), used to place
187+
* notifications clear of it. Default "BOTTOM_LEFT".
188+
* @param headerColor2 Second header gradient color. Defaults to `headerColor`.
189+
* @param headerColor3 Third header gradient color. Defaults to `headerColor`.
190+
*/
191+
function setStyles(
192+
primaryColor: string,
193+
headerColor: string,
194+
buttonColor: string,
195+
backgroundColor?: string,
196+
borderRadius?: number,
197+
buttonX?: number,
198+
buttonY?: number,
199+
buttonStyle?: string,
200+
headerColor2?: string,
201+
headerColor3?: string
202+
): void;
183203
function disableConsoleLogOverwrite(): void;
184204
function setLiveSite(isLiveSite: boolean): void;
185205
function enableShortcuts(enabled: boolean): void;

‎smoke/typings.fixture.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Calls a TypeScript project makes, compiled against index.d.ts by typings.spec.mjs.
2+
// A call marked @ts-expect-error must not compile: the SDK would fail on it at runtime.
3+
import Gleap from '../index';
4+
5+
Gleap.setStyles('#1A73E8', '#0B57D0', '#1A73E8');
6+
Gleap.setStyles('#1A73E8', '#0B57D0', '#1A73E8', '#FFFFFF', 12, 24, 24, 'BOTTOM_RIGHT', '#4285F4', '#8AB4F8');
7+
8+
// @ts-expect-error setStyles takes positional arguments; an object throws on the page and injects no styles.
9+
Gleap.setStyles({ primaryColor: '#1A73E8', headerColor: '#0B57D0', buttonColor: '#1A73E8', backgroundColor: '#FFFFFF' });

‎smoke/typings.spec.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// index.d.ts as a TypeScript project compiles against it, with the options of `npm run typecheck`.
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { expect, test } from '@playwright/test';
5+
import ts from 'typescript';
6+
7+
const FIXTURE = fileURLToPath(new URL('typings.fixture.ts', import.meta.url));
8+
9+
// An unused @ts-expect-error is itself an error, so no errors means every marked call was rejected.
10+
test('index.d.ts accepts the calls in typings.fixture.ts and rejects the ones marked @ts-expect-error', () => {
11+
const program = ts.createProgram([FIXTURE], { strict: true, noEmit: true, types: ['node'] });
12+
const errors = ts.getPreEmitDiagnostics(program).map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, ' '));
13+
expect(errors).toEqual([]);
14+
});

0 commit comments

Comments
 (0)