Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): responsive layouts based on width of drawer #4836

Merged

Conversation

darrelhong
Copy link
Contributor

Problem

breakpoints might not be flexible enough as the current layout allows a split drawer and content up to minimum width of 768px which means each column can get very narrow. Since breakpoints are based on the width of the entire page, it can't account for the split panels. This mainly affects the custom date range input in form builder.

Solution

Most scenarios can be satisfied by simply setting breakpoints at lg instead of md, as per #4835. This PR adds a hook that watches the width of the drawer container then layouts can be changed at any arbitrary width.

Pros:
More flexible

Cons:
Not the cleanest code

Room for improvement:
hook could probably be optimised to give it more structure as opposed to returning the raw width?

Before & After Screenshots

BEFORE
Screen Shot 2022-09-09 at 1 47 06 PM

WITH BREAKPOINTS
Screen Shot 2022-09-09 at 1 46 23 PM

WITH ARBITRARY WIDTH
Screen Shot 2022-09-09 at 1 47 49 PM

Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hook is fine, approach makes sense. thanks, lgtm.

@darrelhong darrelhong force-pushed the form-v2/listen-drawer-width branch from 6e964c9 to 4e5fd5c Compare September 12, 2022 07:20
@darrelhong darrelhong changed the title WIP fix(v2): responsive layouts based on width of drawer fix(v2): responsive layouts based on width of drawer Sep 12, 2022
@darrelhong darrelhong requested a review from karrui September 12, 2022 07:22
Copy link
Contributor

@timotheeg timotheeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, one minor comment to save on an unnecessary function call.

Comment on lines 28 to 27
const { useMeasureDrawer } = useCreatePageSidebar()
const [drawerRef] = useMeasureDrawer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be merged into line 25 instead:

const { activeTab, isDrawerOpen, useMeasureDrawer: [drawerRef] } = useCreatePageSidebar()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tunnel vision got me, fixed. kept it as 2 lines as its a tad more readable imo

@darrelhong darrelhong force-pushed the form-v2/listen-drawer-width branch from 4e5fd5c to 69eb381 Compare September 14, 2022 07:34
@darrelhong darrelhong requested review from timotheeg and karrui and removed request for karrui and timotheeg September 14, 2022 07:39
@@ -151,6 +154,8 @@ export const useCreatePageSidebarContext =
setPendingTab(undefined)
}, [isMobile, pendingTab, setFieldsToInactive])

const useMeasureDrawer = useMeasure()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should not prefix non-hooks with use keyword, causes unnecessary confusion. should we call this drawerDimensions instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we only need the drawer width too; suggest just returning drawerWidth from this hook instead of the entire dimensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on both points

@darrelhong darrelhong force-pushed the form-v2/listen-drawer-width branch from 69eb381 to 681869c Compare September 14, 2022 08:56
Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants