Use the ContentExplorer element
masterContentExplorer is used to navigate a file tree structure. It allows users to select files, select folders, or perform file operations such as moving or copying items.repository·master·Indexed 20 days ago
https://github.com/box/box-ui-elementsA library of pre-built, high-level UI components for integrating core Box web application features into custom applications. It provides standard elements like ContentExplorer, ContentPicker, ContentUploader, and ContentOpenWith, as well as specialized components such as ContentPreview and ContentSidebar. The library is available as React components and includes a variety of utility components including Badge, Breadcrumb, Checkbox, ContextMenu, and DatePicker.
ContentExplorer is used to navigate a file tree structure. It allows users to select files, select folders, or perform file operations such as moving or copying items.<DraftJSMentionSelector /> is a component used for text editing that implements the underlying text editor using Draft.js instead of the standard <ContentEditable />. It functions similarly to the <MentionSelector /> component but uses Draft.js's immutable state model.
Component Hierarchy:
DraftJSMentionSelector (Top-level)DraftJSEditor (Internal editor implementation)SecurityCloudGame is a security feature used by the Embed Widget to prevent clickjacking attacks. It presents a 'game' where a user must drag a randomly positioned DragCloud into a randomly positioned DropCloud. This interaction ensures the user is a human and not an automated script or a malicious overlay.The DraftJSEditor component provides a Draft.js editor interface within box-ui-elements.
This component is uncontrolled regarding its editorState. It does not own or manage the editor state internally. Instead, you must manage the EditorState in your own application logic and pass it to the component.
Whenever the content within the <Editor /> changes, the component triggers its onChange method, passing the new EditorState as an argument. You should use this callback to update your local state.
Because the component does not own the EditorState, you cannot configure Draft.js decorators via the DraftJSEditor component itself. You must apply any decorators (for features like mentions or custom formatting) at the point where you define and manage the EditorState in your application.
// Conceptual usage pattern:
// 1. Manage EditorState in your parent component
// 2. Pass state to DraftJSEditor
// 3. Update state via onChange
<DraftJSEditor
editorState={this.state.editorState}
onChange={(nextEditorState) => this.setState({ editorState: nextEditorState })}
/>The Datalist Item is an ARIA-compliant component designed to render list items within a datalist, such as a SelectorDropdown.
Key Behaviors:
SelectorDropdown, you must specify keys based on your actual data rather than using the default array index. Using data-based keys ensures that component state is reset correctly when the underlying data changes.The Portal component is used to render children into a DOM node outside of the current component's hierarchy. This is specifically useful for UI elements that need to break out of parent containers, such as modals, notifications, popovers, and flyouts.
Key behaviors to note:
Portal only manages the mounting and unmounting logic to the outside DOM; it does not provide any built-in styles, event handlers, or behaviors. You must implement these in your parent component.Portal parent to the children components.Portal (such as className) are applied directly to the inner-wrapper div that contains the children.import { Portal } from 'box-ui-elements';
const MyPortalExample = ({ isOpen }) => {
if (!isOpen) return null;
return (
<Portal className='modal-wrapper'>
<div className='modal'>...
</div>
</Portal>
);
}To ensure Flow types are automatically included, always use the import * as React from 'react' syntax. When using this pattern, you must prefix all React functions and components with React..
Correct:
React.ComponentReact.useStateIncorrect:
ComponentuseStateContentPicker, use the IntlProvider component from the library. You can also pass a language string or a messages Map containing specific translation overrides directly to the ContentPicker props.To use a selectable table (via the makeSelectable HOC), you must ensure that a <HotkeyLayer> component is present somewhere above the table in the component tree. Without a <HotkeyLayer>, the selectable functionality will not work correctly.
// Note: The makeSelectable HOC requires a HotkeyLayer in the component tree
<HotkeyLayer>
<SelectableTableExamples />
</HotkeyLayer>The <Menu> component provides an ARIA-compliant menu implementation, handling keyboard navigation, focus management, and appropriate ARIA attributes according to the WAI-ARIA Menu standard.
To build a menu, you can use several sub-components:
<MenuItem>: A standard menu item.<MenuSeparator />: A visual divider between items.<MenuSectionHeader>: A header for grouping menu items.<MenuLinkItem>: Required for wrapping anchor tags (<a> or <Link>) to ensure correct ARIA behavior for links within a menu.<SelectMenuLinkItem>: Used for items that represent a selectable state, typically rendered with a checkmark.<SubmenuItem>: Used to nest a <Menu> inside another menu to create submenus.const {
MenuItem,
MenuSeparator,
MenuLinkItem,
MenuSectionHeader
} = require('box-ui-elements/es/components/menu');
<Menu>
<MenuItem>View Profile</MenuItem>
<MenuItem showRadar>Help</MenuItem>
<MenuSeparator />
<MenuSectionHeader>Menu Section</MenuSectionHeader>
<MenuLinkItem>
<Link href="/#">Awesome Link</Link>
</MenuLinkItem>
</Menu>;Rich text styling in this component is handled via two mechanisms:
Entities annotate a range of text with metadata. In DraftJSMentionSelector, mentions are implemented as entities.
contentState.createEntity().Modifier.replaceText(...) to replace the partial text (e.g., @se) with the full entity-ified text (e.g., @Sebastian Motraghi) to generate a new ContentState.id in its metadata.Decorators scan text to determine which ranges should be rendered with special UI.
mentionDecorator is applied when creating the initial EditorState.mentionStrategy identifies ranges that have an Entity annotated as type: 'MENTION'.children prop with the actual text content. Your component must use { props.children } to ensure the rendered UI matches the internal state.Correct Pattern:
// Do this
<MyDecoratorComponent>{ props.children }</MyDecoratorComponent>
// Do NOT do this
<MyDecoratorComponent text={ props.text } />Box UI Elements are authentication-agnostic and work with both Managed Users (Box accounts) and App Users. To authenticate, you must provide an access token to the component.
You can provide the accessToken in two ways: