diff --git a/README.md b/README.md index 0cd31a2..9017f8f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ const options = { containerId = 'file-picker-container', baseUrl = 'https://app.stackone.com', fields = ['name', 'path', 'driveId'], + showBranding = false, onFilesPicked = (files) => { console.log('Selected files:', files); }, @@ -80,6 +81,7 @@ const filePicker = new FilePicker(options); | **containerId** | string | No | ID of the container element where the file picker will be mounted. | | **baseUrl** | string | No | Which API instance should it connect to. | | **fields** | string[] | No | Which fields from the raw picked file will be mapped on the files picked callback. | +| **showBranding** | boolean | No | Show StackOne footer on the file picker, it is defaulted to true. | | **onFilesPicked** | function | No | Called when files are selected. | | **onOpen()** | function | No | Called when the file picker is opened. | | **onClose()** | function | No | Called every time the file picker is closed regardless of whether a file has been picked or not. | diff --git a/src/filePicker.ts b/src/filePicker.ts index 3637bfd..2e3d729 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -9,6 +9,7 @@ export class FilePicker { #apiUrl: string; #iframe: HTMLIFrameElement | null = null; #isListenerAttached = false; + #showBranding = true; #fields?: string[]; #onFilesPicked: (data: File[]) => void; #onClose: () => void; @@ -23,6 +24,7 @@ export class FilePicker { baseUrl, apiUrl, fields, + showBranding, onFilesPicked, onClose, onOpen, @@ -34,6 +36,7 @@ export class FilePicker { this.#fields = fields; this.#baseUrl = baseUrl ?? 'https://app.stackone.com'; this.#apiUrl = apiUrl ?? 'https://api.stackone.com'; + this.#showBranding = showBranding ?? true; this.#onFilesPicked = onFilesPicked ?? (() => {}); this.#onClose = onClose ?? (() => {}); this.#onOpen = onOpen ?? (() => {}); @@ -71,6 +74,7 @@ export class FilePicker { window.origin, this.#fields, this.#apiUrl, + this.#showBranding, ); this.#iframe.src = url; } diff --git a/src/specs/url.spec.ts b/src/specs/url.spec.ts index 21f17ee..13eb9b8 100644 --- a/src/specs/url.spec.ts +++ b/src/specs/url.spec.ts @@ -44,5 +44,26 @@ describe('#url', () => { expect(parsedUrl.searchParams.has('fields')).toBe(false); }); }); + + describe('when showBranding is false', () => { + it('creates URL without showBranding parameter', () => { + const baseUrl = 'https://example.com'; + const sessionToken = 'test-token'; + const origin = 'https://myapp.com'; + const showBranding = false; + + const url = createUrl( + baseUrl, + sessionToken, + origin, + undefined, + undefined, + showBranding, + ); + const parsedUrl = new URL(url); + + expect(parsedUrl.searchParams.get('showBranding')).toBe('false'); + }); + }); }); }); diff --git a/src/types.ts b/src/types.ts index 6bf717c..94da561 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,6 +11,7 @@ export interface FilePickerOptions { baseUrl?: string; apiUrl?: string; fields?: string[]; + showBranding?: boolean; onFilesPicked?: (data: File[]) => void; onError?: (error: Error) => void; onClose?: () => void; diff --git a/src/utils/url.ts b/src/utils/url.ts index bfaa1f5..d507059 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -4,10 +4,12 @@ export const createUrl = ( origin: string, fields?: string[], apiUrl?: string, + showBranding?: boolean, ) => { const url = new URL(baseUrl); url.searchParams.set('token', sessionToken); url.searchParams.set('origin', btoa(origin)); + url.searchParams.set('showBranding', showBranding ? 'true' : 'false'); if (fields) { url.searchParams.set('fields', btoa(JSON.stringify(fields)));