justdice / responsive-react Goto Github PK
View Code? Open in Web Editor NEWconditional rendering of react component for responsive display
License: MIT License
conditional rendering of react component for responsive display
License: MIT License
Hi, your library is rather nice. Thank you for the effort.
For my own purposes, I have made some (API and param) changes and wonder if you would be interested? I know, these are big changes. So, feel free to close.
This seems to be a bug: it should read width
instead of height
as your are in landscape mode:
https://github.com/applike/responsive-react/blob/eb601c0aa78492f359d387bd0291d43a252a94f5/src/utilResponsive.js#L64-L65
In the README.md under ### Approach 2
and ### Additional helper function
I suggest to
import {...} from "react-responsive"
.
I added constants
export const PORTRAIT = "PORTRAIT"
export const LANDSCAPE = "LANDSCAPE"
export const MOBILE = "MOBILE"
export const MOBILE_SMALL = "MOBILE_SMALL"
export const MOBILE_MEDIUM = "MOBILE_MEDIUM"
export const MOBILE_LARGE = "MOBILE_LARGE"
export const TABLET = "TABLET"
export const IPAD_PRO = "IPAD_PRO"
export const LAPTOP = "LAPTOP"
export const LAPTOP_SMALL = "LAPTOP_SMALL"
export const LAPTOP_MEDIUM = "LAPTOP_MEDIUM"
export const LARGE_SCREEN = "LARGE_SCREEN"
export const SUPER_LARGE_SCREEN = "SUPER_LARGE_SCREEN"
export const DeviceWidthObject = {
// MobileSmall: { max: 320, min: 0 },
MOBILE_SMALL: { max: 480, min: 0 }, // e.g. iPhone4
// MobileMedium: { max: 375, min: 321 },
MOBILE_MEDIUM: { max: 640, min: 481 }, // e.g. iPhone5
MOBILE_LARGE: { max: 767, min: 641 }, // e.g. Pixel 2, iPhone X
TABLET: { max: 991, min: 768 },
LAPTOP_SMALL: { max: 1024, min: 992 },
// LaptopLarge: { max: 1440, min: 1025 },
LAPTOP_MEDIUM: { max: 1440, min: 1025 },
// LargerThanLaptop: { max: 2560, min: 1441 },
LARGE_SCREEN: { max: 2560, min: 1441 },
SUPER_LARGE_SCREEN: { max: 999999, min: 2561 }
}
You can save 1/3 of the code in utilResponsive.js
if you always virtually swap the device into landscape mode to determine its size.
I have made boolean values. e.g. isMobileDevice
, boolean and not a function
export const isMobileDevice = (() => {
const deviceInformation = getDeviceTypeInfo()
return deviceInformation.deviceType === "Mobile"
})()
import {
LANDSCAPE,
LAPTOP_SMALL,
LAPTOP_MEDIUM,
LARGE_SCREEN,
SUPER_LARGE_SCREEN,
MOBILE_SMALL,
MOBILE_MEDIUM,
MOBILE_LARGE,
TABLET,
IPAD_PRO,
getDeviceTypeInfo
} from "./utilResponsive"
const sizeDevice = () => {
const { deviceTypeVariant: deviceType, orientation } = getDeviceTypeInfo()
const isLandscape = orientation === LANDSCAPE
const isPortrait = !isLandscape
const isSmartphoneSmall = deviceType === MOBILE_SMALL
const isSmartphoneMedium = deviceType === MOBILE_MEDIUM
const isSmartphoneLarge = deviceType === MOBILE_LARGE
const isMaxSmartphone =
isSmartphoneSmall || isSmartphoneMedium || isSmartphoneLarge
const isSuperLargeScreen = deviceType === SUPER_LARGE_SCREEN
const isMinLargeScreen = deviceType === LARGE_SCREEN || isSuperLargeScreen
const isMinLaptop =
deviceType === LAPTOP_SMALL ||
deviceType === LAPTOP_MEDIUM ||
isMinLargeScreen
const isMinTablet =
deviceType === TABLET || deviceType === IPAD_PRO || isMinLaptop
const isMinSmartphoneLarge = isSmartphoneLarge || isMinLaptop
const isMinSmartphoneMedium = isSmartphoneMedium || isSmartphoneLarge
return {
isPortrait,
isLandscape,
isSmartphoneSmall,
isSmartphoneMedium,
isSmartphoneLarge,
isMaxSmartphone,
isMinSmartphoneMedium,
isMinSmartphoneLarge,
isMinTablet,
isMinLaptop,
isMinLargeScreen,
isSuperLargeScreen
}
}
What do you think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.