Users should be able to:
See: Weather Conditions of OpenWeather API
See: Setup TypeScript with React - React TypeScript CheatSheet
See: OpenWeather One Call API docs
Convert a timestamp (seconds) into hours (e.g 10 PM or 11 AM):
dayjs(timestamp * 1000).format('h A');
Create a ScrollableContainer
component:
export default function ScrollableContainer({ children }) {
return <div className="overflow-x-scroll no-scrollbar">{children}</div>;
}
Add a new CSS class no-scrollbar
in tailwind.config.js
file. That will hide the scrollbar but keep the scroll functionality.
Notice that we don't use overflow-x-hidden
class because it'll disable the scroll.
const plugin = require('tailwindcss/plugin');
module.exports = {
/* ... */
plugins: [
plugin(function ({ addUtilities }) {
const newUtilities = {
'.no-scrollbar::-webkit-scrollbar': {
display: 'none' /* Chrome */,
},
'.no-scrollbar': {
'-ms-overflow-style': 'none' /* IE and Edge */,
scrollbarWidth: 'none' /* Firefox */,
},
};
addUtilities(newUtilities);
}),
],
};
Create a chart that its width is greater than the container:
<ScrollableContainer>
<LineChart data={chartData} width={1200}>
...
</LineChart>
</ScrollableContainer>
Source : How to create scrollable element in Tailwind without a scrollbar - Stack Overflow
// ScrollableContainer.tsx
import { Swiper, SwiperSlide } from 'swiper/react';
export default function ScrollableContainer(props) {
return (
<Swiper
slidesPerView={'auto'}
freeMode={true}
// Prevent the whole page to be swiped
touchMoveStopPropagation={true}
>
{/* The width is the chart's */}
<SwiperSlide style={{ width: '1200px' }}>{props.children}</SwiperSlide>
</Swiper>
);
}
Use the ScrollableContainer
component:
<ScrollableContainer>
<LineChart data={chartData} width={1200} height={200}>
<Line type="linear" dataKey="temperature" />
</LineChart>
</ScrollableContainer>
We set the width of SwiperSlide
to 1200px
to make sure we can scroll over the whole chart.
https://www.freecodecamp.org/news/make-react-apps-responsive/
The example below use Merriweather font.
I've used Fontsource to download the font.
Fontsource is a fonts monorepo bundled into individual NPM packages. That means you can download several Google fonts with the command npm install
.
Download Merriweather font:
npm install @fontsource/merriweather-sans
Import the font in the React app entry file App.tsx
or App.js
.
import '@fontsource/merriweather-sans';
Then add Merriweather Sans
in your Tailwind config file. E.g. tailwind.config.js
.
module.exports = {
theme: {
fontFamily: {
sans: ['Merriweather Sans', 'sans-serif'],
},
},
That will overwrite Tailwind default font family settings and will create a class named font-sans
that you can use to styling React components.
Finally, add the class font-sans
to your App
component in App.tsx
or App.js
file.
function App() {
return (
<div className="App font-sans">
<HomePage />
<DetailsPage />
</div>
);
}
When the user type a city in the search input field, the app shows a list of suggestions of city. The Openweather API needs the latitude & longitude to get data. But we want to type the city name, not the lat & lon. That's why we are going to use the Geocoding API to convert the city name that user type to the coordinate.
How to Build a Weather Application with React and React Hooks
3D Weather Icons by hosein_bagheri
https://objectifsmartphone.fr/wp-content/uploads/2021/06/iOS-15-weather-app.jpg