-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minimum width/height components.
- Loading branch information
1 parent
354ea70
commit 4b0526a
Showing
12 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
react-native/components/createMinimumHeightComponent/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
import { StyleSheet, View } from 'react-native' | ||
import type { MinimumHeightProps } from '../../types/MinimumHeightProps' | ||
|
||
/** | ||
* Creates a React component which has a minimum height. | ||
* @param minimumHeight The minimum Height of the component | ||
* @returns The created component. | ||
*/ | ||
export const createMinimumHeightComponent = ( | ||
minimumHeight: number | ||
): React.FunctionComponent<MinimumHeightProps> => { | ||
const styles = StyleSheet.create({ | ||
fillsContainer: { | ||
minHeight: minimumHeight, | ||
width: '100%' | ||
}, | ||
fitsContent: { | ||
minHeight: minimumHeight | ||
} | ||
}) | ||
|
||
const MinimumHeight: React.FunctionComponent<MinimumHeightProps> = ({ children, width }) => ( | ||
<View | ||
style={ | ||
width === 'fillsContainer' ? styles.fillsContainer : styles.fitsContent | ||
} | ||
pointerEvents="box-none" | ||
> | ||
{children} | ||
</View> | ||
) | ||
|
||
return MinimumHeight | ||
} |
29 changes: 29 additions & 0 deletions
29
react-native/components/createMinimumHeightComponent/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# `react-native-app-helpers/createMinimumHeightComponent` | ||
|
||
Creates a React component which has a minimum height. | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { createMinimumHeightComponent } from "react-native-app-helpers"; | ||
|
||
const ExampleComponent = createMinimumHeightComponent(243); | ||
|
||
const ExampleScreen = () => ( | ||
<ExampleComponent width="fillsContainer"> | ||
<Text>This is at least 243 tall and fills its container horizontally.</Text> | ||
</ExampleComponent> | ||
); | ||
``` | ||
|
||
```tsx | ||
import { createMinimumHeightComponent } from "react-native-app-helpers"; | ||
|
||
const ExampleComponent = createMinimumHeightComponent(243); | ||
|
||
const ExampleScreen = () => ( | ||
<ExampleComponent width="fitsContent"> | ||
<Text>This is at least 243 tall and fits its content horizontally.</Text> | ||
</ExampleComponent> | ||
); | ||
``` |
38 changes: 38 additions & 0 deletions
38
react-native/components/createMinimumHeightComponent/unit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react' | ||
import { Text, View } from 'react-native' | ||
import { | ||
createMinimumHeightComponent, | ||
unwrapRenderedFunctionComponent | ||
} from '../../..' | ||
|
||
test('renders as expected when filling its container vertically', () => { | ||
const Component = createMinimumHeightComponent(243) | ||
|
||
const rendered = ( | ||
<Component width="fillsContainer"> | ||
<Text>Example Content</Text> | ||
</Component> | ||
) | ||
|
||
expect(unwrapRenderedFunctionComponent(rendered)).toEqual( | ||
<View style={{ minHeight: 243, width: '100%' }} pointerEvents="box-none"> | ||
<Text>Example Content</Text> | ||
</View> | ||
) | ||
}) | ||
|
||
test('renders as expected when fitting its content vertically', () => { | ||
const Component = createMinimumHeightComponent(243) | ||
|
||
const rendered = ( | ||
<Component width="fitsContent"> | ||
<Text>Example Content</Text> | ||
</Component> | ||
) | ||
|
||
expect(unwrapRenderedFunctionComponent(rendered)).toEqual( | ||
<View style={{ minHeight: 243 }} pointerEvents="box-none"> | ||
<Text>Example Content</Text> | ||
</View> | ||
) | ||
}) |
35 changes: 35 additions & 0 deletions
35
react-native/components/createMinimumWidthComponent/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
import { StyleSheet, View } from 'react-native' | ||
import type { MinimumWidthProps } from '../../types/MinimumWidthProps' | ||
|
||
/** | ||
* Creates a React component which has a maximum width. | ||
* @param minimumWidth The maximum width of the component | ||
* @returns The created component. | ||
*/ | ||
export const createMinimumWidthComponent = ( | ||
minimumWidth: number | ||
): React.FunctionComponent<MinimumWidthProps> => { | ||
const styles = StyleSheet.create({ | ||
fillsContainer: { | ||
minWidth: minimumWidth, | ||
height: '100%' | ||
}, | ||
fitsContent: { | ||
minWidth: minimumWidth | ||
} | ||
}) | ||
|
||
const MinimumWidth: React.FunctionComponent<MinimumWidthProps> = ({ children, height }) => ( | ||
<View | ||
style={ | ||
height === 'fillsContainer' ? styles.fillsContainer : styles.fitsContent | ||
} | ||
pointerEvents="box-none" | ||
> | ||
{children} | ||
</View> | ||
) | ||
|
||
return MinimumWidth | ||
} |
29 changes: 29 additions & 0 deletions
29
react-native/components/createMinimumWidthComponent/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# `react-native-app-helpers/createMinimumWidthComponent` | ||
|
||
Creates a React component which has a minimum width. | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { createMinimumWidthComponent } from "react-native-app-helpers"; | ||
|
||
const ExampleComponent = createMinimumWidthComponent(243); | ||
|
||
const ExampleScreen = () => ( | ||
<ExampleComponent height="fillsContainer"> | ||
<Text>This is up to 243 wide and fills its container vertically.</Text> | ||
</ExampleComponent> | ||
); | ||
``` | ||
|
||
```tsx | ||
import { createMinimumWidthComponent } from "react-native-app-helpers"; | ||
|
||
const ExampleComponent = createMinimumWidthComponent(243); | ||
|
||
const ExampleScreen = () => ( | ||
<ExampleComponent height="fitsContent"> | ||
<Text>This is up to 243 wide and fits its content vertically.</Text> | ||
</ExampleComponent> | ||
); | ||
``` |
38 changes: 38 additions & 0 deletions
38
react-native/components/createMinimumWidthComponent/unit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react' | ||
import { Text, View } from 'react-native' | ||
import { | ||
createMinimumWidthComponent, | ||
unwrapRenderedFunctionComponent | ||
} from '../../..' | ||
|
||
test('renders as expected when filling its container vertically', () => { | ||
const Component = createMinimumWidthComponent(243) | ||
|
||
const rendered = ( | ||
<Component height="fillsContainer"> | ||
<Text>Example Content</Text> | ||
</Component> | ||
) | ||
|
||
expect(unwrapRenderedFunctionComponent(rendered)).toEqual( | ||
<View style={{ minWidth: 243, height: '100%' }} pointerEvents="box-none"> | ||
<Text>Example Content</Text> | ||
</View> | ||
) | ||
}) | ||
|
||
test('renders as expected when fitting its content vertically', () => { | ||
const Component = createMinimumWidthComponent(243) | ||
|
||
const rendered = ( | ||
<Component height="fitsContent"> | ||
<Text>Example Content</Text> | ||
</Component> | ||
) | ||
|
||
expect(unwrapRenderedFunctionComponent(rendered)).toEqual( | ||
<View style={{ minWidth: 243 }} pointerEvents="box-none"> | ||
<Text>Example Content</Text> | ||
</View> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type * as React from 'react' | ||
|
||
/** | ||
* Props to be given to minimum height components. | ||
*/ | ||
export type MinimumHeightProps = React.PropsWithChildren<{ | ||
/** | ||
* Describes how the component's width should be sized. | ||
*/ | ||
readonly width: 'fillsContainer' | 'fitsContent' | ||
}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# `react-native-app-helpers/MinimumHeightProps` | ||
|
||
Props to be given to minimum height components. | ||
|
||
## Usage | ||
|
||
```tsx | ||
import type { MinimumHeightProps } from "react-native-app-helpers"; | ||
|
||
const example: MinimumHeightProps = { | ||
width: "fitsContent", | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type * as React from 'react' | ||
|
||
/** | ||
* Props to be given to minimum width components. | ||
*/ | ||
export type MinimumWidthProps = React.PropsWithChildren<{ | ||
/** | ||
* Describes how the component's height should be sized. | ||
*/ | ||
readonly height: 'fillsContainer' | 'fitsContent' | ||
}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# `react-native-app-helpers/MinimumWidthProps` | ||
|
||
Props to be given to minimum width components. | ||
|
||
## Usage | ||
|
||
```tsx | ||
import type { MinimumWidthProps } from "react-native-app-helpers"; | ||
|
||
const example: MinimumWidthProps = { | ||
height: "fitsContent", | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters