From 7c5888557755f9110a0a8ea2f7bd9b6d556f7395 Mon Sep 17 00:00:00 2001 From: Francesco Giordano Date: Mon, 7 Aug 2017 14:49:59 +0200 Subject: [PATCH] add innerComponent and innerComponentProps --- src/ScrollView/README.md | 2 ++ src/ScrollView/ScrollView.d.ts | 6 ++++-- src/ScrollView/ScrollView.js | 23 ++++++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ScrollView/README.md b/src/ScrollView/README.md index c5de3bd06..be2176813 100644 --- a/src/ScrollView/README.md +++ b/src/ScrollView/README.md @@ -10,5 +10,7 @@ A scrollable view | **forceGemini** | Boolean | true | *optional*. Force ScrollView to use `gemini-scrollbar`s | | **component** | union(Function | String) | "div" | *optional*. Component to use as the wrapper | | **componentProps** | Object | | *optional*. Props to pass to the wrapper component | +| **innerComponent** | union(Function | String) | "div" | *optional*. Component to use as the inner wrapper | +| **innerComponentProps** | Object | | *optional*. Props to pass to the inner wrapper component | | **className** | String | | *optional*. ClassName to pass to the wrapper component | | **style** | Object | | *optional*. Style to pass to the wrapper component | \ No newline at end of file diff --git a/src/ScrollView/ScrollView.d.ts b/src/ScrollView/ScrollView.d.ts index f88be9b2b..8661671e9 100644 --- a/src/ScrollView/ScrollView.d.ts +++ b/src/ScrollView/ScrollView.d.ts @@ -1,12 +1,14 @@ import { CSSProperties, PureComponent, ComponentType } from 'react'; import { Type } from 'tcomb'; -export type ScrollViewProps = { // TODO(typo) not really working +export type ScrollViewProps = { // TODO(typo) not really working children: any, autoshow?: boolean, forceGemini?: boolean, component?: string | ComponentType, componentProps?: CP, + innerComponent?: string | ComponentType, + innerComponentProps?: ICP, className?: string, style?: CSSProperties } @@ -15,4 +17,4 @@ export const Props: { [key: string]: Type }; -export default class ScrollView extends PureComponent> {} +export default class ScrollView extends PureComponent> {} diff --git a/src/ScrollView/ScrollView.js b/src/ScrollView/ScrollView.js index ea932c9a2..0a863e7e7 100644 --- a/src/ScrollView/ScrollView.js +++ b/src/ScrollView/ScrollView.js @@ -11,6 +11,8 @@ export const Props = { forceGemini: t.maybe(t.Boolean), component: t.maybe(t.union([t.Function, t.String])), componentProps: t.maybe(t.Object), + innerComponent: t.maybe(t.union([t.Function, t.String])), + innerComponentProps: t.maybe(t.Object), className: t.maybe(t.String), style: t.maybe(t.Object) }; @@ -21,6 +23,8 @@ export const Props = { * @param forceGemini - force ScrollView to use `gemini-scrollbar`s * @param component - component to use as the wrapper * @param componentProps - props to pass to the wrapper component + * @param innerComponent - component to use as the inner wrapper + * @param innerComponentProps - props to pass to the inner wrapper component * @param className - className to pass to the wrapper component * @param style - style to pass to the wrapper component */ @@ -30,7 +34,8 @@ export default class ScrollView extends React.PureComponent { static defaultProps = { component: 'div', - forceGemini: true + forceGemini: true, + innerComponent: 'div' } /** @@ -66,12 +71,20 @@ export default class ScrollView extends React.PureComponent { children ); + innerWrapperRenderer = ({ children, ...innerWrapperProps }) => React.createElement( + this.props.innerComponent, + innerWrapperProps, + children + ); + getLocals() { - const { componentProps, className, style, children } = this.props; + const { componentProps, innerComponentProps, className, style, children } = this.props; return { children, Wrapper: this.wrapperRenderer, + InnerWrapper: this.innerWrapperRenderer, + innerWrapperProps: innerComponentProps, wrapperProps: { ...componentProps, style, @@ -80,7 +93,7 @@ export default class ScrollView extends React.PureComponent { }; } - template({ children, Wrapper, wrapperProps }) { + template({ children, Wrapper, wrapperProps, InnerWrapper, innerWrapperProps }) { return ( this.forceUpdate()}> @@ -92,9 +105,9 @@ export default class ScrollView extends React.PureComponent {
this.forceUpdate()}> -
+ {children} -
+