Socket
Socket
Sign inDemoInstall

@pija-ab/react-native-elements

Package Overview
Dependencies
1
Maintainers
5
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @pija-ab/react-native-elements

## Installation


Version published
Weekly downloads
25
increased by212.5%
Maintainers
5
Created
Weekly downloads
 

Readme

Source

react-native-elements

Installation

npm

npm install --save @pija-ab/react-native-elements

yarn

yarn add @pija-ab/react-native-elements

Forewords

This is a repostitory for themeing your react-native app and easily structure your project with simple building blocks.

Getting started

To get started using this repostitory you need to configure a theme folder with the basic structure that you're going to be usign.

First of all you should make a folder structure that looks like something like this.

ProjectRoot
    └──theme
        ├── colors.js
        ├── dimensions.js
        ├── fontFiles.js
        ├── fonts.js
        └── index.js

Define your theme in the index.js file:

import { Theme, font, type ThemeSpec, createStyleSheets } from '@pija-ab/react-native-elements';

import colors from './colors';
import dimensions from './dimensions';
import fonts from './fonts';
import getFontName from './fontFiles';

const themeSpec: ThemeSpec = {
  name: 'default',
  colors,
  dimensions,
  fonts,
  getFontName,
};
themeSpec.font = props => font(themeSpec, props);

const theme = new Theme(themeSpec);
theme.addStyleSheets(createStyleSheets(themeSpec));

export default theme;

color.js file should look something like this:

export default {
  primary: '#3ac4a1',
  primaryLabel: '#ffffff',
  secondary: '#fceb49',
  secondaryLabel: '#2a3532',
  text: '#2a3532',
  secondaryText: '#999999',
  background: '#ffffff',
  secondaryBackground: '#f2f2f2',
  border: '#d9d9d9',
};

dimensions.js file should look something like this:

export default {
  /** Core dimension parameter, controls the overall scale of Element components */
  baseSize: 20,
};

fontFiles.js file should look something like this:

import fonts from './fonts';

const primaryFont = fonts.primary.fontFamily;
const primaryFont = fonts.primary.fontFamily;

const fontFiles = {
  [fonts.primary.fontFamily]: {
    '200': {
      normal: `${primaryFont}-ExtraLight`,
      italic: `${primaryFont}-ExtraLightItalic`,
    },
    '300': {
      normal: `${primaryFont}-Light`,
      italic: `${primaryFont}-LightItalic`,
    },
    '400': {
      normal: `${primaryFont}-Regular`,
      italic: `${primaryFont}-Italic`,
    },
    '500': {
      normal: `${primaryFont}-Medium`,
      italic: `${primaryFont}-MediumItalic`,
    },
    '600': {
      normal: `${primaryFont}-SemiBold`,
      italic: `${primaryFont}-SemiBoldItalic`,
    },
    '700': {
      normal: `${primaryFont}-Bold`,
      italic: `${primaryFont}-BoldItalic`,
    },
    '800': {
      normal: `${primaryFont}-ExtraBold`,
      italic: `${primaryFont}-ExtraBoldItalic`,
    },
    '900': {
      normal: `${primaryFont}-Black`,
      italic: `${primaryFont}-BlackItalic`,
    },
  },
};

export default (fontFamily, fontWeight, fontStyle) => fontFiles[fontFamily][fontWeight][fontStyle];

and font.js file should look something like this:

import { Platform } from 'react-native';

export default {
  primary: {
    fontFamily: 'Verdana',
  },
  secondary: {
  },
};

After this has been done you should be good to go and use all of the building blocks in the theme.

Basic building blocks:

Common props

Some common props that is available on all of the components

PropDescriptionType
styleBasic inline stylestyle
classNameSets class for your componentstring
Button
PropDescriptionType
variantString that should be one of the defined colors in the color.js filestring
onPressAssigning button triggerfunction
loadingShows a loading indicator in the middle of the buttonboolean
disabledDisables the buttonboolean
textStyleBasic inline stylingtext style

Button will take strings and React components as children, any string will be wrapped in a text component and the rest will just be rendered as is.

import { Button } from '@pija-ab/react-native-elements';
...
<Button
  variant="primary"
  onPress={() => console.log('button has been triggered')}
>
String
</Button>
...
...
<Button
  variant="primary"
  onPress={() => console.log('button has been triggered')}
>
  <View>
    <Text>String</Text>
  </View>
</Button>
...
Container
PropDescriptionType
scrollableMakes it scrollableboolean
keyboardAwareAutomatically scrolls to focused area when keyboard appearsboolean
verticallyAlignedGrows the container component and aligns content inside the component in the centerboolean

Basic usage of the Container component is wrapping the content in your components

