I have Navigation component that is the same at every page of my gatsby website. In development mode every styles are working properly. Button in dev mode on every page:
But in production build of gatsby only on home page ("/") it looks like that:
In production mode, on every page it works like in develop except home page, on home page styles are not apply only on this one button. And i have no idea why.
This is how Navigation component looks like:
const NavigationSearchBar = () => {
const { isMobile, windowWidth } = useResize()
const { setSearch } = useNavigationSearchBar()
return (
<StyledContainer>
<Row>
{!isMobile && (
<Col md="2">
<NavbarBrand href="/">
<img src={'/images/logo.svg'} />
</NavbarBrand>
</Col>
)}
<StyledSearchBar sm="12" md={{ size: 6, offset: 2 }}>
<StyledForm>
<SearchInput
type="text"
name="search"
onChange={e => setSearch(e.target.value)}
/>
<SimpleButton width="160px" background="primary" color="whiteColor">
Search
</SimpleButton>
</StyledForm>
</StyledSearchBar>
<StyledCol2 sm="12" lg="2">
<SimpleButton
width={windowWidth >= 400 ? '160px' : '100%'}
background="primaryOrange"
color="blackColor"
>
On Sale
</SimpleButton>
</StyledCol2>
</Row>
</StyledContainer>
)
}
export default NavigationSearchBar
Nothing special, there is no business logic here. This is how styles in styled components looks like for this button:
const SimpleButton = styled.button`
width: ${({ width }) => width};
background: ${({ background }) =>
theme.colors[background] ? theme.colors[background] : background};
padding: ${({ padding }) => (padding ? padding : '0.5rem 0')};
text-align: center;
border: 1px solid
${({ background }) =>
theme.colors[background] ? theme.colors[background] : background};
border-radius: 8px;
text-transform: uppercase;
color: ${({ color }) => (theme.colors[color] ? theme.colors[color] : color)};
letter-spacing: 1.5%;
font-weight: ${theme.fontWeights.medium};
position: relative;
z-index: 1;
`
I think it could be some issue with gatsby build process, because everything except this one button in production mode styles the same way as in development mode.
Do you have any idea why it's not working ?
I've just noticed that on refresh there is no styles, but if i get on page through gatsby link inside application styles are applied. For example if i'm on page /login every styles are applied, but when i refresh by clicking F5 gatsby enters /login/ and every styles disappear (this happens only in production mode).
I forget to install styled-components plugin for gatsby.
On develop everything working correctly, but on build version issues starts off.
Todo:
npm install gatsby-plugin-styled-components styled-components babel-plugin-styled-components
And don't forget to add plugin to gatsby-config.js file:
module.exports = {
/* Your site config here */
plugins: [
....other plugins
'gatsby-plugin-styled-components',
],
}
Related
I have problem, I use this piece of code to responsive layout. In my computer when I use programming tools to watch how my code look in phone size, it look perfect but when I deployment it this not work at all.
I do not understand why, because I have the same piece of code in another sub-page, and there it work good.
import MediaQuery, { useMediaQuery } from "react-responsive";
const Phone = useMediaQuery({
query: "(max-width: 641px)"
});
<Card style={{ width: Phone ? '100%' : "32%", float: "left", backgroundColor: "#003263", height: "380px"}} >
Hello I had the same problem, I searched for several solutions, but I ended up using material UI.
import React from 'react'
import useMediaQuery from '#mui/material/useMediaQuery'
const ProductCard = ({ name, category, description, tech, url, image, color }) => {
const isMobile = useMediaQuery('(max-width: 786px)')
return (
<div style={{ margin: isMobile ? '0px' : '18px' }}>
<p>{name}</p>
<p>{category}...</p>
</div>
)
}
export default ProductCard
It worked perfect, on mobile in the first render it detects the variable correctly and makes the css change, but you would have to install MUI
I am using this api to create customize google calendar.
https://github.com/ericz1803/react-google-calendar
Here are the codeSandbox for demo, the tooltip is perfectly working.
https://codesandbox.io/s/cocky-rgb-2y3t7?file=/src/App.js
Then, I copied the same code into mine project with all path, API ... changed.
Every things works well, but the tooltip doesn't appear any more.
import React from "react";
import "./styles.css";
import Calendar from "#ericz1803/react-google-calendar";
import { css } from "#emotion/react";
const API_KEY = "AIzaSyAKzScoADeBmp6qUsEzrwZhLqb6WARNFOo";
//replace calendar id with one you want to test
let calendars = [
{ calendarId: "c_7q0ai3mn1p9b880f7llhbnv364#group.calendar.google.com" }
];
let styles = {
//you can use object styles
calendar: {
borderWidth: "3px" //make outer edge of calendar thicker
},
today: css`
/* highlight today by making the text red and giving it a red border */
color: red;
border: 1px solid red;
`
};
export default function App() {
return (
<div className="App">
<body>
<div
style={{
width: "90%",
paddingTop: "50px",
paddingBottom: "50px",
margin: "auto",
maxWidth: "1200px"
}}
>
<Calendar apiKey={API_KEY} calendars={calendars} styles={styles} />
</div>
</body>
</div>
);
}
There is open issue for same on github.
Till it gets fixed, use the same version of the package which is used in the sandbox demo, it doesn't have that bug.
"#ericz1803/react-google-calendar": "4.0.1"
I am trying to implement a hover effect in the react component using react inline-styling.
const InfoWindow: React.FC<IInfoWindowProps> = ({ room }) => {
const info_window_image = {
width: "100%",
height: "168px",
background: `url(${room.pictures[0].image.large}) no-repeat`,
backgroundSize: "contain",
cursor: 'pointer'
};
return (
<div className="info_window_container">
<div style={info_window_image} />
</div>
)
};
div tag under info_window_container gets style object info_window_image .
I can successfully receive an image from API but I want to give zoom-in animation when the user hovers the image in the component.
I gave className to the div and styled in CSS file however it does not work. Styles I declared in CSS file do not render.
How can I make hover or focus effect in react-inline-styling?
I'm trying to configure the style/css of my Antd React app to be mobile ready.
My main menu uses the Reactive Sider Menu seen here.
My issue is when I'm viewing with a mobile viewport it's kinda ugly and it squashes everything outside of the menu. And the little tab to expand/condense the menu covers some of my other components.
I'd much prefer the design that they have in the Ant Design Pro demo.
But I'm not sure how to create this exactly. Has anyone attempted it before? It seems to use a Drawer when it's in a mobile viewport as opposed to using the Sider in the Layout API.
Figured this out.
Essentially my solution (not sure if this is what they actually did in Ant Design Pro) is to use the Reactive Sider Menu example for the desktop and use a Drawer for mobile.
The same Toggle button in the Reactive Sider Menu example can hide/close the Sider (in Desktop) and Drawer (in mobile).
The trick was using CSS Media Queries to hide the Drawer in Desktop and hide the Sider in mobile so each could do their thing.
CSS
.hideOnMobile {
display: none;
}
#media only screen and (min-width: 768px) {
.hideOnMobile {
display: block;
}
}
.hideOnDesktop {
display: block;
}
#media only screen and (min-width: 768px) {
.hideOnDesktop {
display: none;
}
}
App.js
const App = () => {
// sider and drawer toggle
const [isToggled, setToggled] = useState(false);
const toggleTrueFalse = () => setToggled(!isToggled);
const onClose = () => {
setToggled(false);
};
return (
<Layout style={{ minHeight: "100vh" }}>
<Drawer
placement="left"
onClose={onClose}
closable={false}
visible={isToggled}
className="hideOnDesktop"
bodyStyle={{ backgroundColor: "#001529", padding: "0" }}
>
<Navbar />
</Drawer>
<Sider
breakpoint="lg"
collapsedWidth="0"
collapsed={isToggled}
onBreakpoint={(broken) => {
setToggled(broken);
}}
className="hideOnMobile"
>
<Navbar />
</Sider>
<Layout className="site-layout">
<Header
className="site-layout-background"
style={{ padding: 0 }}
>
<Row>
{React.createElement(
isToggled ? MenuUnfoldOutlined : MenuFoldOutlined,
{
className: "trigger",
onClick: toggleTrueFalse,
}
)}
<TopNavbar />
</Row>
</Header>
...
Also per the Antd docs for the Drawer component you can use the bodyStyle prop to set the background color and remove the padding so the menu sits flush to the sides of the Drawer.
I'm using <Transition> as explained in main documentation of React Transition Group.
import React from 'react';
import PropTypes from 'prop-types';
import Transition from 'react-transition-group/Transition';
const defaultStyle = {
transition: `opacity 300ms ease-in-out`,
opacity: 0,
};
const transitionStyles = {
entering: { opacity: 1 },
entered: { opacity: 1 },
};
const Fade = ({
in: inProp,
children,
}) => (
<Transition in={inProp} timeout={300}>
{state => (
<div
style={{
...defaultStyle,
...transitionStyles[state],
}}
>
{children}
</div>
)}
</Transition>
);
Fade.propTypes = {
in: PropTypes.bool.isRequired,
children: PropTypes.node.isRequired,
};
export default Fade;
It works, but not so well with Material UI, especially with Buttons, everywhere on my app: when I click on them, appears a white div behind them:
<div in="false" style="position: absolute; top: -88.218px; left: -97.218px; height: 220.436px; width: 220.436px; border-radius: 50%; background-color: rgb(255, 255, 255);"></div>
and this weird error in console:
Warning: Unknown props `onExited`, `appear`, `enter`, `exit` on <div> tag. Remove these props from the element.
Those props are about Transition, but I can't understand the problem.
I'm using React 15.6.1, Material ui 0.18.7 and React Transition Group 2.2.0
I encountered this bug today, and I logged an issue + repro case on their github.
https://github.com/callemall/material-ui/issues/8046
(repro: https://codesandbox.io/s/q9o5q0l5nw)
I have tested in v1.0.0-beta.8 and it looks like it's working fine (https://codesandbox.io/s/r5nplz89nn).
The project's stance is essentially "material-ui v0.x is legacy code".
So your options are either; disable ripples across your app, fix it for them via a PR, or move to the unfinished v1 beta branch.