Sidebar components
Summary: _typescript_ Reviewed By: priteshrnandgaonkar Differential Revision: D16828870 fbshipit-source-id: b343b28b3dd1700919df3fcfde659f7fe99cadff
This commit is contained in:
committed by
Facebook Github Bot
parent
dedf09c2ae
commit
4c521858c7
@@ -7,9 +7,16 @@
|
|||||||
|
|
||||||
import Interactive from './Interactive.js';
|
import Interactive from './Interactive.js';
|
||||||
import FlexColumn from './FlexColumn.js';
|
import FlexColumn from './FlexColumn.js';
|
||||||
import {colors} from './colors.tsx';
|
import {colors} from './colors';
|
||||||
import {Component} from 'react';
|
import {Component} from 'react';
|
||||||
import styled from '../styled/index.js';
|
import styled from 'react-emotion';
|
||||||
|
import {
|
||||||
|
BackgroundClipProperty,
|
||||||
|
HeightProperty,
|
||||||
|
WidthProperty,
|
||||||
|
BackgroundColorProperty,
|
||||||
|
} from 'csstype';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
const SidebarInteractiveContainer = styled(Interactive)({
|
const SidebarInteractiveContainer = styled(Interactive)({
|
||||||
flex: 'none',
|
flex: 'none',
|
||||||
@@ -17,74 +24,81 @@ const SidebarInteractiveContainer = styled(Interactive)({
|
|||||||
|
|
||||||
type SidebarPosition = 'left' | 'top' | 'right' | 'bottom';
|
type SidebarPosition = 'left' | 'top' | 'right' | 'bottom';
|
||||||
|
|
||||||
const SidebarContainer = styled(FlexColumn)(props => ({
|
const SidebarContainer = styled(FlexColumn)(
|
||||||
backgroundColor: props.backgroundColor || colors.macOSTitleBarBackgroundBlur,
|
(props: {
|
||||||
borderLeft: props.position === 'right' ? '1px solid #b3b3b3' : 'none',
|
position: 'right' | 'top' | 'left' | 'bottom';
|
||||||
borderTop: props.position === 'bottom' ? '1px solid #b3b3b3' : 'none',
|
backgroundColor?: BackgroundClipProperty;
|
||||||
borderRight: props.position === 'left' ? '1px solid #b3b3b3' : 'none',
|
overflow?: boolean;
|
||||||
borderBottom: props.position === 'top' ? '1px solid #b3b3b3' : 'none',
|
}) => ({
|
||||||
height: '100%',
|
backgroundColor:
|
||||||
overflowX: 'hidden',
|
props.backgroundColor || colors.macOSTitleBarBackgroundBlur,
|
||||||
overflowY: 'auto',
|
borderLeft: props.position === 'right' ? '1px solid #b3b3b3' : 'none',
|
||||||
textOverflow: props.overflow ? 'ellipsis' : 'auto',
|
borderTop: props.position === 'bottom' ? '1px solid #b3b3b3' : 'none',
|
||||||
whiteSpace: props.overflow ? 'nowrap' : 'normal',
|
borderRight: props.position === 'left' ? '1px solid #b3b3b3' : 'none',
|
||||||
}));
|
borderBottom: props.position === 'top' ? '1px solid #b3b3b3' : 'none',
|
||||||
|
height: '100%',
|
||||||
|
overflowX: 'hidden',
|
||||||
|
overflowY: 'auto',
|
||||||
|
textOverflow: props.overflow ? 'ellipsis' : 'auto',
|
||||||
|
whiteSpace: props.overflow ? 'nowrap' : 'normal',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
type SidebarProps = {
|
type SidebarProps = {
|
||||||
/**
|
/**
|
||||||
* Position of the sidebar.
|
* Position of the sidebar.
|
||||||
*/
|
*/
|
||||||
position: SidebarPosition,
|
position: SidebarPosition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default width of the sidebar. Only used for left/right sidebars.
|
* Default width of the sidebar. Only used for left/right sidebars.
|
||||||
*/
|
*/
|
||||||
width?: number,
|
width?: number;
|
||||||
/**
|
/**
|
||||||
* Minimum sidebar width. Only used for left/right sidebars.
|
* Minimum sidebar width. Only used for left/right sidebars.
|
||||||
*/
|
*/
|
||||||
minWidth?: number,
|
minWidth?: number;
|
||||||
/**
|
/**
|
||||||
* Maximum sidebar width. Only used for left/right sidebars.
|
* Maximum sidebar width. Only used for left/right sidebars.
|
||||||
*/
|
*/
|
||||||
maxWidth?: number,
|
maxWidth?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default height of the sidebar.
|
* Default height of the sidebar.
|
||||||
*/
|
*/
|
||||||
height?: number,
|
height?: number;
|
||||||
/**
|
/**
|
||||||
* Minimum sidebar height. Only used for top/bottom sidebars.
|
* Minimum sidebar height. Only used for top/bottom sidebars.
|
||||||
*/
|
*/
|
||||||
minHeight?: number,
|
minHeight?: number;
|
||||||
/**
|
/**
|
||||||
* Maximum sidebar height. Only used for top/bottom sidebars.
|
* Maximum sidebar height. Only used for top/bottom sidebars.
|
||||||
*/
|
*/
|
||||||
maxHeight?: number,
|
maxHeight?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background color.
|
* Background color.
|
||||||
*/
|
*/
|
||||||
backgroundColor?: string,
|
backgroundColor?: BackgroundColorProperty;
|
||||||
/**
|
/**
|
||||||
* Callback when the sidebar size ahs changed.
|
* Callback when the sidebar size ahs changed.
|
||||||
*/
|
*/
|
||||||
onResize?: (width: number, height: number) => void,
|
onResize?: (width: number, height: number) => void;
|
||||||
/**
|
/**
|
||||||
* Contents of the sidebar.
|
* Contents of the sidebar.
|
||||||
*/
|
*/
|
||||||
children?: React$Node,
|
children?: React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Class name to customise styling.
|
* Class name to customise styling.
|
||||||
*/
|
*/
|
||||||
className?: string,
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SidebarState = {|
|
type SidebarState = {
|
||||||
width?: number,
|
width?: WidthProperty<number>;
|
||||||
height?: number,
|
height?: HeightProperty<number>;
|
||||||
userChange: boolean,
|
userChange: boolean;
|
||||||
|};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A resizable sidebar.
|
* A resizable sidebar.
|
||||||
@@ -120,7 +134,12 @@ export default class Sidebar extends Component<SidebarProps, SidebarState> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {backgroundColor, onResize, position, children} = this.props;
|
const {backgroundColor, onResize, position, children} = this.props;
|
||||||
let height, minHeight, maxHeight, width, minWidth, maxWidth;
|
let height: number;
|
||||||
|
let minHeight: number;
|
||||||
|
let maxHeight: number;
|
||||||
|
let width: number;
|
||||||
|
let minWidth: number;
|
||||||
|
let maxWidth: number;
|
||||||
|
|
||||||
const resizable: {[key: string]: boolean} = {};
|
const resizable: {[key: string]: boolean} = {};
|
||||||
if (position === 'left') {
|
if (position === 'left') {
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {colors} from './colors.tsx';
|
import {colors} from './colors';
|
||||||
import Label from './Label.js';
|
import Label from './Label.js';
|
||||||
import styled from '../styled/index.js';
|
import styled from 'react-emotion';
|
||||||
|
|
||||||
export default styled(Label)({
|
export default styled(Label)({
|
||||||
color: colors.blackAlpha30,
|
color: colors.blackAlpha30,
|
||||||
@@ -116,8 +116,8 @@ export {default as View} from './components/View.js';
|
|||||||
export {default as ViewWithSize} from './components/ViewWithSize.js';
|
export {default as ViewWithSize} from './components/ViewWithSize.js';
|
||||||
export {default as Block} from './components/Block.js';
|
export {default as Block} from './components/Block.js';
|
||||||
export {default as FocusableBox} from './components/FocusableBox.js';
|
export {default as FocusableBox} from './components/FocusableBox.js';
|
||||||
export {default as Sidebar} from './components/Sidebar.js';
|
export {default as Sidebar} from './components/Sidebar.tsx';
|
||||||
export {default as SidebarLabel} from './components/SidebarLabel.js';
|
export {default as SidebarLabel} from './components/SidebarLabel.tsx';
|
||||||
export {default as Box} from './components/Box.js';
|
export {default as Box} from './components/Box.js';
|
||||||
export {default as FlexBox} from './components/FlexBox.js';
|
export {default as FlexBox} from './components/FlexBox.js';
|
||||||
export {default as FlexRow} from './components/FlexRow.js';
|
export {default as FlexRow} from './components/FlexRow.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user