import { Container } from '@pija-ab/react-native-elements';
...
render(
  <Container>
    <Text>This is some content</Text>
  </Container>
);

Container also have a child component for making the content ignore the bounds of the container, such as menu items reaching the edges of the screen, or a header image ignoring the top-left-right margins. It can be used by having a <Container.Fill> component

<Container>
  <Container.Fill>
    <Text>This content will ignore the bounds of the container component</Text>
  </Container.Fill>
</Container>
Grid
PropDescriptionType
sizeTakes one of either collapsed small medium large extraLargestring
flexWrapTakes one of either wrap nowrapstring
alignItemsTakes one of either flex-start flex-end center stretch baselinestring
alignContentTakes one of either flex-start flex-end center stretch space-between space-aroundstring
justifyContentTakes one of either flex-start flex-end center space-between space-around space-evenlystring

Grid.Cell props

PropDescriptionType
sizeTakes one of either collapsed small medium large extraLargestring
columnTakes one of either 1 2 3 4 5 6 7 8 9 10 11 12number
flexGrowspecifies how much of the remaining space in the flex container should be assigned to the itemnumber
flexShrinkIf the size of all flex items is larger than the container items shrink to fitnumber
flexBasisSets the initial main size of an itemstring or number
alignSelfTakes one of either auto flex-start flex-end center stretch baselinestring

Basic usage of the cell component is that you have 1 <Grid> wrapping the <Grid.Cell> components.

import { Grid } from '@pija-ab/react-native-elements';
...
<Grid>
  <Grid.Cell>
    <Text>This is cell 1</Text>
  </Grid.Cell>
  <Grid.Cell>
    <Text>This is cell 2</Text>
  </Grid.Cell>
</Grid>
...

Using columns, full with of the container is 12.

import { Grid } from '@pija-ab/react-native-elements';
...
<Grid>
  <Grid.Cell column={4}>
    <Text>This is cell 1</Text>
  </Grid.Cell>
  <Grid.Cell column={8}>
    <Text>This is cell 2</Text>
  </Grid.Cell>
</Grid>
...
Divider
PropDescriptionType
childrenTakes either a Text or View as a child and puts it's content in the center of the dividercomponent
fittedRemoves the margin on the bottom and the top of the dividerboolean

Basic usage of the devider:

import { Divider } from '@pija-ab/react-native-elements';
...
<Divider />
...
import { Divider } from '@pija-ab/react-native-elements';
...
<Divider fitted>
  <Text>This is some content</Text>
</Divider>
...
Header
PropDescriptionType
asTakes one of either h1 h2 h3 h4 h5 h6string
subCreates a sub headerboolean
invertedChanges the color of the headerboolean
marginBottomAdds margin under the headerboolean
textAlignTakes one of either left center rightstring

Basic usage:

import { Header } from '@pija-ab/react-native-elements';
...
<Header
  as="h2"
  textAlign="center"
>
This is header 2
</Header>
<Header
  as="h2"
  textAlign="center"
  sub
  marginBottom
>
This is header 2 sub
</Header>
...

PropDescriptionType
onPressAssigning link triggerfunction
loadingShows a loading indicator in the middle of the buttonboolean
disabledDisables the linkboolean
textAlignTakes one of either left center rightstring
buttonUnderlineIf there should be an underlineboolean
underlineIf there should be an underlineboolean

Basic usage of the Link component

import { Link } from '@pija-ab/react-native-elements';

<Link onPress={console.log('trigger')} underline>Test Link</Link>
Loader

This is just a basic loader that should align in the middle of the contianing view.

import { Loader } from '@pija-ab/react-native-elements';
...
<Loader />
...
LoadingIndicator
PropDescriptionType
LoadingWill be shown if loading is trueboolean
sizeShould be either button or mediumstring
nonBasicWill show another color scheme of the loaderboolean
absoluteMakes the loader absolute positionedboolean
centeredCenters the loader in it's current containerboolean

Basic usage:

import { LoadingIndicator } from '@pija-ab/react-native-elements';
...
<LoadingIndicator loading nonBasic centered />
...
Message
PropDescriptionType
variantShould be error or nullstring

Some basic usage of the error

import { Message } from '@pija-ab/react-native-elements';
...
<Message variant="error">
  Error message
</Message>
...
paragraph
PropDescriptionType
textAlignTakes one of either left center rightstring
paddingBeforeIf it should have padding before the paragraphboolean
paddingAfterIf it should have padding after the paragraphboolean
import { Message } from '@pija-ab/react-native-elements';
...
<Paragraph>
 This is some paragraph text
</Paragraph>
...
FormInput

TODO: Document FormInput.

SceneContainer

Depricated. Use <Container className="scene"> instead.

Keywords

FAQs

Last updated on 10 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc