React-Shadow-Component: Add Shadows to Your Components with Ease!
Tags: react, tutorial, webdev, javascript
Published: 2023-01-29 17:49:32

React-Shadow-Component is an easy-to-use library for adding shadows to your React components. Whether you're creating a website, a mobile app, or any other type of user interface, the ability to add shadows to your components can greatly enhance the visual appeal of your project.

The library has two main export components, `BoxShadow` and `WithShadow`, that make it simple to add shadows to your components. In this article, we'll take a closer look at how to use these components to add shadows to your React components.

## Installation
To install `React-Shadow-Component`, simply run the following command in your terminal:

```sh
npm install react-shadow-component
```

or if you prefer Yarn:

```sh
yarn add react-shadow-component
```

## BoxShadow Component

The BoxShadow component is used to add a box shadow to your components. It accepts several props, including `color`, `offsetX`, `offsetY`, `blur`, and `spread`. These props allow you to customize the shadow to fit your design needs.

The BoxShadow component takes precedence over the WithShadow component when both are used. This means that if you pass props to the BoxShadow component, it will use those props instead of the WithShadow props.

Here's an example of how to use the BoxShadow component:

```jsx
import React from 'react';
import { BoxShadow } from 'react-shadow-component';

export const MyComponent = () => {
  return (
    <BoxShadow color="#000" offsetX={10} offsetY={10} blur={10} spread={10}>
      <div>My Shadowed Component</div>
    </BoxShadow>
  );
};

```

## WithShadow Component

The WithShadow component is used to wrap any element and add a shadow to it. If the BoxShadow component does not have any props, it will use the props from the WithShadow component if provided.

Here's an example of how to use the WithShadow component:

```js
import React from 'react';
import { WithShadow, BoxShadow } from 'react-shadow-component';

export const MyComponent = () => {
  return (
    <WithShadow color="#000" offsetX={10} offsetY={10} blur={10} spread={10}>
      // This color overrides the color
      // passed to `WithShadow`
      <BoxShadow color="#ff0000">
        <div>My Shadowed Component</div>
      </BoxShadow>
      <BoxShadow>
        <div>My Shadowed Component</div>
      </BoxShadow>
    </WithShadow>
  );
};

```
In this example, we import the WithShadow component from the `react-shadow-component` library. Then, we wrap the component we want to add a shadow to with the WithShadow component. Finally, we pass the props we want to use to the WithShadow component. In this case, we're using the `color`, `offsetX`, `offsetY`, `blur`, and `spread` props to customize the shadow.

## Default Props

React-Shadow-Component also has default props, so you don't have to worry about passing props to the components every time (If you prefer the default shadow  😉). However, if you pass props to the BoxShadow component, it will take precedence over the default props and the WithShadow props. If you pass props to the WithShadow component, it will take precedence over the default props, but only if the BoxShadow component does not have any props.

Got it 🤷‍♂️? If not, don't worry! Just imagine you're playing a game of shadows where BoxShadow is the big boss, WithShadow is the lieutenant, and the default props are just the little minions following orders. If the big boss says jump, they jump, if the lieutenant says sit, they sit 😂. 

## Conclusion

React-Shadow-Component is a fun and effective way to add shadows to your React components. With its two main components, BoxShadow and WithShadow, and its ability to customize the shadow through props, you have full control over the look of your shadows. So go ahead, give it a try and turn your flat and boring components into a work of shadow art!

You can find the library on Github here: [React-Shadow-Component](https://github.com/geekreflex/react-shadow-component) 🚀