processing / p5.js-web-editor

The p5.js Editor is a website for creating p5.js sketches, with a focus on making coding accessible and inclusive for artists, designers, educators, beginners, and anyone else! You can create, share, or remix p5.js sketches without needing to download or configure anything.
https://editor.p5js.org
GNU Lesser General Public License v2.1
1.3k stars 1.26k forks source link

Centralising breakpoints #3035

Closed Keshav-0907 closed 3 months ago

Keshav-0907 commented 4 months ago

Increasing Access

Having a centralised approach for breakpoints will enhance the code readability, collaboration, and scalability. It will ensure a consistent and efficient approach to handling responsiveness in our project.

Feature enhancement details

The current code appears to be decentralized regarding breakpoints, which may impact maintainability and consistency By consolidating breakpoints in a dedicated file, we can streamline development, making it easier to manage and update responsive design across the editor.

Approch

Using a centralised breakpoints.js

const breakpoints = {
  mobile: 767,
  tablet: 1024, //  Just for reference, as we don't have distinct breakpoints for tablets now
};

Importing the breakpoints in the components where we need to use media queries.

import breakpoints from './breakpoints';

const aRandomComponent = () => {
  const isMobile = useMediaQuery({ maxWidth: breakpoints.mobile });

  ....
};

I want to work on this issue

lindapaiste commented 4 months ago

I absolutely agree and you'll find some comments from me in the code like //TODO: centralize breakpoints.

We can create and export a useIsMobile hook that returns a boolean.

Note that there are some places on the code where used non-standard breakpoints on purpose based on the size of the content and what fits. These aren't a problem, IMO. But we do want our standard breakpoint(s) to be declared in one place instead of everywhere.

Keshav-0907 commented 4 months ago

To handle custom breakpoints, we can pass a 'customBreakpoint' parameter to 'useIsMobile' hook.

And if the customBreakpoint is provided ---> use that value; Otherwise --> use the default value of 767.