@brandfolder-panel/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.9.33 • Public • Published

Panel UI SDK

Documentation

Getting started

  1. Install the npm package: npm install @brandfolder-panel/sdk.
  2. Import the stylesheet, found in @brandfolder-panel/sdk/styles.css, in your application. All styles are namespaced to .panel-ui-sdk so there should be no conflicts.
  3. Initialize and start using the SDK.

Note: Because the Brandfolder PanelUI SDK renders the components inside of the consuming context, as opposed to within an iframe, all of its dependencies are currently included in the package. We will reassess and move libraries to become peer dependencies as needed.

Initialization

export interface PanelUISdkParameters {
  appName: string;
  anchorElement: HTMLElement; // Used to append the Iframe containing the Panel
  panelUIBaseUrl?: string; // OPTIONAL. Custom base URL if using a self-hosted version of the Panel
  headerBackgroundUrl?: string; // OPTIONAL. Custom background image url for the header
  // OPTIONAL. You can pass in a valid auth token that will be used for requests to the Brandfolder API. If this is
  // not passed in we will fallback to having the user input their API key.
  authParameters?: {
    token: string; // Valid OAuth token or API key
    refreshTokenHandler: () => Promise<string>; // Handler for fetching a new token if the initial one has become invalid. The SDK will call this function as needed.
  };
  statePersistence?: {
    enabled: boolean; // If true, the panel will persist its state in between uses
    storage?: Storage; // OPTIONAL. Allows consumer to pass in a custom storage implementation for persisting state
  };
  styles?: {
    backgroundColor?: string; // Background color for the panel,
    backgroundColorSecondary?: string; // Secondary background color for contrasted elements (i.e. hover styling)
  };
}

Example in React:

function App() {
  const ref = useRef();

  useEffect(() => {
    if (ref.current) {
      const sdk = new PanelUISdk({ appName: 'test', anchorElement: ref.current } });
      sdk.selectAttachments();
    }
  }, [])

  return (
    <div className="App">
      <div ref={ref} id='panel-root' />
    </div>
  );
}

PanelUISdk.selectAttachments

Opens the Panel on the Org landing page by default or on the show page if a Brandfolder or Collection ID is specified. Allows you to pass in a handler to listen for attachment selection events.

Arguments:

export interface SelectAttachmentProps {
  containerId?: string | null; // OPTIONAL - Navigate to specified Brandfolder or Collection, otherwise go to org landing page
  supportedMimeTypes?: string[]; // OPTIONAL - pass in a list of supported mime types
  onDragStart?: (attachment: AttachmentDto) => void; // Called when a user starts dragging an attachment
  onDragEnd?: (attachment: AttachmentDto) => void; // Called when a user stops dragging an attachment
  onSelect: (attachment: AttachmentDto) => void; // Called whenever user selects an attachment
  hideHeader?: boolean; // OPTIONAL - hides the header. Defaults to false.
  resumeSession?: boolean; // OPTIONAL - resume from persisted session
  searchParameters?: SearchParameters; // OPTIONAL - Use search parameters with Brandfolder API 
  enforcedSearchParameters?: EnforcedSearchParameters; // OPTIONAL - Enforce search parameters with Brandfolder API
};

Example:

panel.selectAttachments({
  containerId: 'VALID_BRANDFOLDER_ID',
  onSelect: (attachment) => console.log('Attachment selected: ', attachment),
  hideHeader: true,
});

Supporting drag and drop for Brandfolder attachments

The @brandfolder-panel/sdk/utilities namespace exposes utility functions that you can use to simplify how you consume drag and drop events originating from the Panel. It will take care of extracting the attachment data from the event and passing it to your handler.

Here are the available functions:

export function isAttachmentDragEvent(event: DragEvent): boolean => {...};

export function handleAttachmentDragEvent(
  event: DragEvent,
  handler: (props: AttachmentDragEventHandlerProps) => void,
): void => {...};

And here's an example of how you can use them in react:

const handleAttachmentDrag = (event: DragEvent) => {
  if (isAttachmentDragEvent(event)) {
    handleAttachmentDragEvent(event, ({ attachment }) => {
      console.log('Attachment dragged over drop zone: ', attachment);
    });
  }
};

return <div onDragOver={handleAttachmentDrag}>Drop Zone</div>;

PanelUISdk.openUpload

Opens the Panel on the Upload page. Allows you to pass in an array of objects with file blobs to be uploaded.

Arguments:

export interface ImageUploadPayload {
  file_name: string;
  file: Blob;
}
export interface OpenUploadProps {
  uploadAssets: ImageUploadPayload[]; // an array of file blobs with file names
  hideHeader?: boolean; // OPTIONAL - hides the header
}

Example:

panel.openUpload({
  uploadAssets: [{file_name: 'new-file', file: new Blob()}];
  hideHeader?: true;
});

PanelUISdk.closePanel

Removes the Panel from the anchor element. The SDK object remains valid and can be used to initiate new operations.

Example:

panel.closePanel()

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.9.33372latest

Version History

VersionDownloads (Last 7 Days)Published
0.9.33372
0.9.3212
0.9.3110
0.9.304
0.9.295
0.9.281
0.9.271
0.9.26243
0.9.253
0.9.242
0.9.232
0.9.212
0.9.202
0.9.192
0.9.173
0.9.162
0.9.152
0.9.142
0.9.112
0.9.102
0.9.92
0.9.82
0.9.72
0.9.62
0.9.52
0.9.42
0.9.32
0.9.22
0.9.12
0.9.02
0.8.32
0.8.22
0.8.12
0.8.02
0.7.12
0.7.02
0.6.3125
0.6.22
0.6.12
0.6.02
0.5.02
0.4.02
0.3.527
0.3.42
0.3.32
0.3.22
0.3.12
0.2.42
0.2.32
0.2.22
0.2.12
0.2.02
0.1.02

Package Sidebar

Install

npm i @brandfolder-panel/sdk

Weekly Downloads

679

Version

0.9.33

License

MIT

Unpacked Size

9.36 MB

Total Files

852

Last publish

Collaborators

  • brandfolder-developers