Gathering detailed insights and metrics for react-mosaic-component-bp3
Gathering detailed insights and metrics for react-mosaic-component-bp3
Gathering detailed insights and metrics for react-mosaic-component-bp3
Gathering detailed insights and metrics for react-mosaic-component-bp3
npm install react-mosaic-component-bp3
Typescript
Module System
Node Version
NPM Version
69.9
Supply Chain
99.1
Quality
73.6
Maintenance
100
Vulnerability
98.2
License
TypeScript (87.41%)
CSS (12.11%)
HTML (0.29%)
JavaScript (0.2%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
2,113
Last Day
1
Last Week
2
Last Month
19
Last Year
267
NOASSERTION License
91 Commits
2 Watchers
2 Branches
7 Contributors
Updated on Sep 12, 2018
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
react-mosaic-component-bp3@1.0.1
Unpacked Size
275.83 kB
Size
53.04 kB
File Count
108
NPM Version
6.4.1
Node Version
10.4.0
Cumulative downloads
Total Downloads
Last Day
-66.7%
1
Compared to previous day
Last Week
-77.8%
2
Compared to previous week
Last Month
111.1%
19
Compared to previous month
Last Year
-36.9%
267
Compared to previous year
1
44
react-mosaic is a full-featured React Tiling Window Manager meant to give a user complete control over their workspace. It provides a simple and flexible API to tile arbitrarily complex react components across a user's view. react-mosaic is written in TypeScript and provides typings but can be used in JavaScript as well.
The best way to see it is a simple Demo.
v1.0 just released! Upgrade guide here.
The core of react-mosaic's operations revolve around the simple binary tree specified by MosaicNode<T>
.
T
is the type of the leaves of the tree and is a string
or a number
that can be resolved to a JSX.Element
for display.
yarn add react-mosaic-component
react-mosaic-component.css
is included on your page.Mosaic
component and use it in your app.Without a theme, Mosaic only loads the styles necessary for it to function - making it easier for the consumer to style it to match their own app.
By default, Mosaic renders with the mosaic-blueprint-theme
class.
This uses the excellent Blueprint React UI Toolkit to provide a good starting state.
It is recommended to at least start developing with this theme.
To use it install Blueprint yarn add @blueprintjs/core
and add its CSS to your page.
Note: Currently react-mosaic only supports v1.x
of Blueprint (tracking here)
See blueprint-theme.less for an example of creating a theme.
Mosaic supports the Blueprint Dark Theme out of the box when rendered with the mosaic-blueprint-theme pt-dark
class.
1html, 2body, 3#app { 4 height: 100%; 5 width: 100%; 6 margin: 0; 7}
1import { Mosaic } from 'react-mosaic-component'; 2import '@blueprintjs/core/dist/blueprint.css'; 3import './app.css'; 4 5const ELEMENT_MAP: { [viewId: string]: JSX.Element } = { 6 a: <div>Left Window</div>, 7 b: <div>Top Right Window</div>, 8 c: <div>Bottom Right Window</div>, 9}; 10 11export const app = ( 12 <div id="app"> 13 <Mosaic 14 renderTile={(id) => ELEMENT_MAP[id]} 15 initialValue={{ 16 direction: 'row', 17 first: 'a', 18 second: { 19 direction: 'column', 20 first: 'b', 21 second: 'c', 22 }, 23 splitPercentage: 40, 24 }} 25 /> 26 </div> 27);
renderTile
is a stateless lookup function to convert T
into a displayable JSX.Element
.
By default T
is string
(so to render one element initialValue="ID"
works).
T
s must be unique within an instance of Mosaic
, they are used as keys for React list management.
initialValue
is a MosaicNode<T>
.
The user can resize these panes but there is no other advanced functionality. This example renders a simple tiled interface with one element on the left half, and two stacked elements on the right half. The user can resize these panes but there is no other advanced functionality.
MosaicWindow
MosaicWindow
is a component that renders a toolbar and controls around its children for a tile as well as providing full featured drag and drop functionality.
1export type ViewId = 'a' | 'b' | 'c' | 'new'; 2 3// Make type alias for generic checking in TSX until https://github.com/Microsoft/TypeScript/issues/6395 is fixed 4 5const ViewIdMosaic = Mosaic.ofType<ViewId>(); 6const ViewIdMosaicWindow = MosaicWindow.ofType<ViewId>(); 7 8const TITLE_MAP: Record<ViewId, string> = { 9 a: 'Left Window', 10 b: 'Top Right Window', 11 c: 'Bottom Right Window', 12 new: 'New Window', 13}; 14 15export const app = ( 16 <ViewIdMosaic 17 renderTile={(id, path) => ( 18 <ViewIdMosaicWindow path={path} createNode={() => 'new'} title={TITLE_MAP[id]}> 19 <h1>{TITLE_MAP[id]}</h1> 20 </ViewIdMosaicWindow> 21 )} 22 initialValue={{ 23 direction: 'row', 24 first: 'a', 25 second: { 26 direction: 'column', 27 first: 'b', 28 second: 'c', 29 }, 30 }} 31 /> 32);
Here T
is a ViewId
that can be used to look elements up in TITLE_MAP
.
This allows for easy view state specification and serialization.
This will render a view that looks very similar to the previous examples, but now each of the windows will have a toolbar with buttons.
These toolbars can be dragged around by a user to rearrange their workspace.
MosaicWindow
API docs here.
Mosaic views have two modes, similar to React.DOM
input elements:
All of the previous examples show use of Mosaic in an Uncontrolled fashion.
Components export both factories and component classes.
If you are using TS/JS then use the factories;
if you are using TSX/JSX then use the exported class but know that you will lose the generics if you aren't careful.
The exported classes are named as the base name of the component (e.g. MosaicWindow
) while the exported factories
have 'Factory' appended (e.g. MosaicWindowFactory
).
See ExampleApp (the application used in the Demo) for a more interesting example that shows the usage of Mosaic as a controlled component and modifications of the tree structure.
1export interface MosaicBaseProps<T extends MosaicKey> { 2 /** 3 * Lookup function to convert `T` to a displayable `JSX.Element` 4 */ 5 renderTile: TileRenderer<T>; 6 /** 7 * Called when a user initiates any change to the tree (removing, adding, moving, resizing, etc.) 8 */ 9 onChange?: (newNode: MosaicNode<T> | null) => void; 10 /** 11 * Additional classes to affix to the root element 12 * Default: 'mosaic-blueprint-theme' 13 */ 14 className?: string; 15 /** 16 * Options that control resizing 17 * @see: [[ResizeOptions]] 18 */ 19 resize?: ResizeOptions; 20 /** 21 * View to display when the current value is `null` 22 * default: Simple NonIdealState view 23 */ 24 zeroStateView?: JSX.Element; 25} 26 27export interface MosaicControlledProps<T extends MosaicKey> extends MosaicBaseProps<T> { 28 /** 29 * The tree to render 30 */ 31 value: MosaicNode<T> | null; 32 onChange: (newNode: MosaicNode<T> | null) => void; 33} 34 35export interface MosaicUncontrolledProps<T extends MosaicKey> extends MosaicBaseProps<T> { 36 /** 37 * The initial tree to render, can be modified by the user 38 */ 39 initialValue: MosaicNode<T> | null; 40} 41 42export type MosaicProps<T extends MosaicKey> = MosaicControlledProps<T> | MosaicUncontrolledProps<T>;
MosaicWindow
1export interface MosaicWindowProps<T extends MosaicKey> { 2 title: string; 3 /** 4 * Current path to this window, provided by `renderTile` 5 */ 6 path: MosaicBranch[]; 7 className?: string; 8 /** 9 * Controls in the top right of the toolbar 10 * default: [Replace, Split, Expand, Remove] if createNode is defined and [Expand, Remove] otherwise 11 */ 12 toolbarControls?: React.ReactNode; 13 /** 14 * Additional controls that will be hidden in a drawer beneath the toolbar. 15 * default: [] 16 */ 17 additionalControls?: React.ReactNode; 18 /** 19 * Label for the button that expands the drawer 20 */ 21 additionalControlButtonText?: string; 22 /** 23 * Whether or not a user should be able to drag windows around 24 */ 25 draggable?: boolean; 26 /** 27 * Method called when a new node is required (such as the Split or Replace buttons) 28 */ 29 createNode?: CreateNode<T>; 30 /** 31 * Optional method to override the displayed preview when a user drags a window 32 */ 33 renderPreview?: (props: MosaicWindowProps<T>) => JSX.Element; 34}
The default controls rendered by MosaicWindow
can be accessed from defaultToolbarControls
The above API is good for most consumers, however Mosaic provides functionality on the Context of its children that make it easier to alter the view state.
All leaves rendered by Mosaic will have the following available on React context.
These are used extensively by MosaicWindow
.
1/** 2 * Valid node types 3 * @see React.Key 4 */ 5export type MosaicKey = string | number; 6export type MosaicBranch = 'first' | 'second'; 7export type MosaicPath = MosaicBranch[]; 8 9/** 10 * Context provided to everything within Mosaic 11 */ 12export interface MosaicContext<T extends MosaicKey> { 13 mosaicActions: MosaicRootActions<T>; 14 mosaicId: string; 15} 16 17export interface MosaicRootActions<T extends MosaicKey> { 18 /** 19 * Increases the size of this node and bubbles up the tree 20 * @param path Path to node to expand 21 * @param percentage Every node in the path up to root will be expanded to this percentage 22 */ 23 expand: (path: MosaicPath, percentage?: number) => void; 24 /** 25 * Remove the node at `path` 26 * @param path 27 */ 28 remove: (path: MosaicPath) => void; 29 /** 30 * Hide the node at `path` but keep it in the DOM. Used in Drag and Drop 31 * @param path 32 */ 33 hide: (path: MosaicPath) => void; 34 /** 35 * Replace currentNode at `path` with `node` 36 * @param path 37 * @param node 38 */ 39 replaceWith: (path: MosaicPath, node: MosaicNode<T>) => void; 40 /** 41 * Atomically applies all updates to the current tree 42 * @param updates 43 */ 44 updateTree: (updates: MosaicUpdate<T>[]) => void; 45 /** 46 * Returns the root of this Mosaic instance 47 */ 48 getRoot: () => MosaicNode<T> | null; 49}
Children (and toolbar elements) within MosaicWindow
are passed the following additional functions on context.
1export interface MosaicWindowContext<T extends MosaicKey> extends MosaicContext<T> { 2 mosaicWindowActions: MosaicWindowActions; 3} 4 5export interface MosaicWindowActions { 6 /** 7 * Fails if no `createNode()` is defined 8 * Creates a new node and splits the current node. 9 * The current node becomes the `first` and the new node the `second` of the result. 10 * `direction` is chosen by querying the DOM and splitting along the longer axis 11 */ 12 split: () => Promise<void>; 13 /** 14 * Fails if no `createNode()` is defined 15 * Convenience function to call `createNode()` and replace the current node with it. 16 */ 17 replaceWithNew: () => Promise<void>; 18 /** 19 * Sets the open state for the tray that holds additional controls 20 */ 21 setAdditionalControlsOpen: (open: boolean) => void; 22 /** 23 * Returns the path to this window 24 */ 25 getPath: () => MosaicPath; 26}
To access the functions on context simply specify contextTypes
on your component.
1class RemoveButton extends React.PureComponent<Props> { 2 static contextTypes = MosaicWindowContext; 3 context: MosaicWindowContext<TileId>; 4 5 render() { 6 return <button onClick={this.remove}>╳</button>; 7 } 8 9 private remove = () => this.context.mosaicActions.remove(this.context.mosaicWindowActions.getPath()); 10}
Utilities are provided for working with the MosaicNode tree in mosaicUtilities
and
mosaicUpdates
MosaicUpdateSpec
is an argument meant to be passed to immutability-helper
to modify the state at a path.
mosaicUpdates
has examples.
/**
* Used by many utility methods to update the tree.
* spec will be passed to https://github.com/kolodny/immutability-helper
*/
export interface MosaicUpdateSpec<T extends MosaicKey> {
$set?: MosaicNode<T>;
splitPercentage?: {
$set: number | null;
};
direction?: {
$set: MosaicDirection;
}
first?: MosaicUpdateSpec<T>;
second?: MosaicUpdateSpec<T>;
}
See Releases
Copyright 2016 Palantir Technologies
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
119 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More