Transitioning from feelings to sewing: incorporate a duo of properties within variations and breakpoints

I was thinking about how to convert this styled-emotion code into stitches. Essentially, I need to handle the onlyShowOnDesktop and breakpoint props.

The definition of breakpoint is as follows:

const breakpoint = isTopNavigationBreakPoint ? theme.defaultBreakpoints.xl : theme.defaultBreakpoints.m

This will return either 1280 or 600 depending on whether isTopNavigationBreakPoint is included.

The code structure is like this:

export const Visible = styled.div<{
  onlyShowOnDesktop?: boolean
  breakpoint?: number
  selected?: boolean
}>`
  display: ${(props) => (props.onlyShowOnDesktop ? 'none' : 'unset')};
  ${({ onlyShowOnDesktop, breakpoint }) =>
    `
  @media(min-width: ${breakpoint}px) {
        display: ${onlyShowOnDesktop ? 'unset' : 'none'};
      }
  `}
`

I'm questioning how to manage the @media section. My current idea involves having 2 variants with breakpoints of 600 and 1280 and nested inside them another variant for onlyShowOnDesktop with objects for true and false. Each object would have a display property with values of unset and none, respectively. However, I am unsure if we should use variants nested in media queries?

If anyone has any suggestions or examples related to using stitches in this scenario, it would be greatly appreciated as I haven't found any online resources addressing this specific case.

Answer №1

If by chance someone comes across this in the future:

[isTopNavigationBreakPoint ? '@xlUp' : '@mUp']: {
  display: onlyShowOnDesktop ? 'unset' : 'none',
}

When passing isTopNavigationBreakPoint as a prop, for screen sizes at @xlUp, set display to 'unset'. If also passing onlyShowOnDesktop prop, else set display to 'none' if onlyShowOnDesktop was not passed.

Same applies for @mUp if isTopNavigationBreakpoint wasn't passed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing a switch statement for form validation

Currently, I am in the process of creating a form validation that involves two conditions for validation. I'm considering using a combination of switch case and if else statements. Would this be an appropriate approach or is it generally discouraged? ...

Utilizing Astro Project to gather content from various directories containing Markdown files

I am embarking on a project to convert Mark Down files (MD) into HTML format. While delving into this endeavor, I have chosen to utilize Astro due to its compatibility with MD to HTML conversion, even though I am relatively new to ASTRO or JSX style coding ...

Creating a text shadow effect with text that has a transparent color

I am attempting to replicate the design shown below using the CSS text-shadow property, but I keep getting a solid color outcome. I have tried using an rgba value of 255,0,0,0.0 for the font-color and text-shadow like this: text-shadow: -1px -1px 0 #0 ...

How to Efficiently Display Multiple Modals with React Components

I'm currently navigating the world of React and coding in general. I am facing an issue where multiple modals are being rendered simultaneously within the same component, creating a confusing display where it seems like all links trigger the content f ...

Is it feasible to conceal a certain field once the user has chosen another field?

Looking to create an IF statement that will help me establish a specific rule. On a customer portal page, customers can open tickets via a form where they provide information such as "software product" and "environment" from dropdown lists, as well as othe ...

Scrollbar generation causing spacing issues in Internet Explorer

So I've been working on implementing a scrollable div with a specific code overflow: auto; However, for some reason, when viewed in Internet Explorer, the scroll creates an unexpected margin on the right side. It functions properly on both Chrome an ...

What is the process for incorporating Dark Mode into a map?

Hey there! I'm diving into the world of web development and experimenting with a new react google maps package. I used npm i @vis.gl/react-google--maps to install it. I'm curious if there's a way to switch the embedded google map on my webs ...

Exploring the mern.io scaffolder tool - Unraveling the essence of the .need method

While exploring the code of the scaffolder mern.io, I came across an intriguing method called ".need". It appeared to be related to es6 classes, but unfortunately, I couldn't find any valuable information about it. Thus, I'm curious to know: what ...

Having difficulty adjusting the padding of the Material UI table

I have been using the Table component provided by the material-ui library in my React project. However, I have encountered an issue where each row, including the header, has a padding of 24px on the top and bottom that I am unable to modify or overwrite. D ...

Guide to implementing setTimeout in a .map() function in ReactJS

I am currently working on a project that involves an array of players. Whenever a user adds a new player to this array, I need it to be displayed one at a time with a 500ms interval between each player. Below is the code snippet I have written for this f ...

The trick to organizing an array in useSelector() without triggering endless re-renders

I'm currently attempting to display a sorted list of anecdotes by utilizing useSelector() within the Redux framework for this exercise in my current course. However, every time I try to access the anecdotes from the state, I consistently encounter th ...

Strategies for passing multiple props to a function in React using TypeScript, such as useState([]) and useState(boolean)

Dealing with API Structure { "default": [ { "id": 1, "name": "A" }, { "id": 2, "name": "B" }, { "id": 3, "name" ...

Issue encountered: "An error has occurred stating that your cache folder contains files owned by root. This is likely a result of a bug present in older versions of npm. This issue arose during the execution of the

While attempting to create a new react app using the command npx create-react-app example_app, I encountered the following issue: [ Your cache folder contains root-owned files, due to a bug in previous versions of npm which has since been addressed sudo ...

Fairly intricate React function component declaration with TypeScript

const withAuth = () => <OriginalProps extends {}>( Component: React.ComponentType<OriginalProps & IAuthContextInterface> ) => { } (withAuth()(PrivateRoute)) // this is how the HOC called Could someone simplify what this function d ...

Arranging Bootstrap inputs horizontally with lengthy labels

When placing two input fields in a row, such as a drop down menu, with labels of varying lengths, the alignment of the inputs can become skewed. This issue persists even when attempting to add breaks in the code due to unpredictable wrapping behavior at di ...

Dimensions of Titles (H1, H2 etc)

I am looking to have a unique background color for my headers from h1 through h6. The width of this background should match the width of the text in the header, along with padding. Currently, the background width is matching the container instead of the te ...

Press here to unveil and modify using the Redactor JS WYSIWYG HTML editor

I am working on a project where I have three separate divs that are set to be editable using the attribute contenteditable="true". Additionally, I have configured the redactor wysiwyg toolbar to remain fixed on the page. Here is the structure in HTML: &l ...

Enhancing User Experience on Android Devices: Automatic Website Zoom-In Feature for Responsive Design

For the first time, I am delving into creating a responsive website design. I seem to be encountering difficulties when it comes to smartphones. I have been using the following meta-tag to ensure that the website loads "zoomed in". (I found this method on ...

Tips for sending an email to an address from a user input field in React.js/Express.js

I am currently developing an email application that allows users to send emails to any recipient of their choice. The challenge I'm facing is that I need a way to send emails to user-specified email addresses without requiring passwords or user.id det ...

What steps should I follow to create a cohesive background design using CSS?

https://i.sstatic.net/e3LYL.png Is there a way to combine two separate div elements in CSS? Currently, the image Row and col are not connected to the above SVG blob. How can I utilize the blob as a background? Based on the code provided below, they appear ...