@bynder/compact-view

中文文档
7.0.0发布于 2026/10/29UNLICENSEDTypeScriptESM + CJS近 30 天下载 12万

Bynder Compact View

原始使用文档
文档目录8 节
  1. Install
  2. Exports
  3. Usage
  4. API
  5. <CompactView> props ( CompactViewProps )
  6. <Login> props ( CompactViewLoginProps )
  7. <Modal> props ( CompactViewModalProps )
  8. Types

Bynder Compact View — React component

Embeddable Bynder asset picker, distributed as the @bynder/compact-view NPM package.

For the CDN/window.BynderCompactView.open() usage, see the docs.

Install

npm install @bynder/compact-view

Peer dependencies: react and react-dom (^19.2.5).

Exports

import {
    CompactView,
    Login,
    Modal,
    // types
    type CompactViewProps,
    type CompactViewLoginProps,
    type CompactViewModalProps,
} from '@bynder/compact-view';

Usage

CompactView must be rendered inside <Login>. <Modal> is optional — if omitted, mount <Login> into your own container element.

import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';
import { CompactView, Login, Modal } from '@bynder/compact-view';

const assetFieldSelection = `
    name
    url
    originalUrl
    derivatives {
        thumbnail
        webImage
    }
    ... on Video {
        previewUrls
    }
`;

function App() {
    const [isOpen, setIsOpen] = useState(false);

    const onSuccess = (assets, additionalInfo) => {
        console.log(assets, additionalInfo);
        setIsOpen(false);
    };

    return (
        <>
            <button onClick={() => setIsOpen(true)}>Open Compact View</button>
            <Modal isOpen={isOpen} onClose={() => setIsOpen(false)}>
                <Login portal={{ url: 'portal.bynder.com', editable: true }} language="en_US">
                    <CompactView
                        language="en_US"
                        onSuccess={onSuccess}
                        assetFieldSelection={assetFieldSelection}
                    />
                </Login>
            </Modal>
        </>
    );
}

const root = createRoot(document.getElementById('app'));
root.render(<App />);

For the container-mounted variant, drop <Modal> and pass isContainerMode to <CompactView>:

<div style={{ width: 800, height: 600 }}>
    <Login portal={{ url: 'portal.bynder.com' }}>
        <CompactView isContainerMode onSuccess={onSuccess} />
    </Login>
</div>

See more on Bynder Docs.

API

<CompactView> props (CompactViewProps)

All props are optional.

PropTypeDefaultDescription
onSuccess(assets: OnSuccessAsset[], info: AdditionalInfo) => voidconsole.logCalled with the selected assets and an additionalInfo object (currently { selectedFile? }).
language"en_US" | "nl_NL" | "de_DE" | "fr_FR" | "es_ES""en_US"UI language. Only the first two characters of the locale are used to load translations.
mode"SingleSelect" | "SingleSelectFile" | "MultiSelect""MultiSelect"Selection mode.
assetTypesAssetType[]["IMAGE", "AUDIO", "VIDEO", "DOCUMENT"]Allowed asset types. Values are case-insensitive at the API surface.
assetFieldSelectionstringSee defaultAssetFieldSelectionGraphQL field selection for the asset returned to onSuccess. Fields outside this selection are undefined.
assetFilterAssetFilterJsonNonePredefined filters applied on open.
defaultSearchTermstringNoneInitial value for the search input.
defaultImageDerivativeNamestringNoneName of the image derivative returned as selectedFile for SingleSelectFile.
defaultVideoDerivativeNamestringNoneName of the video derivative returned as selectedFile for SingleSelectFile.
selectedAssetsstring[][]Asset IDs to preselect. In single-select modes, only the last ID is used.
themeThemeNoneTheming overrides (see below).
hideExternalAccessbooleanfalseRemoves access to external DAM from assets and collections.
hideLimitedUsebooleanfalseHides limited-use assets from the grid.
hideSwitchbooleanfalseHides the Assets/Collections switch.
hideDefaultDerivativesbooleanfalseHides the default derivatives webImage, thumbnail and mini from the derivative dropdown for every asset type. The original asset and other derivatives stay available.
selectAllOptionbooleanfalseAdds a "Select all" action in MultiSelect mode.
noCachebooleanfalseDisables HTTP caching on GraphQL requests.
isContainerModebooleanfalseRequired when mounting <Login> inside your own DOM container instead of <Modal>.
resetStoreOnMountbooleanfalseIn isContainerMode, resets internal stores (search, filters, selection, routing) on mount. Ignored otherwise — non-container mode always resets.
enableDASHbooleanfalseIncludes DASH streaming links alongside HLS in streamingLinks for video assets.
enableDATPermissionManagementbooleanfalseWhen true, DAT UI (the "New transformation" link and the preset picker in the transformation editor) is gated on the authenticated user's DAT permissions from module_permissions in the access token. When false, DAT UI is always available and the preset picker is hidden — matching the behavior before permission-based gating was introduced.

