简体   繁体   中英

Styled Component/ React/ Semantic / Props and calc

Hello i have a menu which is working normally I use the property to set its size open and closed and also in mobile resolution. But I tried to do the same with my content grid my second column and not getting the value I don't know if it has to do with calc:

code:

    <ContainerGrid style={{background: '#eee'}}>

    {/* <ContainerGridColumn mobile={2} > */}
    <ContainerGridColumnMenu status={open ? '12.5%' : '50px'} mobile= {open ? '31.25%' : '12.5%'} >
    <div style={{background:'#000', width:'100%', height:'100%'}}>

    </div>
    </ContainerGridColumnMenu>
    <ContainerContent desktop={open ? '87.5%' : 'calc(87.5%+50px)'} mobile = { open ? '68.75%' : '87.5%' }>
          <Button icon onClick={handleClick}>
            <Icon name="align justify" />
          </Button>
    </ContainerContent>
   </ContainerGrid>

styled:

import { Grid, Column } from 'semantic-ui-react';
import styled from 'styled-components';
import { device } from './device';

export const ContainerGrid = styled(Grid)`
    background: #eee;
`;

export const ContainerGridColumnMenu = styled(Grid.Column)`
    background: #e548;
    width: ${props => props.status} !important;
    padding: 0 !important;
    height: 100vh;
    @media only screen and (max-width: 767px) and (min-width: 320px) {
    width: ${props => props.mobile} !important;
    }
`;
export const ContainerContent = styled(Grid.Column)`
background: #e548;
width: ${props => props.desktop} !important;
padding: 0 !important;
height: 100vh;
@media only screen and (max-width: 767px) and (min-width: 320px) {
width: ${props => props.mobile} !important;
}
`;

css:

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
#root,
.App,
.ui.grid{
  height: 100vh !important;
  margin: 0 !important;
  padding:0 !important;
}

basically my red content should occupy the rest of the grid but it doesn't happen I don't know why edit:

The first error was that I was using ',' instead of '. 'na props

good but i have some problem when i pass in my props: 'calc (87.5% + 50px)' best view in codesandbox: https://codesandbox.io/s/autumn-cache-0i402

You need to update the width of both ContainerContent , Apart from that everything is perfect, Please refer to this example link: codesandbox

App.js

import React, { useState } from "react";
import { Grid, Button, Icon } from "semantic-ui-react";
import "./style.css";
import {
  ContainerGrid,
  ContainerGridColumnMenu,
  ContainerContent
} from "./styled";

export default function App() {
  const [open, setOpen] = useState(true); // declare new state variable "open" with setter
  const handleClick = e => {
    e.preventDefault();
    setOpen(!open);
  };
  return (
    <ContainerGrid style={{ background: "#eee" }}>
      {/* <ContainerGridColumn mobile={2} > */}
      <ContainerGridColumnMenu
        status={open ? "12.5%" : "calc(12.5% - 50px)"}
        mobile={open ? "31.25%" : "12.5%"}
      >
        <div style={{ background: "#000", width: "100%", height: "100%" }} />
      </ContainerGridColumnMenu>
      <ContainerContent
        desktop={open ? "87.5%" : "calc(87.5% + 50px)"}
        mobile={open ? "68.75%" : "87.5%"}
      >
        <Button icon onClick={handleClick}>
          <Icon name="align justify" />
        </Button>
      </ContainerContent>
    </ContainerGrid>
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM