Checkbox

Custom components for rendering checkbox input

See it on Snack

import React from "react";
import { SafeAreaView, StatusBar } from "react-native";
import { Div, ThemeProvider, Checkbox } from "react-native-magnus";

const App = () => {
  return (
    <ThemeProvider>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={{ flex: 1 }}>
        <Div m="lg">
          <Div>
            <Div row>
              <Checkbox value={1} />
              <Checkbox value={2} defaultChecked />
              <Checkbox value={3} activeColor="green500" />
              <Checkbox value={4} disabled />
              <Checkbox value={5} loading />
            </Div>
          </Div>
        </Div>
      </SafeAreaView>
    </ThemeProvider>
  );
};

export default App;

Example 1

Checkbox with prefix text

import React from "react";
import { SafeAreaView, StatusBar } from "react-native";
import { Div, ThemeProvider, Checkbox, Text } from "react-native-magnus";

const App = () => {
  return (
    <ThemeProvider>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={{ flex: 1 }}>
        <Div m="lg">
          <Div>
            <Div>
              <Checkbox value={1} prefix={<Text flex={1}>Option 1</Text>} />
              <Checkbox value={2} prefix={<Text flex={1}>Option 2</Text>} />
              <Checkbox value={3} prefix={<Text flex={1}>Option 3</Text>} />
            </Div>
          </Div>
        </Div>
      </SafeAreaView>
    </ThemeProvider>
  );
};

export default App;

Example 2

Custom renderer

import React from "react";
import { SafeAreaView, StatusBar } from "react-native";
import { Div, ThemeProvider, Checkbox, Text } from "react-native-magnus";

const App = () => {
  return (
    <ThemeProvider>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={{ flex: 1 }}>
        <Div m="lg">
          <Checkbox.Group row>
            {["Option 1", "Option 2", "Option 3"].map((item) => (
              <Checkbox value={item}>
                {({ checked }) => (
                  <Div
                    bg={checked ? "blue600" : "blue100"}
                    px="xl"
                    py="md"
                    mr="md"
                    rounded="circle"
                  >
                    <Text color={checked ? "white" : "gray800"}>{item}</Text>
                  </Div>
                )}
              </Checkbox>
            ))}
          </Checkbox.Group>
        </Div>
      </SafeAreaView>
    </ThemeProvider>
  );
};

export default App;

Props

Checkbox

PropertyDescriptionTypeDefault
onChangeevent triggered on toggling the checkbox`((value: any) => void)undefined;`
checkedstate to control the state of checkboxboolean-
loadingshows ActivityIndicator when truebooleanfalse
disabledshow disabled icon when truebooleanfalse
fontSizefont size for iconstringmd
activeColorcolor for icon when checkbox is checkedstringblue600
inactiveColorcolor for icon when checkbox is uncheckedstringgray400

Checkbox.Group

Checkbox group is a wrapper around Div component. So it accepts all props of Div along with following extra props.

PropertyDescriptionTypeDefault
onChangeevent triggered on toggling the checkbox`((values: any[]) => void)undefined;`
valuevalue for the checkbox groupany[][]
defaultValuedefault value for the checkbox groupany[][]