Skip to content

Latest commit

 

History

History

bpk-component-badge

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

bpk-component-badge

Backpack React Native badge component.

Default

Day Night
bpk-component-badge default iPhone 8 simulator bpk-component-badge default iPhone 8 simulator - dark mode
bpk-component-badge default Google Pixel emulator bpk-component-badge default Google Pixel emulator - dark mode

With icon

Day Night
bpk-component-badge with-icon iPhone 8 simulator bpk-component-badge with-icon iPhone 8 simulator - dark mode
bpk-component-badge with-icon Google Pixel emulator bpk-component-badge with-icon Google Pixel emulator - dark mode

With trailing icon

Day Night
bpk-component-badge with-trailing-icon iPhone 8 simulator bpk-component-badge with-trailing-icon iPhone 8 simulator - dark mode
bpk-component-badge with-trailing-icon Google Pixel emulator bpk-component-badge with-trailing-icon Google Pixel emulator - dark mode

With multiple icons

Day Night
bpk-component-badge with-multiple-icons iPhone 8 simulator bpk-component-badge with-multiple-icons iPhone 8 simulator - dark mode
bpk-component-badge with-multiple-icons Google Pixel emulator bpk-component-badge with-multiple-icons Google Pixel emulator - dark mode

Docked start

Day Night
bpk-component-badge docked-start iPhone 8 simulator bpk-component-badge docked-start iPhone 8 simulator - dark mode
bpk-component-badge docked-start Google Pixel emulator bpk-component-badge docked-start Google Pixel emulator - dark mode

Docked end

Day Night
bpk-component-badge docked-end iPhone 8 simulator bpk-component-badge docked-end iPhone 8 simulator - dark mode
bpk-component-badge docked-end Google Pixel emulator bpk-component-badge docked-end Google Pixel emulator - dark mode

Installation

Check the main Readme for a complete installation guide.

Usage

import React, { Component } from 'react';
import { View, StyleSheet } from 'react-native';
import BpkBadge, {
  BpkBadgeIcons,
  BADGE_TYPES,
  BADGE_DOCKED_TYPES,
  BADGE_ACCESSORY_VIEW_ALIGNMENTS,
  } from 'backpack-react-native/bpk-component-badge';
import BpkIcon, { icons } from 'backpack-react-native/bpk-component-icon';
import { spacingBase } from '@skyscanner/bpk-foundations-react-native/tokens/base.react.native';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    padding: spacingBase,
  }
});

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <BpkBadge message="Badge" accessibilityLabel="This is a badge" type={BADGE_TYPES.success} />
        <BpkBadge message="Badge" type={BADGE_TYPES.warning} />
        <BpkBadge message="Badge" type={BADGE_TYPES.destructive} />
        <BpkBadge message="Badge" type={BADGE_TYPES.inverse} />
        <BpkBadge message="Badge" type={BADGE_TYPES.light} />
        <BpkBadge message="Badge" type={BADGE_TYPES.outline} />
        <BpkBadge
          message="Badge"
          type={BADGE_TYPES.success}
          accessoryView={
            <BpkBadgeIcons
              icons={[<BpkIcon icon={icons.flight} />, <BpkIcon icon={icons.hotels} />]}
              separator="+"
            />
          }
          accessoryViewAlignment={BADGE_ACCESSORY_VIEW_ALIGNMENTS.leading}
        />
        <BpkBadge message="Badge" docked={BADGE_DOCKED_TYPES.start} type={BADGE_TYPES.warning} />
        <BpkBadge message="Badge" docked={BADGE_DOCKED_TYPES.end} type={BADGE_TYPES.destructive} />
      </View >
    );
  }
}

Props

Property PropType Required Default Value
accessibilityLabel string if message === null props.message
accessoryView element false null
accessoryViewAlignment oneOf('leading', 'trailing') false 'leading'
docked oneOf('start', 'end') false null
message string false null
type oneOf('success', 'warning', 'destructive', 'light', 'inverse', 'outline') false warning

accessoryView

The accessory view allows for icons to be placed in front of the text inside the Badge component in conjunction with BpkBadgeIcons.

BpkBadgeIcons

Renders icons suitable to be placed inside a Badge.

Theme Props

  • badgeSuccessBackgroundColor
  • badgeWarningBackgroundColor
  • badgeDestructiveBackgroundColor
  • badgeSuccessTextColor
  • badgeWarningTextColor
  • badgeDestructiveTextColor

Props

Property PropType Required Default Value
icons arrayOf(BpkIcon) true -
itemStyle style false null
separator string false null