Gathering detailed insights and metrics for react-responsive-detecter
Gathering detailed insights and metrics for react-responsive-detecter
Gathering detailed insights and metrics for react-responsive-detecter
Gathering detailed insights and metrics for react-responsive-detecter
Component for the development environment, which detects the screen size and generates a fully customizable responsive grid for React applications.
npm install react-responsive-detecter
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (59.88%)
JavaScript (20.63%)
SCSS (17.75%)
Shell (0.85%)
HTML (0.83%)
CSS (0.07%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
7 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 04, 2022
Latest Version
2.0.0
Package Id
react-responsive-detecter@2.0.0
Unpacked Size
286.80 kB
Size
69.00 kB
File Count
66
NPM Version
9.5.1
Node Version
19.8.1
Published on
Oct 27, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
41
Component for the development environment, which detects the screen size and generates a fully customizable responsive grid for React applications.
Keep component layout powerful and responsive, make sure all your development is vertically and horizontally aligned, spread your components evenly, make responsive development easy, use a persistent vertical rhythm in all your text.
The component helps the developer to detect the screen size in which he is working (XS, SM, MD, LG, XL, XX), so that the developer can adjust the styles of his project, according to a responsive design for each screen size.
Likewise, this component also allows the developer to paint a grid on the entire screen, to serve as a guide in the development of its components, distribution of elements, alignment of texts, separation of elements, among other uses.
This grid can be customized and disabled if desired.
Note: :warning: This component is only for the development environment, so it is the responsibility of each developer, not to include this module in production, exclude it from the compilation bundle or disable it when the environment changes to be different from development. End users are not expected to see this component.
Using npm:
1npm install --save-dev react-responsive-detecter 2 3npm i -D react-responsive-detecter
Using yarn:
1yarn add react-responsive-detecter --dev 2 3yarn add react-responsive-detecter -D
The component is already configured with 6 breakpoints to be based on responsive development, but if these breakpoints do not suit your design or development template, you can modify their value for those you consider useful.
Sample:
The component is intended to be displayed on all screens as it is helpful for development, so a good place to mount it would be within your App component or within your route handler (react-router-dom to mention one).
If this is not it, you are free to render it wherever you like, the component will still work correctly, this is just to help you decide where it would be good to mount it.
1import ResponsiveDetecter from 'react-responsive-detecter'; 2 3const App = () => { 4 return ( 5 <> 6 <ResponsiveDetecter /> 7 8 <!-- other components... --> 9 </> 10 ); 11}; 12
1import ResponsiveDetecter from 'react-responsive-detecter'; 2import { BrowserRouter, Routes, Route } from 'react-router-dom'; 3 4const App = () => { 5 return ( 6 <BrowserRouter> 7 <ResponsiveDetecter /> 8 9 <!-- other components... --> 10 <Routes> 11 <Route path="/" element={<HomeScreen />} /> 12 </Routes> 13 </BrowserRouter> 14 ); 15}; 16
Important: :exclamation: The component should not be rendered inside another component that prevents ResponsiveDetecter from occupying 100% of it's screen, since this component has the styles of: position: absolute, width: 100% and height: 100vh.
:x: Bad usage example:
1import ResponsiveDetecter from 'react-responsive-detecter'; 2 3const App = () => { 4 return ( 5 <div style={{ width: '50%', height: '500px' }}> 6 <ResponsiveDetecter /> 7 8 <!-- other components... --> 9 </div> 10 ); 11}; 12
The component has a gear icon, which, when pressed, will display a menu of small settings that can be of great help when working with it.
Note: :sunny: The configuration of these options is persisted in the localStorage of the browser under the key 'LayoutConfig', this is useful so that every time your project is opened in the same browser, the component respects its configuration.
Enable grid:
Disabling this option, will hide the entire grid, as well as its rows and columns.
Grid in front:
Enabling this option, will send the grid to the front of your development, by default it is at the bottom. This is useful when you have a component with a background color or an image, and you want these elements not to cover the rows or columns.
Doing this will help you align the elements that are inside other components with font color or text inside images, just keep in mind that since the grid is in front, many or all of its elements cannot be selected, since the grid is above them.
Hide rows:
Enabling this option, will hide all grid rows.
Left position:
Enabling this option, will position the component on the left side of your screen.
Top position:
Enabling this option, will position the component at the top side of your screen.
Enable theme light:
Enabling this option, will allow you to toggle between the light and dark theme of the component, menu and font color.
Name | Type | Default | Description |
---|---|---|---|
disable | boolean | false | Disable the component, this will prevent the functions and eventListeners from executing |
classNameContainer | string | N/A | Replace all styles of the container that wraps the columns and the grid |
screenSizes | ScreenSizesType | { XS: 350, SM: 600, MD: 905, LG: 1280, XL: 1440, XX: 1920 } | Allows you to customize all default screen sizes |
columnDistribution | ColumnDistributionType | { INIT: 3, XS: 6, MD: 8, LG: 12 } | Allows you to customize the number of columns in relation to the current screen size |
rowHeight | RowHeightType | 16 | Allows you to change the size of the grid rows |
Description of the data types used by some of the props.
This data type is an object, where all its attributes are optional and have the following structure.
Interface:
Name | Type | Required | Description |
---|---|---|---|
XS | number | false | Screen size name to identify cell phone screens |
SM | number | false | Screen size name to identify screens of large cell phones or small tablets |
MD | number | false | Screen size name to identify tablets screens |
LG | number | false | Screen size name to identify screens large tablets or small laptops |
XL | number | false | Screen size name to identify large laptop screens or monitors |
XX | number | false | Screen size name to identify large monitors onwards |
This data type is an object, where only the INIT attribute is required, they have the following structure.
Interface:
Name | Type | Required | Description |
---|---|---|---|
INIT | 1 \ | 2 \ | 3 \ |
XS | 1 \ | 2 \ | 3 \ |
SM | 1 \ | 2 \ | 3 \ |
MD | 1 \ | 2 \ | 3 \ |
LG | 1 \ | 2 \ | 3 \ |
XL | 1 \ | 2 \ | 3 \ |
XX | 1 \ | 2 \ | 3 \ |
This data type is numeric, but can only take one of the following values.
Type:
Name | Type | Description |
---|---|---|
rowHeight | 7 \ | 8 \ |
classNameContainer:
Passing an empty string will disable all styles in the container that wraps the grid, and will make the grid fill the full available width of the screen.
This is not highly recommended, as you should always develop with a maximum screen width limit and/or horizontal margins, to prevent your components from overflowing to full width on very large screens, or simply to prevent your text from sticking to the screen edge.
screenSizes:
You can modify the value of the breakpoints, but you cannot modify the name assigned to each of them.
If you don't want to include a screen name, what the component will do is take the next value it finds, either up or down.
The order of values that each screen name takes is described below, so if you try to pass something like, { MD: 1200, LG: 900 }
, this will throw you an error and not display the current screen size, until I correct this, since MD cannot be greater than LG, and so on with each of the screen names.
Note: From 0px to 349px, it is considered as an INIT size, and this is used to identify very very small screen sizes for which you no longer want to continue to find an optimal design, and the base styles of your spreadsheet. styles, before your first breakpoint, are what should be applied here.
Default screenSizes:
Custom screenSizes:
1import ResponsiveDetecter from 'react-responsive-detecter'; 2 3const App = () => { 4 return ( 5 <> 6 <ResponsiveDetecter 7 screenSizes={{ SM: 400, MD: 950, LG: 1280 }} 8 /> 9 </> 10 ); 11}; 12
This will cause only 4 breakpoints to be considered, from 0 to 399 as a INIT, from 400 to 949 for SM, from 950 to 1279 for MD, and 1280 onwards for LG.
columnDistribution:
You can modify the value of the column distribution by screen size, but you cannot modify the name assigned to each of them.
If you don't want to include a column layout for a screen size, what the component will do is take the next value it finds, either up or down, as long as it exists within the screen names.
Note: If you want to modify the number of columns per screen, you must take into account that the INIT attribute is the only attribute required when using this prop, that is, the new object that you provide to the component must at least contain the INIT attribute.
Default columnDistribution:
Custom columnDistribution:
1import ResponsiveDetecter from 'react-responsive-detecter'; 2 3const App = () => { 4 return ( 5 <> 6 <ResponsiveDetecter 7 screenSizes={{ SM: 400, MD: 950, LG: 1280 }} 8 columnDistribution={{ INIT: 3, SM: 6, XL: 8 }} 9 /> 10 </> 11 ); 12}; 13
This will mean that if the current screen size is LG, since LG does not belong to the attributes declared in columnDistribution, the next value down will be taken, that is, the value of SM, since MD is not inside columnDistribution either.
If you have any ideas to improve this package or any functionality that you would expect it to have, feel free to write to me.
No vulnerabilities found.
No security vulnerabilities found.