UNPKG

react-onsenui

Version:

Onsen UI - React Components for Hybrid Cordova/PhoneGap Apps with Material Design and iOS UI components

217 lines (193 loc) 5.17 kB
import React from 'react'; import PropTypes from 'prop-types'; import 'onsenui/esm/elements/ons-splitter-side'; import onsCustomElement from '../onsCustomElement'; const deprecated = { onOpen: 'onPostOpen', onClose: 'onPostClose' }; const notAttributes = ['isOpen']; const Element = onsCustomElement('ons-splitter-side', {deprecated, notAttributes}); /** * @original ons-splitter-side * @category menu * @tutorial react/Reference/splitter * @description * [en] The SplitterContent element is used as a child element of Splitter. * It contains the main content of the page while SplitterSide contains the list. [/en] * [ja][/ja] * @example <Splitter> <SplitterSide side="left" width={200} swipeable={true}> <Page> Page Left </Page> </SplitterSide> <SplitterContent> <Page> Page Content </Page> </SplitterContent> <SplitterSide side="right" width={300} collapse={!this.state.showRight} isOpen={this.state.openRight} onClose={this.handleRightClose.bind(this)} onOpen={this.handleRightOpen.bind(this)} swipeable={true}> <Page> Page Right </Page> </SplitterSide> </Splitter> */ const SplitterSide = React.forwardRef((props, ref) => { const {width, ...rest} = props; // number values for width are deprecated but handle them safely to avoid breaking user code const realWidth = typeof width === 'number' ? `${width}px` : width; return ( <Element width={realWidth} ref={ref} {...rest} > {props.children} </Element> ); }); SplitterSide.propTypes = { /** * @name collapse * @type string * @description * [en] Specify the collapse behavior. Valid values are `"portrait"`, `"landscape"` or a media query. * The strings `"portrait"` and `"landscape"` means the view will collapse when device is in landscape or portrait orientation. * If the value is not defined, the view always be in `"collapse"` mode. [/en] * [ja][/ja] */ collapse: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), /** * @name swipeable * @type bool * @description * [en]Ennable swipe interaction on collapse mode.[/en] * [ja][/ja] */ swipeable: PropTypes.bool, /** * @name isOpen * @type bool * @description * [en]Specifies whether the menu is open.[/en] * [ja][/ja] */ isOpen: PropTypes.bool, /** * @name onPostOpen * @type function * @description * [en]Called after the menu is opened.[/en] * [ja][/ja] */ onPostOpen: PropTypes.func, /** * @name onOpen * @type function * @description * [en]DEPRECATED! Use `onPostOpen` instead.[/en] * [ja][/ja] */ onOpen: PropTypes.func, /** * @name onPostClose * @type function * @description * [en]Called after the menu is closed.[/en] * [ja][/ja] */ onPostClose: PropTypes.func, /** * @name onClose * @type function * @description * [en]DEPRECATED! Use `onPostClose` instead.[/en] * [ja][/ja] */ onClose: PropTypes.func, /** * @name side * @type string * @description * [en]Specify which side of the screen the SplitterSide element is located. Possible values are `"left"` and `"right"`.[/en] * [ja][/ja] */ side: PropTypes.oneOf(['left', 'right']), /** * @name swipeTargetWidth * @type number * @description * [en]The width of swipeable area calculated from the edge (in pixels). Use this to enable swipe only when the finger touch on the screen edge.[/en] * [ja][/ja] */ swipeTargetWidth: PropTypes.number, /** * @name width * @type number * @description * [en]Specifies the width of the menu. Can be specified in either pixels or as a percentage, e.g. `"90%"` or `"200px"`.[/en] * [ja][/ja] */ width: PropTypes.string, /** * @name animation * @type string * @required false * @description * [en]Specify the animation. Use one of `overlay`, `push`, `reveal`, or `default`.[/en] * [ja][/ja] */ animation: PropTypes.string, /** * @name animationOptions * @type object * @required false * @description * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en] * [ja][/ja] */ animationOptions: PropTypes.object, /** * @name openThreshold * @type object * @required false * @description * [en] Specify how much the menu needs to be swiped before opening. A value between `0` and `1`. [/en] * [ja][/ja] */ openThreshold: PropTypes.number, /** * @name onPreOpen * @type string * @description * [en] Called before the menu opens. [/en] * [ja][/ja] */ onPreOpen: PropTypes.func, /** * @name onPreClose * @type string * @description * [en] Called before the menu closes. [/en] * [ja][/ja] */ onPreClose: PropTypes.func, /** * @name onModeChange * @type string * @description * [en] Called after the component's mode changes. [/en] * [ja][/ja] */ onModeChange: PropTypes.func }; export default SplitterSide;