Skip to content

Commit 4b0526a

Browse files
committed
Add minimum width/height components.
1 parent 354ea70 commit 4b0526a

File tree

12 files changed

+260
-0
lines changed

12 files changed

+260
-0
lines changed

index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export { createImageBackgroundComponent } from './react-native/components/create
2222
export { createInputComponent } from './react-native/components/createInputComponent'
2323
export { createLimitedHeightComponent } from './react-native/components/createLimitedHeightComponent'
2424
export { createLimitedWidthComponent } from './react-native/components/createLimitedWidthComponent'
25+
export { createMinimumHeightComponent } from './react-native/components/createMinimumHeightComponent'
26+
export { createMinimumWidthComponent } from './react-native/components/createMinimumWidthComponent'
2527
export { createNullableEmailInputComponent } from './react-native/components/createNullableEmailInputComponent'
2628
export { createNullableFloatInputComponent } from './react-native/components/createNullableFloatInputComponent'
2729
export { createNullableIntegerInputComponent } from './react-native/components/createNullableIntegerInputComponent'
@@ -127,6 +129,8 @@ export type { KeyableTableCell } from './react-native/types/KeyableTableCell'
127129
export type { LimitedHeightProps } from './react-native/types/LimitedHeightProps'
128130
export type { LimitedWidthProps } from './react-native/types/LimitedWidthProps'
129131
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'
130134
export type { NonKeyableTableCell } from './react-native/types/NonKeyableTableCell'
131135
export type { NullableEmailInputProps } from './react-native/types/NullableEmailInputProps'
132136
export type { NullableFloatInputProps } from './react-native/types/NullableFloatInputProps'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
```

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import { createTextComponent } from "react-native-app-helpers";
4141
- [createInputComponent](./react-native/components/createInputComponent/readme.md)
4242
- [createLimitedHeightComponent](./react-native/components/createLimitedHeightComponent/readme.md)
4343
- [createLimitedWidthComponent](./react-native/components/createLimitedWidthComponent/readme.md)
44+
- [createMinimumHeightComponent](./react-native/components/createMinimumHeightComponent/readme.md)
45+
- [createMinimumWidthComponent](./react-native/components/createMinimumWidthComponent/readme.md)
4446
- [createNullableEmailInputComponent](./react-native/components/createNullableEmailInputComponent/readme.md)
4547
- [createNullableFloatInputComponent](./react-native/components/createNullableFloatInputComponent/readme.md)
4648
- [createNullableIntegerInputComponent](./react-native/components/createNullableIntegerInputComponent/readme.md)
@@ -145,6 +147,8 @@ import { createTextComponent } from "react-native-app-helpers";
145147
- [KeyableTableCell](./react-native/types/KeyableTableCell/readme.md)
146148
- [LimitedHeightProps](./react-native/types/LimitedHeightProps/readme.md)
147149
- [LimitedWidthProps](./react-native/types/LimitedWidthProps/readme.md)
150+
- [MinimumHeightProps](./react-native/types/MinimumHeightProps/readme.md)
151+
- [MinimumWidthProps](./react-native/types/MinimumWidthProps/readme.md)
148152
- [NonKeyableTableCell](./react-native/types/NonKeyableTableCell/readme.md)
149153
- [NullableEmailInputProps](./react-native/types/NullableEmailInputProps/readme.md)
150154
- [NullableFloatInputProps](./react-native/types/NullableFloatInputProps/readme.md)

0 commit comments

Comments
 (0)