Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

define a media query in styled components

const CardWrapper = styled.div`
  display: flex;
  flex-direction: row;
  @media (max-width: 768px) {
    flex-direction: column;
  }
`;
Comment

conditional styled components with media query

import styled, { css } from 'styled-components'

const YourComponent = styled.div`
  //...
  
  ${props => props.isFirstPage && css`
     @media only screen and (max-width: 480px) {
       padding: 8px 8px 24px 8px
     }
  `}
`;
Comment

media queries in styled components

export const device = {
  mobileS: `(min-width: ${size.mobileS})`,
  mobileM: `(min-width: ${size.mobileM})`,
  mobileL: `(min-width: ${size.mobileL})`,
  tablet: `(min-width: ${size.tablet})`,
  laptop: `(min-width: ${size.laptop})`,
  laptopL: `(min-width: ${size.laptopL})`,
  desktop: `(min-width: ${size.desktop})`,
  desktopL: `(min-width: ${size.desktop})`
};
Comment

media queries in styled components

const size = {
  mobileS: '320px',
  mobileM: '375px',
  mobileL: '425px',
  tablet: '768px',
  laptop: '1024px',
  laptopL: '1440px',
  desktop: '2560px'
}
Comment

media query with styled-components

// You first need to install 'styled-components' from your package manager

import { useState } from 'react'
import styled from 'styled-components'

const DivContainer = styled.div`
    border-radius: .5rem;
    padding-block: .5rem;
    box-shadow: 1px 1px 5px rgba(25, 25, 25, .65);
    
    // Media query
      @media (min-width: 768px) {
        width: auto;
      }
`

const InputControl = styled.input`
	width: 80%;
    padding: .5rem;
    border-radius: .5rem;
    margin-inline: auto;
    background-color: ${({inputLength}) => inputLength < 1 
                                          ? 'maroon': 'transparent' };
    border: ${({inputLength}) => inputLength < 1 
                                		  ? '1px solid red': 'none' };
    color: ${({inputLength}) => inputLength < 1 ? 'white': 'black' };
    
    // Media query
      @media (min-width: 768px) {
        width: 100%;
      }
`

const userName = () => setUserName(userName)

const Card = () => (
  const [ userName, setUserName] = ('');

  // Instead of regular <div></div> Tag
  // You wrap your elements around your 'custom styled component'
  <DivContainer>
  	<InputControl inputLength={userName.length} 
		value={userName} 
		onChange{handleUserName} 
		placeholder="Enter your name" />
  </DivContainer>
)

// With love @kouqhar
Comment

PREVIOUS NEXT
Code Example
Typescript :: get type of element of array typescript 
Typescript :: serverless.ps1 cannot be loaded because running scripts is disabled on this system. 
Typescript :: nuxt 3 postcss 
Typescript :: git squash commits on branch 
Typescript :: web3.js 
Typescript :: typescript null and undefined check 
Typescript :: type script array 
Typescript :: python discord action when someone reacts to message 
Typescript :: typescript http get attach headers 
Typescript :: input fc typescript 
Typescript :: Custom validation for phone-number using class-validator package 
Typescript :: links a otros components angular 
Typescript :: angular animation done event type typescript 
Typescript :: react inherit html input props 
Typescript :: eliminar un elemento de un array typescript 
Typescript :: typescript date before 
Typescript :: go Array’s length is part of its type. 
Typescript :: typescript string concatenation best practice 
Typescript :: file reader with promise 
Typescript :: Unshift type Typescript 
Typescript :: invoke lambda after cdk deploy 
Typescript :: how to reset windows update components in windows 
Typescript :: is missing in props validation typescript 
Typescript :: nest js get request response 
Typescript :: how to create multiple sheets in excel using python in openpyxml 
Typescript :: testing in different environments 
Typescript :: react hide elements from window print 
Typescript :: how to get an object from array of objects in java 
Typescript :: highcharts print 
Typescript :: What do HTTP requests and responses look like? 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =