File tree 12 files changed +260
-0
lines changed
createMinimumHeightComponent
createMinimumWidthComponent 12 files changed +260
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ export { createImageBackgroundComponent } from './react-native/components/create
22
22
export { createInputComponent } from './react-native/components/createInputComponent'
23
23
export { createLimitedHeightComponent } from './react-native/components/createLimitedHeightComponent'
24
24
export { createLimitedWidthComponent } from './react-native/components/createLimitedWidthComponent'
25
+ export { createMinimumHeightComponent } from './react-native/components/createMinimumHeightComponent'
26
+ export { createMinimumWidthComponent } from './react-native/components/createMinimumWidthComponent'
25
27
export { createNullableEmailInputComponent } from './react-native/components/createNullableEmailInputComponent'
26
28
export { createNullableFloatInputComponent } from './react-native/components/createNullableFloatInputComponent'
27
29
export { createNullableIntegerInputComponent } from './react-native/components/createNullableIntegerInputComponent'
@@ -127,6 +129,8 @@ export type { KeyableTableCell } from './react-native/types/KeyableTableCell'
127
129
export type { LimitedHeightProps } from './react-native/types/LimitedHeightProps'
128
130
export type { LimitedWidthProps } from './react-native/types/LimitedWidthProps'
129
131
export type { LoggerInterface } from './react-native/types/LoggerInterface'
132
+ export type { MinimumHeightProps } from './react-native/types/MinimumHeightProps'
133
+ export type { MinimumWidthProps } from './react-native/types/MinimumWidthProps'
130
134
export type { NonKeyableTableCell } from './react-native/types/NonKeyableTableCell'
131
135
export type { NullableEmailInputProps } from './react-native/types/NullableEmailInputProps'
132
136
export type { NullableFloatInputProps } from './react-native/types/NullableFloatInputProps'
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { StyleSheet , View } from 'react-native'
3
+ import type { MinimumHeightProps } from '../../types/MinimumHeightProps'
4
+
5
+ /**
6
+ * Creates a React component which has a minimum height.
7
+ * @param minimumHeight The minimum Height of the component
8
+ * @returns The created component.
9
+ */
10
+ export const createMinimumHeightComponent = (
11
+ minimumHeight : number
12
+ ) : React . FunctionComponent < MinimumHeightProps > => {
13
+ const styles = StyleSheet . create ( {
14
+ fillsContainer : {
15
+ minHeight : minimumHeight ,
16
+ width : '100%'
17
+ } ,
18
+ fitsContent : {
19
+ minHeight : minimumHeight
20
+ }
21
+ } )
22
+
23
+ const MinimumHeight : React . FunctionComponent < MinimumHeightProps > = ( { children, width } ) => (
24
+ < View
25
+ style = {
26
+ width === 'fillsContainer' ? styles . fillsContainer : styles . fitsContent
27
+ }
28
+ pointerEvents = "box-none"
29
+ >
30
+ { children }
31
+ </ View >
32
+ )
33
+
34
+ return MinimumHeight
35
+ }
Original file line number Diff line number Diff line change
1
+ # ` react-native-app-helpers/createMinimumHeightComponent `
2
+
3
+ Creates a React component which has a minimum height.
4
+
5
+ ## Usage
6
+
7
+ ``` tsx
8
+ import { createMinimumHeightComponent } from " react-native-app-helpers" ;
9
+
10
+ const ExampleComponent = createMinimumHeightComponent (243 );
11
+
12
+ const ExampleScreen = () => (
13
+ <ExampleComponent width = " fillsContainer" >
14
+ <Text >This is at least 243 tall and fills its container horizontally.</Text >
15
+ </ExampleComponent >
16
+ );
17
+ ```
18
+
19
+ ``` tsx
20
+ import { createMinimumHeightComponent } from " react-native-app-helpers" ;
21
+
22
+ const ExampleComponent = createMinimumHeightComponent (243 );
23
+
24
+ const ExampleScreen = () => (
25
+ <ExampleComponent width = " fitsContent" >
26
+ <Text >This is at least 243 tall and fits its content horizontally.</Text >
27
+ </ExampleComponent >
28
+ );
29
+ ```
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { Text , View } from 'react-native'
3
+ import {
4
+ createMinimumHeightComponent ,
5
+ unwrapRenderedFunctionComponent
6
+ } from '../../..'
7
+
8
+ test ( 'renders as expected when filling its container vertically' , ( ) => {
9
+ const Component = createMinimumHeightComponent ( 243 )
10
+
11
+ const rendered = (
12
+ < Component width = "fillsContainer" >
13
+ < Text > Example Content</ Text >
14
+ </ Component >
15
+ )
16
+
17
+ expect ( unwrapRenderedFunctionComponent ( rendered ) ) . toEqual (
18
+ < View style = { { minHeight : 243 , width : '100%' } } pointerEvents = "box-none" >
19
+ < Text > Example Content</ Text >
20
+ </ View >
21
+ )
22
+ } )
23
+
24
+ test ( 'renders as expected when fitting its content vertically' , ( ) => {
25
+ const Component = createMinimumHeightComponent ( 243 )
26
+
27
+ const rendered = (
28
+ < Component width = "fitsContent" >
29
+ < Text > Example Content</ Text >
30
+ </ Component >
31
+ )
32
+
33
+ expect ( unwrapRenderedFunctionComponent ( rendered ) ) . toEqual (
34
+ < View style = { { minHeight : 243 } } pointerEvents = "box-none" >
35
+ < Text > Example Content</ Text >
36
+ </ View >
37
+ )
38
+ } )
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { StyleSheet , View } from 'react-native'
3
+ import type { MinimumWidthProps } from '../../types/MinimumWidthProps'
4
+
5
+ /**
6
+ * Creates a React component which has a maximum width.
7
+ * @param minimumWidth The maximum width of the component
8
+ * @returns The created component.
9
+ */
10
+ export const createMinimumWidthComponent = (
11
+ minimumWidth : number
12
+ ) : React . FunctionComponent < MinimumWidthProps > => {
13
+ const styles = StyleSheet . create ( {
14
+ fillsContainer : {
15
+ minWidth : minimumWidth ,
16
+ height : '100%'
17
+ } ,
18
+ fitsContent : {
19
+ minWidth : minimumWidth
20
+ }
21
+ } )
22
+
23
+ const MinimumWidth : React . FunctionComponent < MinimumWidthProps > = ( { children, height } ) => (
24
+ < View
25
+ style = {
26
+ height === 'fillsContainer' ? styles . fillsContainer : styles . fitsContent
27
+ }
28
+ pointerEvents = "box-none"
29
+ >
30
+ { children }
31
+ </ View >
32
+ )
33
+
34
+ return MinimumWidth
35
+ }
Original file line number Diff line number Diff line change
1
+ # ` react-native-app-helpers/createMinimumWidthComponent `
2
+
3
+ Creates a React component which has a minimum width.
4
+
5
+ ## Usage
6
+
7
+ ``` tsx
8
+ import { createMinimumWidthComponent } from " react-native-app-helpers" ;
9
+
10
+ const ExampleComponent = createMinimumWidthComponent (243 );
11
+
12
+ const ExampleScreen = () => (
13
+ <ExampleComponent height = " fillsContainer" >
14
+ <Text >This is up to 243 wide and fills its container vertically.</Text >
15
+ </ExampleComponent >
16
+ );
17
+ ```
18
+
19
+ ``` tsx
20
+ import { createMinimumWidthComponent } from " react-native-app-helpers" ;
21
+
22
+ const ExampleComponent = createMinimumWidthComponent (243 );
23
+
24
+ const ExampleScreen = () => (
25
+ <ExampleComponent height = " fitsContent" >
26
+ <Text >This is up to 243 wide and fits its content vertically.</Text >
27
+ </ExampleComponent >
28
+ );
29
+ ```
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { Text , View } from 'react-native'
3
+ import {
4
+ createMinimumWidthComponent ,
5
+ unwrapRenderedFunctionComponent
6
+ } from '../../..'
7
+
8
+ test ( 'renders as expected when filling its container vertically' , ( ) => {
9
+ const Component = createMinimumWidthComponent ( 243 )
10
+
11
+ const rendered = (
12
+ < Component height = "fillsContainer" >
13
+ < Text > Example Content</ Text >
14
+ </ Component >
15
+ )
16
+
17
+ expect ( unwrapRenderedFunctionComponent ( rendered ) ) . toEqual (
18
+ < View style = { { minWidth : 243 , height : '100%' } } pointerEvents = "box-none" >
19
+ < Text > Example Content</ Text >
20
+ </ View >
21
+ )
22
+ } )
23
+
24
+ test ( 'renders as expected when fitting its content vertically' , ( ) => {
25
+ const Component = createMinimumWidthComponent ( 243 )
26
+
27
+ const rendered = (
28
+ < Component height = "fitsContent" >
29
+ < Text > Example Content</ Text >
30
+ </ Component >
31
+ )
32
+
33
+ expect ( unwrapRenderedFunctionComponent ( rendered ) ) . toEqual (
34
+ < View style = { { minWidth : 243 } } pointerEvents = "box-none" >
35
+ < Text > Example Content</ Text >
36
+ </ View >
37
+ )
38
+ } )
Original file line number Diff line number Diff line change
1
+ import type * as React from 'react'
2
+
3
+ /**
4
+ * Props to be given to minimum height components.
5
+ */
6
+ export type MinimumHeightProps = React . PropsWithChildren < {
7
+ /**
8
+ * Describes how the component's width should be sized.
9
+ */
10
+ readonly width : 'fillsContainer' | 'fitsContent'
11
+ } >
Original file line number Diff line number Diff line change
1
+ # ` react-native-app-helpers/MinimumHeightProps `
2
+
3
+ Props to be given to minimum height components.
4
+
5
+ ## Usage
6
+
7
+ ``` tsx
8
+ import type { MinimumHeightProps } from " react-native-app-helpers" ;
9
+
10
+ const example: MinimumHeightProps = {
11
+ width: " fitsContent" ,
12
+ };
13
+ ```
Original file line number Diff line number Diff line change
1
+ import type * as React from 'react'
2
+
3
+ /**
4
+ * Props to be given to minimum width components.
5
+ */
6
+ export type MinimumWidthProps = React . PropsWithChildren < {
7
+ /**
8
+ * Describes how the component's height should be sized.
9
+ */
10
+ readonly height : 'fillsContainer' | 'fitsContent'
11
+ } >
Original file line number Diff line number Diff line change
1
+ # ` react-native-app-helpers/MinimumWidthProps `
2
+
3
+ Props to be given to minimum width components.
4
+
5
+ ## Usage
6
+
7
+ ``` tsx
8
+ import type { MinimumWidthProps } from " react-native-app-helpers" ;
9
+
10
+ const example: MinimumWidthProps = {
11
+ height: " fitsContent" ,
12
+ };
13
+ ```
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ import { createTextComponent } from "react-native-app-helpers";
41
41
- [ createInputComponent] ( ./react-native/components/createInputComponent/readme.md )
42
42
- [ createLimitedHeightComponent] ( ./react-native/components/createLimitedHeightComponent/readme.md )
43
43
- [ createLimitedWidthComponent] ( ./react-native/components/createLimitedWidthComponent/readme.md )
44
+ - [ createMinimumHeightComponent] ( ./react-native/components/createMinimumHeightComponent/readme.md )
45
+ - [ createMinimumWidthComponent] ( ./react-native/components/createMinimumWidthComponent/readme.md )
44
46
- [ createNullableEmailInputComponent] ( ./react-native/components/createNullableEmailInputComponent/readme.md )
45
47
- [ createNullableFloatInputComponent] ( ./react-native/components/createNullableFloatInputComponent/readme.md )
46
48
- [ createNullableIntegerInputComponent] ( ./react-native/components/createNullableIntegerInputComponent/readme.md )
@@ -145,6 +147,8 @@ import { createTextComponent } from "react-native-app-helpers";
145
147
- [ KeyableTableCell] ( ./react-native/types/KeyableTableCell/readme.md )
146
148
- [ LimitedHeightProps] ( ./react-native/types/LimitedHeightProps/readme.md )
147
149
- [ LimitedWidthProps] ( ./react-native/types/LimitedWidthProps/readme.md )
150
+ - [ MinimumHeightProps] ( ./react-native/types/MinimumHeightProps/readme.md )
151
+ - [ MinimumWidthProps] ( ./react-native/types/MinimumWidthProps/readme.md )
148
152
- [ NonKeyableTableCell] ( ./react-native/types/NonKeyableTableCell/readme.md )
149
153
- [ NullableEmailInputProps] ( ./react-native/types/NullableEmailInputProps/readme.md )
150
154
- [ NullableFloatInputProps] ( ./react-native/types/NullableFloatInputProps/readme.md )
You can’t perform that action at this time.
0 commit comments