hypertoxin
Version:
A themeable ReactNative component library for developing native apps
944 lines (818 loc) • 110 kB
Markdown
# [Hypertoxin](https://github.com/tuantle/hypertoxin)

[](https://www.npmjs.com/package/hypertoxin)
[](https://www.npmjs.com/package/hypertoxin)
## A themeable and declarative React Native component library for developing native mobile apps.
<p align="center">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-home-default-theme.png">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-home-bubble-theme.png">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-home-coffee-theme.png">
</p>
<p align="center">
<em>Screenshots with some example themes</em>
</p>
<p align="center">
<img width="35%" height="35%" src="/assets/screen-records/theme-switching.gif">
</p>
<p align="center">
<em>Dynamic theme switching</em>
</p>
<p align="center">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-shopping-home-default-theme.png">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-shopping-cart-default-theme.png">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-shopping-checkout-default-theme.png">
</p>
<p align="center">
<em>Mock up shopping app screenshots with default theme</em>
</p>
<p align="center">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-shopping-home-bubble-theme.png">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-shopping-cart-bubble-theme.png">
<img width="25%" height="25%" src="/assets/screenshots/screenshot-shopping-checkout-bubble-theme.png">
</p>
<p align="center">
<em>Mock up shopping app screenshots with bubble theme</em>
</p>
* * *
## Published Open-source App [Virida](https://github.com/tuantle/virida-air-quality-monitor-app) built with Hypertoxin component library.
<p align="center">
<img width="20%" height="20%" src="https://github.com/tuantle/virida-air-quality-monitor-app/blob/master/assets/screenshots/iphone-xs-max-1.png">
<img width="20%" height="20%" src="https://github.com/tuantle/virida-air-quality-monitor-app/blob/master/assets/screenshots/iphone-xs-max-2.png">
<img width="20%" height="20%" src="https://github.com/tuantle/virida-air-quality-monitor-app/blob/master/assets/screenshots/iphone-xs-max-3.png">
<img width="20%" height="20%" src="https://github.com/tuantle/virida-air-quality-monitor-app/blob/master/assets/screenshots/iphone-xs-max-4.png">
</p>
[Checkout Virida on the app store!](https://apps.apple.com/us/app/virida/id1315223443?ls=1)
* * *
- [Documentations](#documentations)
- [Button Components](#button-components)
- [Field Components](#field-components)
- [Text Components](#text-components)
- [Image Components](#image-components)
- [Layout Components](#layout-components)
- [Screen Components](#screen-components)
- [Using Room Property](#using-room-property)
- [Using Action Property](#using-action-property)
- [Using Exclusions Property](##using-exclusions-property)
- [Animation API](#animation-api)
- [Theme Customization](#theme-customization)
- [Todo](#todo)
- [Change Log](#change-log)
- [License](#license)
Documeantations are still WIP.
* * *
# Installation
```bash
$ npm install hypertoxin --save
```
# Demo & Showcase
Hypertoxin comes with a full demo that you can build and run on your device or simulator. All of the code examples in this README are from the demo. To build the demo for iOS,
```bash
$ cd hypertoxin/demo
npm install
```
This will install the required modules such as React Native, Hypertoxin, [Hyperflow](https://github.com/tuantle/hyperflow), and others. Then open `hypertoxin/demo/ios` with Xcode, select your ios simulator/device, and build. The default build scheme is release.
When use successfully, you will see the following on your device or simulator.
<p align="center">
<img width="35%" height="35%" src="/assets/screen-records/demo.gif">
</p>
<p align="center">
<a href="https://github.com/tuantle/hypertoxin/tree/develop/demo/src"><em>Demo source</em></a>
</p>
# Usage
The imported `hypertoxin` object is consists of `Ht`, `ThemeContext`, and `Theme`. `Ht` is an object containing all available components. `Theme` is the default global theme object which is used as a reference for making custom themes. `ThemeContext` the a react context provider which is required for setting custom themes.
```js
import React, { Component } from 'react';
import ReactNative from 'react-native'
import { Ht, ThemeContext, Theme as DefaultTheme } from 'hyperflow';
// All current available components with more to come. See todo list.
const {
FlatButton,
RaisedButton,
AreaButton,
AvatarImage,
IconImage,
CoverImage,
TextField,
SearchField,
HorizontalDivider,
VeriticalDivider,
HeadlineText,
TitleText,
SubtitleText,
InfoText,
CaptionText,
BodyScreen,
HeaderScreen,
RowLayout,
ColumnLayout
} = Ht;
export default class App extends Component {
render() {
return (
<ThemeContext.Provider value = {{
DefaultTheme // Modify this DefaultTheme object to make your own custom theme
}}>
// Top level app component goes here...
</ThemeContext.Provider>
);
}
}
```
* * *
# Documentations
## Button Components
<p align="center">
<img width="35%" height="35%" src="/assets/screen-records/buttons.gif">
</p>
Hypertoxin has three button components, [_FlatButton_](https://github.com/tuantle/hypertoxin/blob/develop/src/components/buttons/flat-button.js), [_RaisedButton_](https://github.com/tuantle/hypertoxin/blob/develop/src/components/buttons/raised-button.js), and [_AreaButton_](https://github.com/tuantle/hypertoxin/blob/develop/src/components/buttons/area-button.js)
#### Flat Button Properties
A standard button component that can be styled as an icon, a clear, or simply a flat opaque button.
| Prop | Type | Default | Description |
| ---------------- | ---------------------- | -------- | -----------
| exclusions | array of string | [] | Set which properties from parent component to exclude. See [Using Exclusions Property](#using-exclusions-property) section for details |
| room | string | `none` | Set button's room with respect to parent component which can be one of `none`, `content-left`, `content-middle`, `content-right`, `content-bottom`, `content-top`, `media`. See [Using Room Property](#using-room-property) section for details |
| action | string, object | `none` | Set button's onPress callback action to be defined by the parent component. This property is used when a button is set as a child search button for parent components such as SearchField, TextField, or HeaderScreen. See [Using Action Property](#using-action-property) section for details |
| shade | string, object | `themed` | Set button's shade theme, can be `themed`, `light`, or `dark` |
| overlay | string | `themed` | Set button's overlay style which can be one of `themed`, `opaque`, `translucent`, `translucent-outline`, `transparent`, `transparent-outline` |
| corner | string, number, object | `themed` | Set button's corner styles. As a number, border radius = corner. Set corner as an object for more control. For example `corner = { topLeft: 0.1, topRight: 0.1, bottomLeft: 0.1, bottomRight: 0.1}` |
| size | string | `themed` | Set button's size which can be one of `themed`, `small`, `normal`, `large` |
| margin | string, number, object | None | Set button's margin styles. As a number, the margin is equally set around the button. Set margin as an object for more control. For example `margin = { top: 5, bottom: 5, left: 5, right: 5, horizontal: 5, vertical: 5}` |
| disabled | boolean | false | Disable the button |
| busy | boolean | false | Enable button busy activity indicator |
| rippled | boolean, string | `themed` | Enable button ripple animation |
| label | string | None | Button string label |
| color | string | `themed` | Set button's color style. Can be hex string, default color name, or themed color name |
| debounced | boolean | false | Enable button debouncing at 250 ms |
| onPress | function | None | Calls when button is pressed |
| style | object | None | Flat button style is an object with the following properties: `container: {...}, contentLeftRoom: {...}, contentMiddleRoom: {...}, contentRightRoom: {...}, badgeRoom: {...}, activityIndicatorRoom: {...}, label: {...}, ripple: {...}`. Standard React Native style properties go inside these properties. Changes to these properties will override the global theme. See [default style object](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/buttons/flat-button.js#L53) |
#### Raised Button Properties
Raised button is similar to flat button with the exceptions that it has permanent drop shadow and opaque color.
| Prop | Type | Default | Description |
| ---------------- | ---------------------- | -------- | ----------- |
| exclusions | array of string | [] | Set which properties from parent component to exclude. See [Using Exclusions Property](#using-exclusions-property) section for details |
| room | string | `none` | Set button's room with respect to parent component which can be one of `none`, `content-left`, `content-middle`, `content-right`, `content-bottom`, `content-top`, `media`. See [Using Room Property](#using-room-property) section for details |
| action | string, object | `none` | Set button's onPress callback action to be defined by the parent component. This property is used when a button is set as a child search button for parent components such as SearchField, TextField, or HeaderScreen. See [Using Action Property](#using-action-property) section for details |
| shade | string, object | `themed` | Set button's shade theme, can be `themed`, `light`, or `dark` |
| corner | string, number, object | `themed` | Set button's corner styles. As a number, border radius = corner. Set corner as an object for more control. For example `corner = { topLeft: 0.1, topRight: 0.1, bottomLeft: 0.1, bottomRight: 0.1}` |
| size | string | `themed` | Set button's size which can be one of `themed`, `small`, `normal`, `large` |
| margin | string, number, object | None | Set button's margin styles. As a number, the margin is equally set around the button. Set margin as an object for more control. For example `margin = { top: 5, bottom: 5, left: 5, right: 5, horizontal: 5, vertical: 5}` |
| disabled | boolean | false | Disable the button |
| busy | boolean | false | Enable button busy activity indicator |
| rippled | boolean, string | `themed` | Enable button ripple animation |
| label | string | None | Button string label |
| color | string | `themed` | Set button's color style. Can be hex string, default color name, or themed color name |
| debounced | boolean | false | Enable button debouncing at 250 ms |
| onPress | function | None | Calls when button is pressed |
| style | object | None | Raised button style is an object with the following properties: `container: {...}, contentLeftRoom: {...}, contentMiddleRoom: {...}, contentRightRoom: {...}, badgeRoom: {...}, activityIndicatorRoom: {...}, label: {...}, ripple: {...}`. Standard React Native style properties go inside these properties. Changes to these properties will override the global theme. See [default style object](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/buttons/raised-button.js#L63) |
#### Area Button Properties
Unlike flat or raised button, area button was intended mainly as a list item component. Therefore it works nicely as a selectable item in a typical list view.
| Prop | Type | Default | Description |
| ---------------- | ---------------------- | -------- | ----------- |
| exclusions | array of string | [] | Set which properties from parent component to exclude. See [Using Exclusions Property](#using-exclusions-property) section for details |
| room | string | `none` | Set button's room with respect to parent component which can be one of `none`, `content-left`, `content-middle`, `content-right`, `content-bottom`, `content-top`, `media`. See [Using Room Property](#using-room-property) section for details |
| action | string, object | `none` | Set button's onPress callback action to be defined by the parent component. This property is used when a button is set as a child search button for parent components such as SearchField, TextField, or HeaderScreen. See [Using Action Property](#using-action-property) section for details |
| shade | string, object | `themed` | Set button's shade theme, can be `themed`, `light`, or `dark` |
| overlay | string | `themed` | Set button's overlay style which can be one of `themed`, `opaque`, `translucent`, `transparent` |
| size | string | `themed` | Set button's size which can be one of `themed`, `small`, `normal`, `large` |
| margin | string, number, object | None | Set button's margin styles. As a number, the margin is equally set around the button. Set margin as an object for more control. For example `margin = { top: 5, bottom: 5, left: 5, right: 5, horizontal: 5, vertical: 5}` |
| disabled | boolean | false | Disable the button |
| rippled | boolean, string | `themed` | Enable button ripple animation |
| debounced | boolean | false | Enable button debouncing at 250 ms |
| onPress | function | None | Calls when button is pressed |
| style | object | None | Area button style is an object with the following properties: `container: {...}, contentLeftRoom: {...}, contentRightRoom: {...}, ripple: {...}`. Unlike flat and raised buttons, there is no middle room styling. Standard React Native style properties go inside these properties. Changes to these properties will override the global theme. See [default style object](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/buttons/area-button.js#L55) |
_Note: `themed` property indicates using values defined by the global theme provider._
By default, flat, raised, and area button components pass `shade`, `size`, `color` (flat & raised only), and `disabled` properties down to their child components and at the same time set `margin = { 0 }` and `indentation = { 0 }` properties onto its children. This behavior can be override by child components with the `exclusions` property. . See [Using Exclusions Property](#using-exclusions-property) section for details.
#
<p align="center">
<img width="50%" height="50%" src="/assets/images/flat-raised-button-compositions.png">
</p>
<p align="center">
<em>Flat & raised button internal view compositions diagram</em>
</p>
<p align="center">
<img width="50%" height="50%" src="/assets/images/area-button-compositions.png">
</p>
<p align="center">
<em>Area button internal view compositions diagram</em>
</p>
Flat & raised button animated internal view composition reference names. See [Animation API](#animation-api) for details:
- `animated-container-view`
- `animated-content-left-room-view`
- `animated-content-middle-room-view`
- `animated-content-right-room-view`
- `animated-activity-indicator-room-view`
- `animated-badge-room-view`
Area button animated internal view composition reference names. See [Animation API](#animation-api) for details:
- `animated-container-view`
- `animated-content-left-room-view`
- `animated-content-right-room-view`
Flat, raised & area button methods & callbacks:
- `animate` - See [Animation API](#animation-api) for details
- `onPress` - Button press callback
* arguments:
- `event` (object) - React Native event
* return: None
#
#### Flat Button Examples
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/flat-buttons.png">
</p>
<p align="center">
<em>Standard flat buttons with colors defined by global theme</em>
</p>
```jsx
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'default' />
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'primary' />
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'secondary' />
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'accent' />
```
Clear buttons can be created when styling flat buttons with `overlay = 'transparent'` property. The component will auto-adjust the label text color accordingly.
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/clear-buttons.png">
</p>
<p align="center">
<em>Standard clear buttons with colors defined by global theme</em>
</p>
```jsx
<FlatButton overlay = 'transparent' label = 'BUTTON' color = 'default' />
<FlatButton overlay = 'transparent' label = 'BUTTON' color = 'primary' />
<FlatButton overlay = 'transparent' label = 'BUTTON' color = 'secondary' />
<FlatButton overlay = 'transparent' label = 'BUTTON' color = 'accent' />
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/flat-buttons-with-l-icons.png">
</p>
<p align="center">
<em>Flat buttons in 3 available sizes with icon images to the left</em>
</p>
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/flat-buttons-with-r-icons.png">
</p>
<p align="center">
<em>And icon images to the right</em>
</p>
To add icon image to button, add a child icon image component (more details for IconImage component below) with a content `room` property. All button components have 4 child rooms, `content-left`, `content-middle`, `content-right`, and `badge`.
Internally, a room is just a convenient way for creating child Views, thus allowing the JSX code to be less clutter and much more declarative.
```jsx
<FlatButton overlay = 'opaque' size = 'small' label = 'SMALL' color = 'primary' >
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
<FlatButton overlay = 'opaque' size = 'normal' label = 'NORMAL' color = 'secondary' >
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
<FlatButton overlay = 'opaque' size = 'large' label = 'LARGE' color = 'accent' >
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
<FlatButton overlay = 'opaque' size = 'small' label = 'SMALL' color = 'primary' >
<IconImage room = 'content-right' source = 'profile' />
</FlatButton>
<FlatButton overlay = 'opaque' size = 'normal' label = 'NORMAL' color = 'secondary' >
<IconImage room = 'content-right' source = 'profile' />
</FlatButton>
<FlatButton overlay = 'opaque' size = 'large' label = 'LARGE' color = 'accent' >
<IconImage room = 'content-right' source = 'profile' />
</FlatButton>
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/clear-buttons-with-l-icons.png">
<img width="50%" height="50%" src="/assets/screenshots/clear-buttons-with-r-icons.png">
</p>
<p align="center">
<em>Clear buttons in 3 available sizes with icon images to the left & right</em>
</p>
```jsx
<FlatButton overlay = 'transparent' size = 'small' label = 'SMALL' color = 'primary' >
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'normal' label = 'NORMAL' color = 'secondary' >
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'large' label = 'LARGE' color = 'accent' >
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'small' label = 'SMALL' color = 'primary' >
<IconImage room = 'content-right' source = 'profile' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'normal' label = 'NORMAL' color = 'secondary' >
<IconImage room = 'content-right' source = 'profile' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'large' label = 'LARGE' color = 'accent' >
<IconImage room = 'content-right' source = 'profile' />
</FlatButton>
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/flat-buttons-with-corners.png">
</p>
<p align="center">
<em>A few examples of corner styling</em>
</p>
```jsx
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'primary' corner = 'sharp' />
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'secondary' corner = 'round' />
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'accent' corner = 'circular' />
```
To create a button with a badge, add a child text component with a `room = 'badge'`.
<p align="center">
<img width="20%" height="20%" src="/assets/screenshots/flat-button-with-badge.png">
</p>
```jsx
<FlatButton overlay = 'opaque' label = 'BUTTON' color = 'primary' >
<InfoText room = 'badge' color = 'white' > 0 </InfoText>
<IconImage room = 'content-left' source = 'home' />
</FlatButton>
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/flat-buttons-with-outlines.png">
</p>
<p align="center">
<em>Flat outlined buttons when styled with `overlay = 'transparent-outline'` property
</em>
</p>
```jsx
<FlatButton overlay = 'transparent-outline' size = 'small' label = 'BUTTON' color = 'primary' corner = 'sharp' >
<IconImage room = 'content-left' source = 'star' />
</FlatButton>
<FlatButton overlay = 'transparent-outline' size = 'normal' label = 'BUTTON' color = 'secondary' corner = 'round' >
<IconImage room = 'content-right' source = 'star' />
</FlatButton>
<FlatButton overlay = 'transparent-outline' size = 'large' label = 'BUTTON' color = 'accent' corner = 'circular' />
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/icon-buttons.png">
</p>
<p align="center">
<em>Flat buttons styled as icon buttons</em>
</p>
```jsx
<FlatButton overlay = 'transparent' size = 'small' color = 'primary' corner = 'circular' >
<IconImage room = 'content-middle' source = 'favorite' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'normal' color = 'secondary' corner = 'circular' >
<IconImage room = 'content-middle' source = 'favorite' />
</FlatButton>
<FlatButton overlay = 'transparent' size = 'large' color = 'accent' corner = 'circular' >
<IconImage room = 'content-middle' source = 'favorite' />
</FlatButton>
<FlatButton overlay = 'transparent' color = { Theme.color.palette.purple } corner = 'circular' >
<IconImage room = 'content-middle' source = 'smiley-face' />
</FlatButton>
<FlatButton overlay = 'transparent' color = { Theme.color.palette.green } corner = 'circular' >
<IconImage room = 'content-middle' source = 'star' />
</FlatButton>
```
#
#### Raised Button Examples
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/raised-buttons.png">
</p>
<p align="center">
<em>Standard raised buttons with colors defined by global theme</em>
</p>
```jsx
<RaisedButton label = 'BUTTON' color = 'default' />
<RaisedButton label = 'BUTTON' color = 'primary' />
<RaisedButton label = 'BUTTON' color = 'secondary' />
<RaisedButton label = 'BUTTON' color = 'accent' />
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/raised-buttons-with-l-icons.png">
<img width="50%" height="50%" src="/assets/screenshots/raised-buttons-with-r-icons.png">
</p>
<p align="center">
<em>Raised buttons in 3 available sizes with icon images to the left & right</em>
</p>
```jsx
<RaisedButton size = 'small' label = 'SMALL' color = 'primary' >
<IconImage room = 'content-left' source = 'home' />
</RaisedButton>
<RaisedButton size = 'normal' label = 'NORMAL' color = 'secondary' >
<IconImage room = 'content-left' source = 'home' />
</RaisedButton>
<RaisedButton size = 'large' label = 'LARGE' color = 'accent' >
<IconImage room = 'content-left' source = 'home' />
</RaisedButton>
<RaisedButton size = 'small' label = 'SMALL' color = 'primary' >
<IconImage room = 'content-right' source = 'profile' />
</RaisedButton>
<RaisedButton size = 'normal' label = 'NORMAL' color = 'secondary' >
<IconImage room = 'content-right' source = 'profile' />
</RaisedButton>
<RaisedButton size = 'large' label = 'LARGE' color = 'accent' >
<IconImage room = 'content-right' source = 'profile' />
</RaisedButton>
```
<p align="center">
<img width="50%" height="50%" src="/assets/screenshots/raised-buttons-with-corners.png">
</p>
<p align="center">
<em>A few examples of corner styling</em>
</p>
```jsx
<RaisedButton label = 'BUTTON' color = 'primary' corner = 'sharp' />
<RaisedButton label = 'BUTTON' color = 'secondary' corner = 'round' />
<RaisedButton label = 'BUTTON' color = 'accent' corner = 'circular' />
```
<p align="center">
<img width="35%" height="35%" src="/assets/screenshots/fab-buttons.png">
</p>
<p align="center">
<em>Raised buttons styled as floating action buttons</em>
</p>
```jsx
<RaisedButton color = 'primary' corner = 'circular' size = 'large' >
<IconImage room = 'content-middle' source = 'add' />
</RaisedButton>
<RaisedButton color = 'secondary' corner = 'circular' size = 'large' >
<IconImage room = 'content-middle' source = 'edit' />
</RaisedButton>
<RaisedButton color = 'accent' corner = 'circular' size = 'large' >
<IconImage room = 'content-middle' source = 'star' />
</RaisedButton>
```
#
#### Area Button Examples
<p align="center">
<img width="50%" height="50%" src="/assets/screen-records/area-buttons.gif">
</p>
<p align="center">
<em>Using area button to create selectable list items</em>
</p>
```jsx
<FlatList
data = { animals }
renderItem = {(listData) => {
const animal = listData.item;
return (
<AreaButton shade = { shade }>
<ColumnLayout room = 'content-left' roomAlignment = 'center' >
<AvatarImage room = 'content-left' source = { animal.avatarImage } dropShadowed = { false } />
<TitleText room = 'content-right' size = 'small' indentation = { 20 }>{ animal.name }</TitleText>
</ColumnLayout>
<FlatButton room = 'content-right' overlay = 'transparent' corner = 'circular' color = 'red' >
<IconImage room = 'content-middle' source = `favorite` />
</FlatButton>
</AreaButton>
);
}}
/>
```
## Field Components
<p align="center">
<img width="35%" height="35%" src="/assets/screen-records/text-fields.gif">
<img width="35%" height="35%" src="/assets/screen-records/search-field.gif">
</p>
Hypertoxin has two field components, [_TextField_](https://github.com/tuantle/hypertoxin/blob/develop/src/components/fields/text-field.js) and [_SearchField_](https://github.com/tuantle/hypertoxin/blob/develop/src/components/fields/search-field.js)
#### Search Field Properties
Use search field to create functional search bar. Notable feature is suggestion pull-up view.
| Prop | Type | Default | Description |
| ------------------------- | ---------------------------------- | -------- | ----------- |
| exclusions | array of string | [] | Set which properties from parent component to exclude. See [Using Exclusions Property](#using-exclusions-property) section for details |
| room | string | `none` | Set search field's room with respect to parent component which can be one of `none`, `content-left`, `content-middle`, `content-right`, `content-bottom`, `content-top`, `media`. See [Using Room Property](#using-room-property) section for details |
| shade | string, object | `themed` | Set search field's shade theme, can be `themed`, `light`, or `dark` |
| overlay | string | `themed` | Set search field's overlay style which can be one of `themed`, `opaque`, `translucent`, `translucent-outline`, `transparent`, `transparent-outline` |
| corner | string, number, object | `themed` | Set search field's corner styles. As a number, border radius = corner. Set corner as an object for more control. For example `corner = { topLeft: 0.1, topRight: 0.1, bottomLeft: 0.1, bottomRight: 0.1}` |
| size | string | `themed` | Set search field's size which can be one of `themed`, `small`, `normal`, `large` |
| margin | string, number, object | None | Set search field's margin styles. As a number, the margin is equally set around search field container. Set margin as an object for more control. For example `margin = { top: 5, bottom: 5, left: 5, right: 5, horizontal: 5, vertical: 5}` |
| dropShadowed | boolean, string | `themed` | Enable search field's container drop shadow |
| autoFocus | boolean | true | Enable search field's auto focus |
| autoCorrect | boolean | true | Enable search field's auto correct spelling |
| suggestive | boolean | true | Enable search field's suggestion pull-up view |
| pinnedSuggestionValues | array of string, number, or object | [] | A list of pinned suggestion values |
| hint | string | None | Set search field's hint |
| style | object | None | Search field style is an object with the following properties: `container: {...}, box, {...}, contentLeftRoom: {...}, contentRightRoom: {...}, input: {...}, suggestion: {...}`. Standard React Native style properties go inside these properties. Changes to these properties will override the global theme. See [default style object](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/fields/search-field.js#L68) |
| onSearch | function | None | Calls after search field's text input onSubmitEditing |
| onGetAutocompletionValues | async function | None | Async retrieve autocompletion string value array for suggestion pull-up view |
| onEditing | function | None | Calls when search field's text input onChangeText |
| onFocus | function | None | Calls after search field's text input is focused |
| onBlur | function | None | Calls after search field's text input is blurred |
| onCollapse | function | None | Calls after search field view collapsed |
| onExpand | function | None | Calls after search field view expanded |
| onHide | function | None | Calls when search field view becomes hidden |
| onShow | function | None | Calls when search field view becomes visible |
| onHideSuggestion | function | None | Calls when search field's suggestion view becomes hidden |
| onShowSuggestion | function | None | Calls when search field's suggestion view becomes visible |
| onClear | function | None | Calls after search field's text input is cleared |
| onClearSuggestion | function | None | Calls after search field's suggestion is clear |
| renderSuggestionItem | function | None | Takes an item from a list of suggestion items (pinned, autocompleted, & history) and renders them into the list in pull-up suggestion view |
#### Text Field Properties
Use text fields to create beautiful input forms. Notable features are input reformatting & validation and selectable pull-up view.
| Prop | Type | Default | Description |
| -------------------- | ----------------------------------- | --------- | ----------- |
| exclusions | array of string | [] | Set which properties from parent component to exclude. See [Using Exclusions Property](#using-exclusions-property) section for details |
| room | string | `none` | Set text field's room with respect to parent component which can be one of `none`, `content-left`, `content-middle`, `content-right`, `content-bottom`, `content-top`, `media`. See [Using Room Property](#using-room-property) section for details |
| shade | string, object | `themed` | Set text field's shade theme, can be `themed`, `light`, or `dark` |
| overlay | string | `themed` | Set text field's overlay style which can be one of `themed`, `opaque`, `translucent`, `translucent-outline`, `transparent`, `transparent-outline` |
| corner | string, number, object | `themed` | Set text field's corner styles. As a number, border radius = corner. Set corner as an object for more control. For example `corner = { topLeft: 0.1, topRight: 0.1, bottomLeft: 0.1, bottomRight: 0.1}` |
| size | string | `themed` | Set text field's size which can be one of `themed`, `small`, `normal`, `large` |
| margin | string, number, object | None | Set text field's margin styles. As a number, the margin is equally set around text field container. Set margin as an object for more control. For example `margin = { top: 5, bottom: 5, left: 5, right: 5, horizontal: 5, vertical: 5}` |
| autoFocus | boolean | true | Enable text field's auto focus |
| autoCorrect | boolean | true | Enable text field's auto correct spelling |
| secured | boolean | false | Enable text field's secure mode |
| underlined | boolean, string | `themed` | Enable text field's underlined animation |
| disabled | boolean | false | Disable text field's input |
| initialValue | string, number | None | Set text input's initial value |
| selectableValues | array of string, number, or object | [] | A list of selectable values |
| label | string | None | Set text field's label |
| hint | string | None | Set text field's hint |
| charLimit | number | -1 | Set text input's max characters count. Set charLimit > -1 for no character limit. When charLimit > 1, a little character counter will be visible in the bottom right |
| lineLimit | number | 1 | Set text input's max lines count. Set lineLimit > 1 for multi-lined text input |
| inputType | string | `default` | Set text input's type which can be one of `default`, `numeric`, `monetary`, `phone-pad`, `email-address`, `credit-card-visa`, `credit-card-master`, `credit-card-discover`, `credit-card-american-express` |
| disableValidation | bool | false | Disable text input validation |
| disableFormatting | bool | false | Disable text input formatting |
| style | object | None | Text field style is an object with the following properties: `container: {...}, box: {...}, contentLeftRoom: {...}, contentRightRoom: {...}, input: {...}, helper: {...}, status: {...}, label: {...}, underline: {...}, selection: {...}`. Standard React Native style properties go inside these properties. Changes to these properties will override the global theme. See [default style object](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/fields/text-field.js#L55) |
| onValidate | function | None | Calls after text field's text input onChangeText or onEndEditing |
| onReformat | function | None | Calls after text field's text input onChangeText |
| onEditing | function | None | Calls when text field's text input onChangeText |
| onDoneEdit | function | None | Calls when a value in text field's selectable pull-up view is selected or after text field's text input onSubmitEditing |
| onSelect | function | None | Calls when a value in text field's selectable pull-up view is selected |
| onFocus | function | None | Calls after text field's text input is focused |
| onBlur | function | None | Calls after text field's text input is blurred |
| onHideSelection | function | None | Calls after text field's selectable pull-up view is hidden |
| onShowSelection | function | None | Calls after text field's selectable pull-up view is visible |
| onClear | function | None | Calls after text field's text input is cleared |
| renderSelectableItem | function | None | Takes an item from a list of selectable items and renders them into the list in pull-up selection view |
_Note: `themed` property indicates using values defined by the global theme provider._
By default, text field component passes `shade`, `size`, and `disabled` properties down to it child components and at the same time set `margin = { 0 }` and `indentation = { 0 }` properties onto its children. By default, search field component passes `shade` property down to it child components and at the same time set `margin = { 0 }` and `indentation = { 0 }` properties onto its children. This behavior can be override by child components with the `exclusions` property. See [Using Exclusions Property](#using-exclusions-property) section for details.
#
<p align="center">
<img width="50%" height="50%" src="/assets/images/search-field-compositions.png">
</p>
<p align="center">
<em>Search field internal view compositions diagram</em>
</p>
Search field animated internal view composition reference names. See [Animation API](#animation-api) for details:
- `animated-container-view`
- `animated-box-view`
- `animated-content-left-room-view`
- `animated-content-right-room-view`
- `animated-suggestion-view`
Search field available actions:
- `search`
- `clear`
- `blur`
- `focus`
- `expand`
- `collapse`
- `show`
- `show-suggestion`
- `hide`
- `hide-suggestion`
Search field methods & callbacks:
- `animate` - See [Animation API](#animation-api) for details
- `isCollapsed`
* arguments: None
* return: bool
- `isVisible`
* arguments: None
* return: bool
- `isSuggestionVisible`
* arguments: None
* return: bool
- `isFocused`
* arguments: None
* return: bool
- `collapse`
* arguments:
- `animation` (object) - Collapse animation object. See [Animation API](#animation-api) for details.
* return: None
- `expand`
* arguments:
- `animation` (object) - Expand animation object. See [Animation API](#animation-api) for details
* return: None
- `show`
* arguments:
- `animation` (object) - Show animation object. See [Animation API](#animation-api) for details
* return: None
- `showSuggestion`
* arguments:
- `animation` (object) - Show animation object. See [Animation API](#animation-api) for details
* return: None
- `hide`
* arguments:
- `animation` (object) - Hide animation object. See [Animation API](#animation-api) for details
* return: None
- `hideSuggestion`
* arguments:
- `animation` (object) - Hide animation object. See [Animation API](#animation-api) for details
* return: None
- `focus`
* arguments: None
* return: None
- `blur`
* arguments: None
* return: None
- `clear`
* arguments: None
* return: None
- `clearSuggestion`
* arguments: None
* return: None
- `onSearch`
* arguments:
- `value` (string) - Submitted search text value
* return: None
- `onGetAutocompletionValues` (async)
* arguments:
- `value` (string) - Submitted search text value
* return:
- results (array) - An array of autocompletion text values
- `onEditing`
* arguments:
- `value` (string) - Current search text value
* return: None
- `onFocus`
* arguments: None
* return: None
- `onBlur`
* arguments: None
* return: None
- `onCollapse`
* arguments: None
* return: None
- `onExpand`
* arguments: None
* return: None
- `onHide`
* arguments: None
* return: None
- `onShow`
* arguments: None
* return: None
- `onHideSuggestion`
* arguments: None
* return: None
- `onShowSuggestion`
* arguments: None
* return: None
- `onClear`
* arguments: None
* return: None
- `onClearSuggestion`
* arguments: None
* return: None
- `renderSuggestionItem` - Render the suggestion item component
* arguments:
- `item` (object) - Suggestion item
- `onPressSelectAndSubmit` - Callback to indicate which item was selected and then submitted
* arguments:
- `item` - Selected item
* return: None
- `onPressSelect` - Callback to indicate which item was selected
* arguments:
- `item` - Selected item
* return: None
* return - Component
#
<p align="center">
<img width="50%" height="50%" src="/assets/images/text-field-compositions.png">
</p>
<p align="center">
<em>Text field internal view compositions diagram</em>
</p>
Text field animated internal view composition reference names. See [Animation API](#animation-api) for details:
- `animated-container-view`
- `animated-box-view`
- `animated-label-text`
- `animated-underline-focused-view`
- `animated-content-left-room-view`
- `animated-content-right-room-view`
- `animated-selection-view`
Text field available actions:
- `clear`
- `blur`
- `focus`
- `show-selection`
- `hide-selection`
Text field methods & callbacks:
- `animate` - See [Animation API](#animation-api) for details
- `isValidated` - Check if text input's value is validated
* arguments: None
* return: bool
- `isSelectionVisible` - Check if selectable pull-up view is visible
* arguments: None
* return: bool
- `isFocused` - Check if text input's value is focused
* arguments: None
* return: bool
- `showSelection` - Show selectable pull-up view if `selectableValues` is provided
* arguments: None
* return: None
- `hideSelection` - Hide selectable pull-up view if `selectableValues` is provided
* arguments: None
* return: None
- `focus` - Focus text input
* arguments: None
* return: None
- `blur` - Blur text input
* arguments: None
* return: None
- `clear` - Clear text input
* arguments: None
* return: None
- `onValidate` - Calls after text field's text input onChangeText or onEndEditing. See [default onValidate](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/fields/text-field.js#L1022)
* arguments:
- `value` (string) - Current text value
- `inputType`
* return: object - Expects return object with a `validate` boolean property and a `status` string property
- `onReformat` - Calls after text field's text input onChangeText. See [default onReformat](https://github.com/tuantle/hypertoxin/blob/c61f4bf96ac92efb550fb5264404f72cc0e1443f/src/components/fields/text-field.js#L1075)
* arguments:
- `value` (string) - Current text value
* return: string - Return reformatted value
- `onEditing` - Calls when text field's text input onChangeText
* arguments:
- `value` (string) - Current text value
* return: None
- `onDoneEdit` - Calls when a value in text field's selectable pull-up view is selected or after text field's text input onSubmitEditing
* arguments:
- `value` (string) - Current text value
* return: None
- `onSelect` - Calls when a value in text field's selectable pull-up view is selected
* arguments:
- `value` (string) - Selected value
* return: None
- `onFocus`
* arguments: None
* return: None
- `onBlur`
* arguments: None
* return: None
- `onHideSelection`
* arguments: None
* return: None
- `onShowSelection`
* arguments: None
* return: None
- `onClear`
* arguments: None
* return: None
- `renderSelectableItem` - Render an item from a list of selectable items and renders them into the list in pull-up selection view.See below for examples
#
#### Search Field Examples
<p align="center">
<img width="35%" height="35%" src="/assets/screen-records/search-field-suggestion.gif">
</p>
<p align="center">
<em>Search field with suggestion using Google's autocompletes</em>
</p>
```jsx
<SearchField
hint = 'Search...'
pinnedSuggestionValues = {[ `Hypertoxin`, `React Native` ]}
onGetAutocompletionValues = {async (text) => {
if (text) {
const response = await fetch(`http://suggestqueries.google.com/complete/search?client=firefox&q=${text}`, {
method: `get`
});
const data = await response.json();
return data[1].slice(0, 6);
}
return [];
}}
renderSuggestionItem = {(item, onPressSelectAndSubmit, onPressSelect) => {
// item = {
// value: ... String value of the suggestion item
// suggestionType: .. String value to indicate the suggestion types: pin, autocompletion, or history
// }
// onPressSelect Callback to indicate which item was selected
// onPressSelectAndSubmit Callback to indicate which item was selected and then submitted
return (
<AreaButton shade = { shade } overlay = 'transparent' size = 'small' onPress = {() => onPressSelectAndSubmit(item)}>
<ColumnLayout room = 'content-left' roomAlignment = 'center'
>
<IconImage
room = 'content-left'
source = {(() => {
switch (item.suggestionType) { // eslint-disable-line
case `pin`:
return `star`;
case `history`:
return `history`;
case `autocompletion`:
return `search`;
default:
return null;
}
})()}
margin = {{ left: 10 }}
/>
<InfoText room = 'content-right' indentation = { 10 }>{ item.value }</InfoText>
</ColumnLayout>
{
item.suggestionType !== `pin` ?
<FlatButton room = 'content-right' overlay = 'transparent' corner = 'circular' onPress = {() => onPressSelect(item)} margin = {{ right: 10 }}>
<IconImage room = 'content-middle' source = 'recall' size = 'small' />
</FlatButton> : null
}
</AreaButton>
);
}}
style = {{
suggestion: {
left: -10
}
}}
>
<FlatButton room = 'content-left' action = 'expand' overlay = 'transparent' corner = 'circular' >
<IconImage room = 'content-middle' source = 'search' />
</FlatButton>
<FlatButton room = 'content-left' action = 'collapse' overlay