Themes within themes with React, TypeScript, and Styled Components ✨

A recent project came with some big challenges. The client wanted a demo experience that would display a range of different websites within a branded ‘container’. These demo websites would be interactive within a mock desktop or mobile device, each with its own individual theme. In this article, I will dive deeper into:

  1. How we set up the project files
  2. Theming using Styled Components

This was challenging enough, but on top of this, we needed to give the user the ability to toggle between the mocked ‘desktop’ display and ‘mobile’ display modes, all within this static container, without using media queries. I will address this challenge in a follow up article.

Here are two illustrations of what we produced:

Mockup design with mobile site demo in the centre

Mobile view

Desktop View

How many themes do we need? 💭

The first step here was figuring out how many themes we were going to need, and secondly, how to set up these themes. It was crucial that we set this up correctly from the beginning, to save us a lot of grief in the long run.

  1. Here we need one theme for the static container, which will stay the same regardless of the active demo. This is going to have a branded dark theme to match the Client’s style guide.
  2. We also need one theme per ‘demo’, which will change depending on which demo is active. So three demos would mean three more themes, etc.

#programming #typescript #javascript #styled-components #react

What is GEEK

Buddha Community

Themes within themes with React, TypeScript, and Styled Components ✨
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

Themes within themes with React, TypeScript, and Styled Components ✨

A recent project came with some big challenges. The client wanted a demo experience that would display a range of different websites within a branded ‘container’. These demo websites would be interactive within a mock desktop or mobile device, each with its own individual theme. In this article, I will dive deeper into:

  1. How we set up the project files
  2. Theming using Styled Components

This was challenging enough, but on top of this, we needed to give the user the ability to toggle between the mocked ‘desktop’ display and ‘mobile’ display modes, all within this static container, without using media queries. I will address this challenge in a follow up article.

Here are two illustrations of what we produced:

Mockup design with mobile site demo in the centre

Mobile view

Desktop View

How many themes do we need? 💭

The first step here was figuring out how many themes we were going to need, and secondly, how to set up these themes. It was crucial that we set this up correctly from the beginning, to save us a lot of grief in the long run.

  1. Here we need one theme for the static container, which will stay the same regardless of the active demo. This is going to have a branded dark theme to match the Client’s style guide.
  2. We also need one theme per ‘demo’, which will change depending on which demo is active. So three demos would mean three more themes, etc.

#programming #typescript #javascript #styled-components #react

Karine  Crooks

Karine Crooks

1593511347

Guide to an auto light theme in React with styled-components and typescript

ELI5

I

am pretty sure that a lot of people, including me, are huge fans of color theming. Although every single device that I own is set to the dark mode I love that feeling of being able to choose rather than being forced to use that bright white theme at the 3:48 AM day before the release. (I love you stripe ❤)

Disclaimer

I’m not going to go in depths with context, typescript, or styled-components, I will just guide you through one of many solutions that I find comfortable using.


Let’s start by creating the app first. I’m going to do the minimal setup of the project, that said I’m just going to use the good old “create-react-app”.

If you don’t trust me about this part just go through the docs or skip the next part.

$ npx create-react-app auto-theme --template typescript

I sincerely suggest you using eslint and prettier with typescript because it’s a killer combo.

As far as styled-components are concerned I’ll follow through their official documentation as well.

You start by adding

$ yarn add styled-components

And because we’re doing this with typescript we’re going to have to add types as well.

$ yarn add -D @types/styled-components

Okay, so you should’ve ended up with something like this

Now we’ll be removing the CSS files and that test, you can just paste the command in the root of your project and it’ll do it for you.

$ rm -rf src/App.css src/App.test.tsx src/index.css src/logo.svg

#styled-components #react-context #react #typescript #programming

Aubrey  Price

Aubrey Price

1591207740

Implementing a dark theme toggle with react-redux and styled-components

To keep things simple and concise, we’ll start fresh with npx create-react-app dark-toggle . While we’re in our command line, let’s get the npm packages out of the way as well:
npm install styled-components styled-theming redux react-redux
styled-components: we’ll use this library to create isolated components that encapsulate their own styling
styled-theming: this library offers a very clean API to work with multiple themes in your styled components
redux and react-redux will do the heavy lifting regarding state management

#styled-components #react #react-hook #dark-theme #redux #react-native

Verdie  Murray

Verdie Murray

1636236360

How to add Cypress for Create React App with TypeScript

In this lesson we look at how to add #cypress with code coverage support for a Create #React App application with #TypeScript.

In the end you will have a developer flow that can save you a bunch of time in testing effort 

#react-native #react #cypress #typescript