Open In App
Related Articles

React Rebass Extending

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

React Rebass is a front-end framework that was designed keeping react in mind. In this article, we will know what are Props in React Rebase. Extending is an important part that is required in each development. Rebass components are meant to be used as building blocks in the development of a design system. You can easily build a component library with a consistent API and styles that are guided by design restrictions defined in your theme by extending these fundamental components.

Rebass components can be extended using adding styling techniques to the Rebass components like:

  • SX props
  • CSS props
  • Variants
  • Style System props

Syntax:

<Component sx={{ 
    //properties 
}}>
</Component>

Let’s understand them in detail.

Creating React Application And Installing Module:

Step 1: Create a React application using the following command.

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command.

cd foldername

Step 3: Install React Rebass and form components in your given directory.

npm i rebass
npm i @rebass/preset

Project Structure: It will look like the following.

Project Structure

Example 1: In this example, we are using sx prop for extending the box component.

 

App.js

import React from "react";
import { Box } from "rebass";
import { Text } from "rebass";
  
const gfg = () => {
  return (
    <div id="gfg">
      <Text
        fontSize={[3, 4, 5]}
        fontWeight='bold'
        color='green'
        ml="42%">
        Geeksforgeeks
      </Text>
      <Box
        sx={{
          fontSize: 3,
          margin: 20,
          width: 100
        }}
        color="white"
        bg="green"
        mr={3}
        ml="40%"
      >
        Coding
      </Box>
      <Box sx={{
        fontSize: 3,
        margin: 20,
        width: 100
      }} color="white"
        bg="blue" mr={3}
        variant='outline'
        ml="40%">
        Articles
      </Box>
      <Box
        sx={{
          fontSize: 3,
          margin: 20,
          width: 200
        }} color="white"
        bg="red"
        disabled="false"
        ml="40%">
        Web Development
      </Box>
    </div>
  );
};
  
export default gfg;

                    

Output:

SX prop for extending the box component

Example 2: In this example, we are using default props for extending the box component.

App.js

import React from 'react'
import { ThemeProvider } from 'theme-ui'
import preset from '@rebass/preset'
import { Box } from "rebass";
  
export default props =>
    <ThemeProvider theme={preset}>
        <div id="gfg">
            <center>
                <br />
                <Box
                    display='grid'
                    bg='green'
                    width={400}
                    height={60}
                    color={"yellow"}
                   >
                    GeeksforGeeks: A Computer Science Portal
                </Box>
            </center>
        </div>
    </ThemeProvider>

                    

Output:

Default props for extending the box component

Reference: https://rebassjs.org/extending/



Last Updated : 28 Dec, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads