GithubHelp home page GithubHelp logo

Comments (5)

ls-sam-leatherdale avatar ls-sam-leatherdale commented on September 10, 2024 1

Hi @PetroPavlenko, thanks, that is a better implementation, I didn't focus too closely on the types in my solution. 👍

from styled-bootstrap-grid.

ls-sam-leatherdale avatar ls-sam-leatherdale commented on September 10, 2024

Yep, same issue here with the Down props, it's all off by one. I want this component to only be visible at lg and above.

<Col lg={6} hiddenLgDown>

If I set to hiddenMdDown, it hides it at md, but md - lg is visible.
If I set to hiddenLgDown, then it hides it between md - lg, but also hides it at lg.

The fix would break backwards compatibility so you might need to add new properties instead of changing the new ones, something like hiddenBelowMd or hiddenAboveLg.

from styled-bootstrap-grid.

ls-sam-leatherdale avatar ls-sam-leatherdale commented on September 10, 2024

@julijatrescenko In the meantime, try this styled Col component I used, it will still use your breakpoints:

export type ColProps = {
  /**
   * Hide only > the specified breakpoint, instead of >=.
   */
  hiddenAbove?: string;
  /**
   * Hide only < the specified breakpoint, instead of <=.
   */
  hiddenBelow?: string;
};

const Col = styled(OriginalCol)`
  @media (max-width: ${(props: ColProps) =>
      props.hiddenBelow && `${getBreakpoint(props, props.hiddenBelow) - 1}px`}) {
    display: none;
  }
  @media (min-width: ${(props: ColProps) =>
      props.hiddenAbove && `${getBreakpoint(props, props.hiddenAbove) + 1}px`}) {
    display: none;
  }
`;

export { Col };
const getBreakpoints = (props): { [key: string]: number } => ({
  ...((props.theme &&
    props.theme.styledBootstrapGrid &&
    props.theme.styledBootstrapGrid.breakpoints) ||
    {}),
});
function getBreakpoint(props, bp: string): number {
  return getBreakpoints(props)[bp];
}

You can use it like:

<Col xl={3} hiddenBelow="xl" />

from styled-bootstrap-grid.

PetroPavlenko avatar PetroPavlenko commented on September 10, 2024

I think you can use slightly better typed

import styled from "styled-components";
import { Col as OriginalCol, Breakpoints } from "styled-bootstrap-grid";

type BreakpointsKeys = keyof typeof MediaLabels

const getBreakpoint = (props: any, bp: BreakpointsKeys): number =>
  props?.theme?.styledBootstrapGrid?.breakpoints[bp] || 0;

export const RespCol = styled(OriginalCol)<{ hiddenAbove?: BreakpointsKeys}>`
  ${props => props.hiddenAbove && `
    @media (min-width: ${`${getBreakpoint(props, props.hiddenAbove) + 1}px`}) {
      display: none;
    }
  `}
`;

from styled-bootstrap-grid.

PetroPavlenko avatar PetroPavlenko commented on September 10, 2024

Hi @dragma Looks like in 3.1 doesn't contain PR #57 that help with this. So I cannot pull it from npm. Can you bump version with fix ?

from styled-bootstrap-grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.