### Basic Hotkey Usage Source: https://github.com/box/box-ui-elements/blob/master/src/components/hotkeys/Hotkeys.md This example demonstrates the basic setup for triggering the help modal by typing '?'. Ensure a base HotkeyLayer is present in your application hierarchy for hotkeys to function. ```jsx /* NOTE: please see the HotkeyFriendlyModal example for code */
Try typing "?" to trigger the help modal.
``` -------------------------------- ### Unified Share Modal Base Example (React) Source: https://github.com/box/box-ui-elements/blob/master/src/features/unified-share-modal/README.md This example demonstrates the basic setup for the Unified Share Modal. It includes initializing the modal's state, defining contact data, and setting up event handlers for closing the modal and fetching initial data. Extend this for different initial loads or to demonstrate various interactions. ```javascript const Button = require('box-ui-elements/es/components/button').default; // Base Example. Extend for different initial loads, or to demonstrate different interactions class USMExample extends React.Component { constructor() { super(); this.setInitialState(); this.contacts = [ { id: 0, collabID: 0, name: 'Jackie', email: 'j@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Owner', userID: '0', profileURL: 'https://foo.bar' }, { id: 1, collabID: 1, name: 'Jeff', email: 'jt@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Viewer', userID: '1', }, { id: 2, collabID: 2, name: 'David', email: 'dt@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '2', }, { id: 3, collabID: 3, name: 'Yang', email: 'yz@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '3', }, { id: 4, collabID: 4, name: 'Yong', email: 'ysu@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '4', }, { id: 5, collabID: 5, name: 'Will', email: 'wy@example.com', type: 'pending', hasCustomAvatar: false, translatedRole: 'Editor', userID: '5', }, { id: 6, collabID: 6, name: 'Dave', email: 'd@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '6', }, { id: 7, collabID: 7, name: 'Ke', email: 'k@external.com', isExternalUser: true, type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '7', }, { id: 8, collabID: 8, name: 'Wenbo', email: 'w@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '8', }, { id: 11, collabID: 11, name: 'Supersupersupersuperreallyreallyreallylongfirstname incrediblyspectacularlylonglastname', email: 'Supersupersupersuperreallyreallyreallyincrediblyspectacularlylongemail@example.com', type: 'user', hasCustomAvatar: false, translatedRole: 'Editor', userID: '11', }, { /* example group contact */ id: 14, collabID: 14, type: 'group', name: 'my group', hasCustomAvatar: false, translatedRole: 'Viewer', userID: null, }, ]; this.closeModal = this.closeModal.bind(this); this.fakeRequest = this.fakeRequest.bind(this); this.getInitialData = this.getInitialData.bind(this); } setInitialState() { return this.state = { isOpen: false, item: { bannerPolicy: { body: 'test', }, classification: 'internal', grantedPermissions: { itemShare: true }, hideCollaborators: false, id: 12345, name: 'My Example Folder', type: 'folder', typedID: 'd_12345' }, collaboratorsList: { collaborators: [], }, selectorOptions: [], sharedLink: this.setDefaultSharedLinkState(), submitting: false }; } setDefaultSharedLinkState() { return this.defaultSharedLinkState = { accessLevel: '', allowedAccessLevels: {}, canChangeAccessLevel: true, enterpriseName: '', expirationTimestamp: null, isDownloadSettingAvailable: true, isNewSharedLink: false, permissionLevel: '', url: '', }; } closeModal() { this.setState({ isOpen: false, sharedLink: this.setDefaultSharedLinkState(), collaboratorsList: { collaborators: [], }, }); } getInitialData() { const { canRemoveCollaborators } = this.props; const initialPromise = this.fakeRequest(); const fetchCollaborators = new Promise(resolved => { setTimeout(() => { const collaborators = this.contacts.slice(); const collaboratorsList = { collaborators: this.contacts.map(contact => { // convert the existing contact entries to compatible collaborator entries const isExternalCollab = contact.isExternalUser; delete contact.isExternalUser; contact.isExternalCollab = isExternalCollab; if (isExternalCollab) { contact.expiration = { executeAt: "November 27, 2022", } } if (canRemoveCollaborators) { ``` -------------------------------- ### Render New Folder Modal Example Source: https://github.com/box/box-ui-elements/blob/master/src/features/content-explorer/new-folder-modal/README.md Demonstrates how to render the New Folder Modal component using its example implementation. Ensure the examples module is correctly imported. ```javascript const NewFolderModalExamples = require('examples').NewFolderModalExamples; ``` -------------------------------- ### USM Example Component Configuration Source: https://github.com/box/box-ui-elements/blob/master/src/features/unified-share-modal/README.md Configuration for the USMExample component, including event handlers for sending invites and shared links, and initial state setup. ```javascript sendInvites={ () => this.fakeRequest().then(() => { this.closeModal(); }) } sendInvitesError={''} sendSharedLink={ ({ emails, emailMessage }) => this.fakeRequest().then(() => { this.closeModal(); console.log(`Sent invite to ${emails} with message "${emailMessage}"`); })} sendSharedLinkError={''} sharedLink={ this.state.sharedLink } showCalloutForUser={true} showUpgradeOptions submitting={ this.state.submitting } suggestedCollaborators={{ '2': { id: 2, userScore: '.1', name: 'David', email: 'dt@example.com', }, '5': { id: 5, userScore: '0.2', name: 'Will', email: 'wy@example.com', }, '1': { id: 1, userScore: '0.5', name: 'Jeff', email: 'jt@example.com', }, '3': { id: 3, userScore: '2', name: 'Yang', email: 'yz@example.com', } }} trackingProps={ { inviteCollabsEmailTracking: {}, sharedLinkEmailTracking: {}, sharedLinkTracking: {}, inviteCollabTracking: {}, modalTracking: {}, collaboratorListTracking: {}, } } canRemoveCollaborators={this.props.canRemoveCollaborators} onRemoveCollaborator={this.props.onRemoveCollaborator} /> } ) } } ``` -------------------------------- ### Render SecurityCloudGameExamples Source: https://github.com/box/box-ui-elements/blob/master/src/features/security-cloud-game/README.md Example of how to render the SecurityCloudGameExamples component. Ensure the 'examples' module is correctly required. ```javascript const SecurityCloudGameExamples = require('examples').SecurityCloudGameExamples; ``` -------------------------------- ### Context Menu with Submenu Example Source: https://github.com/box/box-ui-elements/blob/master/src/components/context-menu/README.md Shows how to use a Context Menu that includes a submenu. This example renders a pre-defined example component. ```javascript const Example = require('examples').ContextMenuWithSubmenuWithBoundariesElementExample; ``` -------------------------------- ### Simple Context Menu Example Source: https://github.com/box/box-ui-elements/blob/master/src/components/context-menu/README.md Demonstrates a basic Context Menu with a target div and a simple menu structure. It uses require for imports as is common in markdown examples. ```javascript // @NOTE: You can only use require instead of import in markdown. const Menu = require('../menu').Menu; const MenuItem = require('../menu').MenuItem;
Target Component - right click me
View Profile Help
``` -------------------------------- ### Basic Form with Various Input Types Source: https://github.com/box/box-ui-elements/blob/master/src/components/form-elements/form/README.md This example shows a comprehensive form setup using FormElement, including text inputs, a select dropdown, a toggle controlling a textarea, and custom validation. ```javascript const Select = require('box-ui-elements/es/components/select').default; const Toggle = require('box-ui-elements/es/components/toggle').default; const Button = require('box-ui-elements/es/components/button').default; const customValidFn = function customFn(value) { if (value !== 'box') { return { code: 'notbox', message: 'value is not box', }; } return null; }; const [state, setState] = React.useState({ formData: { showtextareatoggle: '', }, formValidityState: {}, }); { setState(prevState => ({ ...prevState, formValidityState: {}, formData })); } } onValidSubmit={ () => { // On a server validation error, set formValidityState to // push error states to child inputs setState(prevState => ({ ...prevState, formValidityState: { username: { code: 'usernametaken', message: 'Username already taken.', }, }, })); } } onInvalidSubmit={ formValidityState => console.log(formValidityState) } formValidityState={ state.formValidityState } >
{state.formData.showtextareatoggle === 'on' ? : null}
``` -------------------------------- ### IconsExample Integration Source: https://github.com/box/box-ui-elements/blob/master/src/icons/two-toned/README.md Example of integrating multiple icons using the IconsExample component. ```javascript const icons = [ // ... other icon definitions ]; ; ``` -------------------------------- ### Example Usage of Icons Source: https://github.com/box/box-ui-elements/blob/master/src/icons/general/README.md Demonstrates how to render a collection of icons using the IconsExample component. Ensure the 'icons' array is properly defined. ```javascript ; ``` -------------------------------- ### Complex Flyout Example Source: https://github.com/box/box-ui-elements/blob/master/src/components/flyout/Flyout.md Demonstrates a more complex Flyout setup with custom class names, offset positioning, and integrated form elements like TextArea and TextInput within the overlay. Includes action buttons. ```jsx