<Login> props (CompactViewLoginProps)

PropTypeDescription
portal{ url: string; editable?: boolean } (PortalConfig)Default portal URL. editable: false locks Compact View to a single portal (default true).
languagesame as CompactView.languageLocalizes the login screen.
authentication{ getAccessToken: () => string; hideLogout?: boolean }Skip the interactive OAuth flow by providing an access token. hideLogout: true hides the logout button.
onLogout() => voidCalled after the user logs out.
childrenReact.ReactNodeTypically <CompactView>.

<Modal> props (CompactViewModalProps)

PropTypeDescription
isOpenbooleanControls visibility.
onClose() => voidCalled on backdrop click, escape, or close button.
styleReact.CSSPropertiesInline styles applied to the modal wrapper (e.g. { width: '90%' }).

Types

type AssetType = 'AUDIO' | 'DOCUMENT' | 'IMAGE' | 'VIDEO' | 'ARCHIVE';

type SelectionMode = 'SingleSelect' | 'SingleSelectFile' | 'MultiSelect';

type File = {
    url: string;
    width?: number;
    height?: number;
    fileSize?: number;
};

type PortalConfig = {
    url: string;
    editable?: boolean;
};

type AssetFilterJson = {
    predefinedAssetType?: AssetType[];
    collectionId?: string;
    predefinedMetapropertiesOptions?: Record<string, Record<string, string>>;
    searchTerm?: string;
    predefinedTagNames?: string[];
    isLimitedUse?: boolean;
    showToolbar?: boolean;
};

type Theme = {
    colorPrimary?: string;
    colorButtonPrimary?: string;
    colorButtonPrimaryLabel?: string;
    colorButtonPrimaryActive?: string;
    colorButtonPrimaryHover?: string;
    colorButtonPrimaryHoverLabel?: string;
};

type VideoPreset = {
    presetId: string;
    name: string;
    format: string;
    previewUrl: string;
};

type AdditionalInfo = { selectedFile?: File };

interface OnSuccessAsset {
    id: string;
    files: Record<string, File>;
    name?: string;
    description?: string;
    databaseId?: string;
    createdAt?: string;
    originalUrl?: string;
    publishedAt?: string;
    tags?: string[];
    type?: AssetType;
    updatedAt?: string;
    url?: string;
    extensions?: string[];
    metaproperties?: { nodes: OnSuccessAssetMetaproperty[] };
    textMetaproperties?: OnSuccessAssetTextMetaproperty[];
    derivatives?: { thumbnail?: string; webImage?: string };
    previewUrls?: string[];
    streamingLinks?: { hls?: string; dash?: string; embedCode?: string };
    videoPresets?: VideoPreset[];
}

type OnSuccessCallback = (assets: OnSuccessAsset[], info: AdditionalInfo) => void;

OnSuccessAsset reflects the default GraphQL field selection. With a custom assetFieldSelection, requested fields not declared on OnSuccessAsset will not be typed — cast to a custom interface to read them.

版本与发布记录

@bynder/compact-view 共发布 75 个版本,首次发布于 2019/01/10;过去 12 个月发布了 13 个版本。

版本发布日期距今
7.0.0latest2026/10/2910 天前
6.1.02026/09/181 个月前
6.0.22026/09/012 个月前
6.0.12026/08/252 个月前
6.0.02026/08/202 个月前
5.4.02026/06/094 个月前

关于 @bynder/compact-view 的常见问题

@bynder/compact-view 是什么?

Bynder Compact View

如何安装 @bynder/compact-view?

在项目目录运行 npm install @bynder/compact-view,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2.5)、react-dom(^19.2.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bynder/compact-view 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bynder/compact-view 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bynder/compact-view 可以商用吗?

@bynder/compact-view 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@bynder/compact-view 的下载量有多少?

根据 npm 官方下载统计,@bynder/compact-view 在 2026/10/09 – 2026/11/07 这 30 天内被下载 119,803 次,日均约 3,993 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bynder/compact-view 还在维护吗?

最新版本 7.0.0 发布于 2026/10/29(10 天前);至今共发布 75 个版本,其中过去 12 个月发布了 13 个;首次发布于 2019/01/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。