🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

react-basic-elements

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-basic-elements

A lightweight collection of basic React layout and UI primitives with built-in style support.

latest
npmnpm
Version
0.1.10
Version published
Maintainers
1
Created
Source

react-basic-elements

A lightweight and customizable React component library offering basic UI elements with a focus on flexibility, performance, and reusability.

Features

  • Lightweight - Minimal dependencies and small bundle size
  • Customizable - Consistent styling API across all components
  • Type-safe - Written in TypeScript with full type definitions
  • Modular - Use only what you need
  • Performance-focused - Optimized for minimal re-renders

Installation

# Using npm
npm install react-basic-elements

# Using yarn
yarn add react-basic-elements

# Using pnpm
pnpm add react-basic-elements

Basic Usage

import { Box, Flex, Text, Divider } from 'react-basic-elements';

function App() {
    return (
        <Box p='lg' radius='md'>
            <Text fz='xl' fw={700}>
                Welcome to React Basic Elements
            </Text>
            <Divider my='md' />
            <Flex direction='row' gap='md'>
                <Box p='md' radius='sm' bg='#f0f0f0'>
                    Box 1
                </Box>
                <Box p='md' radius='sm' bg='#f0f0f0'>
                    Box 2
                </Box>
            </Flex>
        </Box>
    );
}

Styling System

react-basic-elements provides a consistent styling API across all components. The styling system includes:

Size Presets

Components use a set of predefined size values for spacing, font sizes, and border radius:

SizeSpacing ValueFont SizeBorder Radius
xs0.25rem0.75rem0.125rem
sm0.5rem0.875rem0.25rem
md1rem1rem0.375rem
lg1.5rem1.25rem0.5rem
xl2rem1.5rem1rem

Common Style Props

All components accept these common style props:

Spacing Props

PropDescription
mMargin on all sides
mtMargin top
mbMargin bottom
mlMargin left
mrMargin right
mxHorizontal margin (left & right)
myVertical margin (top & bottom)
pPadding on all sides
ptPadding top
pbPadding bottom
plPadding left
prPadding right
pxHorizontal padding (left & right)
pyVertical padding (top & bottom)

Size Props

PropDescription
wWidth
hHeight
minWMinimum width
maxWMaximum width
minHMinimum height
maxHMaximum height
fzFont size
radiusBorder radius

Misc Props

PropDescription
bgBackground color

Values can be either predefined sizes (xs, sm, md, lg, xl) or direct CSS values (numbers, pixel values, percentages, etc.). The bg prop accepts any valid CSS color value.

Components

Box

A versatile container component that serves as the foundation for layouts.

import { Box } from 'react-basic-elements';

function Example() {
    return (
        <Box p='md' m='lg' radius='sm' bg='#f9f9f9' style={{ border: '1px solid #eaeaea' }}>
            Content goes here
        </Box>
    );
}

Flex

A flexible container for creating layouts with flexbox.

import { Flex, Box } from 'react-basic-elements';

function Example() {
    return (
        <Flex direction='row' wrap='wrap' justify='space-between' align='center' gap='md'>
            <Box p='md' bg='#f0f0f0'>
                Item 1
            </Box>
            <Box p='md' bg='#f0f0f0'>
                Item 2
            </Box>
            <Box p='md' bg='#f0f0f0'>
                Item 3
            </Box>
        </Flex>
    );
}

Flex Props

PropTypeDefaultDescription
direction'row' | 'column' | 'row-reverse' | 'column-reverse''row'Flex direction
wrap'nowrap' | 'wrap' | 'wrap-reverse''nowrap'Flex wrap behavior
justify'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly''flex-start'Justify content alignment
align'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch''stretch'Align items
gapSizeValueundefinedGap between items

Text

A customizable text component.

import { Text } from 'react-basic-elements';

function Example() {
    return (
        <>
            <Text fz='xl' fw={700} style={{ color: '#333' }}>
                Heading Text
            </Text>
            <Text fz='md'>Normal paragraph text with medium size</Text>
            <Text fz='sm' style={{ color: '#666' }}>
                Smaller secondary text
            </Text>
        </>
    );
}

Text Props

PropTypeDefaultDescription
fwCSSProperties['fontWeight']|number | stringnormalFont weight
fzSizeValue | number | stringundefinedFont size (accepts predefined sizes)
asReact.ElementType'span'HTML element to render
align'left' | 'center' | 'right' | 'justify'undefinedText alignment

Divider

A horizontal or vertical divider.

import { Divider, Box, Text } from 'react-basic-elements';

function Example() {
    return (
        <Box>
            <Text>Section 1</Text>
            <Divider my='md' />
            <Text>Section 2</Text>

            {/* Vertical divider */}
            <Flex align='center' h='200px'>
                <Text>Left</Text>
                <Divider orientation='vertical' mx='md' />
                <Text>Right</Text>
            </Flex>
        </Box>
    );
}

Divider Props

PropTypeDefaultDescription
variant'solid' | 'dashed' | 'dotted''solid'Line style
orientation'horizontal' | 'vertical''horizontal'Divider orientation
colorstringundefinedLine color
lengthstring | numberundefinedWidth or height depending on orientation

SimpleGrid

A grid system with responsive column layouts.

import { SimpleGrid, Box } from 'react-basic-elements';

function Example() {
    return (
        <SimpleGrid cols={3} gap='md'>
            <Box p='md' bg='#f0f0f0'>
                Item 1
            </Box>
            <Box p='md' bg='#f0f0f0'>
                Item 2
            </Box>
            <Box p='md' bg='#f0f0f0'>
                Item 3
            </Box>
            <Box p='md' bg='#f0f0f0'>
                Item 4
            </Box>
        </SimpleGrid>
    );
}

SimpleGrid Props

PropTypeDefaultDescription
colsnumber1Number of columns
gapstring | numberundefinedGap between grid items

Center

A component for centering content.

import { Center, Box } from 'react-basic-elements';

function Example() {
    return (
        <Center h={200} bg='#f9f9f9'>
            <Box p='md' bg='#f0f0f0'>
                Centered content
            </Box>
        </Center>
    );
}

Creating custom components

You can easily build your own components using the base components:

import { Box, Text, Flex } from 'react-basic-elements';

interface CardProps {
    title: string;
    description: string;
    onClick?: () => void;
}

function Card({ title, description, onClick }: CardProps) {
    return (
        <Box
            p='lg'
            radius='md'
            bg='white'
            style={{
                boxShadow: '0 2px 8px rgba(0, 0, 0, 0.1)',
            }}
            onClick={onClick}
        >
            <Flex direction='column' gap='sm'>
                <Text fz='lg' fw={600}>
                    {title}
                </Text>
                <Text fz='sm' color='#555'>
                    {description}
                </Text>
            </Flex>
        </Box>
    );
}

License

This package is licensed under the MIT License.

Keywords

react

FAQs

Package last updated on 04 May 2025

Did you know?

Socket

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