0.1.1 • Published 7 years ago

tipsi-ui-kit v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

tipsi-ui-kit

React Native Tipsi custom UI elements

Components

<Counter />

Component to change the number by press "+" or "-".

Counter Props

NameDescTypeDefault
stepStep of counting.Number1
defaultValueUncontrolled value of counter.Number0
minValueMax value of counter.Number-Infinity
maxValueMin value of counter.NumberInfinity
valueControlled value of counterNumberundefined
onValueChangeHandle value changes.Function() => {}

Example

import React, { PureComponent } from 'react'
import { Counter } from 'tipsi-ui-kit'

class Example extends PureComponent {
  handleValueChange = value => console.log(`Current value is ${value}`)

  render() {
    <Counter
      step={5}
      defaultValue={25}
      onValueChange={this.handleValueChange}
    />
  }
}

Counter Themes

Theme structure:

{
  container: <View />,
  button: <TouchableOpacity />,
  leftButton: <TouchableOpacity />,
  rightButton: <TouchableOpacity />,
  buttonText: <Text />,
  valueWrapper: <View />,
  value: <Text />,
}

Preview

counter_ios counter_android

<Dash />

Component to draw customisable dashed lines

Dash Props

NameDescTypeDefault
styleDash container style as for View componentObject{flexDirection = 'row'}
dashGapGap between two dashesNumber3.5
dashLengthLength of each dashNumber3
dashThicknessThickness of each dashNumber1
dashColorColor of each dashString#c7d1dc

Example

import React from 'react'
import { Dash } from 'tipsi-ui-kit'

const Example = () => (
  <Dash
    dashGap={5}
    dashLength={10}
    dashThickness={2}
    dashColor="black"
  />
)

Preview

dash_ios dash_android

<Carousel />

Carousel component

Carousel Props

NameDescTypeDefault
spacerSpace between last item and right sideNumber0
...restAll other props for ScrollView component except horizontal--

Carousel.Item Props

NameDescTypeDefault
activeShow item as activeBooleanfalse
onPressHandle press actionFunctionundefined
onRemoveHandle remove actionFunctionundefined

Example

import React from 'react'
import { Text } from 'react-native'
import { Carousel } from 'tipsi-ui-kit'

const Example = () => (
  <Carousel spacer={10}>
    <Carousel.Item active>
      <Text>Facebook</Text>
    </Carousel.Item>
    <Carousel.Item>
      <Text>Twitter</Text>
    </Carousel.Item>
    <Carousel.Item active>
      <Text>Instagram</Text>
    </Carousel.Item>
    <Carousel.Item>
      <Text>YouTube</Text>
    </Carousel.Item>
    <Carousel.Item active>
      <Text>Tumblr</Text>
    </Carousel.Item>
  </Carousel>
)

Carousel Themes

theme structure:

{
  container: <ScrollView />,
}

<Carousel.Item /> theme structure:

{
  container: onPress ? <TouchableOpacity /> : <View />,
  active: <View />,
  remove: <TouchableOpacity />,
  removeIcon: <Icon />,
  removeCircle: <View />,
  gap: <View />,
}

Preview

carousel_ios carousel_android

<LabelRating />

LabelRating Props

NameDescTypeDefault
titleisRequired Title of rating, which is shown on the left sideString-
ratingRating, which is shown on the right sideNumber0

Example

import React from 'react'
import { LabelRating } from 'tipsi-ui-kit'

const Example = () => (
  <LabelRating
    title="WS"
    rating="92"
  />
)

LabelRating Themes

Theme structure:

{
  container: <View />,
  titleWrapper: <View />,
  titleText: <Text />,
  ratingWrapper: <View />,
  ratingText: <Text />,
}

Default themes: primary, success, warning, alert

Preview

labelrating_ios labelrating_android

<Label />

Label Props

NameDescTypeDefault
titleisRequired Title of labelString-

Example

import React from 'react'
import { View } from 'react-native'
import { Label } from 'tipsi-ui-kit'

const Example = () => (
  <View style={{ flexDirection: 'row' }}>
    <Label title="On Sale" />
  </View>
)

Label Themes

Theme structure:

{
  container: <View />,
  title: <Text />,
}

Default themes: primary, success, warning, alert, black

Preview

label_ios label_android

<RangeSlider />

Multi handle slider with text labels

RangeSlider Props

NameDescTypeDefault
styleRangeSlider container style as for View componentObject{flexDirection = 'row'}
startValuesArray of one or two numbers. Start values for slider handles positions.Array of Numbers[2, 8]
sliderLengthLength of sliderNumber280
minThe minimum acceptable value of sliderNumber0
maxThe maximum acceptable value of sliderNumber10
stepMin step of dash scaleNumber1
onValuesChangeStartCall when handle start motionFunction-
onValuesChangeCalling while handle do motionFunction-
onValuesChangeEndCall when handle end motionFunction-
customMarkerCustom marker to slider handleFunction-
valueRendererFunction which change slider text if need.Function-

Example

import React from 'react'
import { RangeSlider } from 'tipsi-ui-kit'

const Example = () => (
  <RangeSlider
    min={10}
    max={100}
    step={5}
    values={[25, 75]}
    valueRenderer={value => `$${value}`}
  />
)

RangeSlider Themes

Theme structure:

{
  container: <View />,
  fullTrack: <View />,
  track: <View />,
  selectedTrack: <View />,
  valueContainer: <View />,
  twoMarkersValueContainer: <View />,
  valueWrapper: <View />,
  valueText: <Text />,
  markerContainer: <View />,
  topMarkerContainer: <View />,
  marker: <View />,
  pressedMarker: <View />,
  touch: <View />,
}

Default themes: primary, success, warning, alert

Preview

rangeslider_ios rangeslider_android

<Expand />

Expand component

Expand Props

NameDescTypeDefault
titleAlways visible.String-
descriptionIn close state cropped to one line.String-
defaultExpandedDefault state of component. If it true component will be rendered in open stateBoolfalse
iconDisclosure indicator for close state \n name - icon name for FontAwesomeObject{ name: 'chevron-down', color: ThemeConstants.LIGHT_GRAY, size: 12 }
expandedIconDisclosure indicator for close state \n name - icon name for FontAwesomeObject{ name: 'chevron-up', color: ThemeConstants.LIGHT_GRAY, size: 12 }
childrenChild element will be shown only in open stateNode-

Example

import { Expand } from 'tipsi-ui-kit'

<Expand
  title="Winemakers Notes:"
  description="The 2012 vintage in Napa Valley was about as close to ‘normal’ as it gets! "
/>

Theme structure:

{
  container: <View />,
  titleWrapper: <View />,
  descriptionWrapper: <View />,
  childrenWrapper: <View />,
  titleText: <Text />,
  descriptionText: <Text />,
}

Preview

expand_ios expand_android

Utils

ThemeRegister

To customize components themes or add your own you can use ThemeRegister manager:

import { ThemeRegister } from 'tipsi-ui-kit'

ThemeRegister.set({
  // Change base component styles
  'LabelRating': {
    titleText: {
      fontSize: 30,
      color: 'black',
    },
  },
  // Change success theme for component
  'LabelRating.success': {
    container: {
      backgroundColor: 'black',
    },
  },
  // Add your own theme for component
  'LabelRating.myOwnTheme': {
    container: {
      backgroundColor: 'black',
    },
  },
})

UIExplorer

To open UIExplorer just start mobile app with the react-native command:

react-native run-ios
# OR
react-native run-android

How to add new UI component

For example let's create Button component:

  1. Create a new directory called Button in src directory and create an entry file (index.js) and component file (Button.js) as given below.

    // src/Button/Button.js
    import React, { Component, PropTypes } from 'react'
    import { Button as RNButton } from 'react-native'
    
    export default class Button extends Component {
      static propTypes = {
        title: PropTypes.string.isRequired,
        onPress: PropTypes.func,
      }
    
      render() {
        return (
          <RNButton
            title={this.props.title}
            onPress={this.props.onPress}
          />
        )
      }
    }
    
    // src/Button/index.js
    export { default } from './Button'
  2. Update src entry file (index.js) to export our new component:

    // src/index.js
    export { default as StarRating } from './StarRating'
    // ...
    export { default as Button } from './Button' // Add this line
  3. Then write your example in uiexplorer/examples directory like this:

    // uiexplorer/examples/Button.js
    import React, { Component } from 'react'
    import register from '../core/utils/register'
    import Button from '../../src/Button'
    
    register.addExample({
      type: 'components',
      title: '<Button />',
      description: 'Button component',
      examples: [{
        title: 'Title',
        description: 'Prop: title (String)',
        render: () => (
          <Button title="Example" />
        ),
      }, {
        title: 'Handle press',
        description: 'Prop: onPress (Function)',
        render: ({ action }) => (
          <Button title="Press me!" onPress={action('onPress')} />
        ),
      }],
    })
  4. Update uiexplorer/examples entry file (index.js) to export example for our new component:

    // uiexplorer/examples/index.js
    import './StarRating'
    // ...
    import './Button' // Add this line
  5. Now you can open UIExplorer and click on <Button /> item to see a result.