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

Automatic Breakpoint for UButtonGroup and UTabs Orientation #1805

Open
maximepvrt opened this issue May 20, 2024 · 7 comments
Open

Automatic Breakpoint for UButtonGroup and UTabs Orientation #1805

maximepvrt opened this issue May 20, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@maximepvrt
Copy link
Contributor

Description

I would like to propose a feature that allows the UButtonGroup component to automatically switch its orientation between horizontal and vertical based on a responsive breakpoint. This feature would enhance the flexibility and usability of the component, particularly for responsive design.

Current Workaround:

Currently, I am using the following code to achieve this behavior:

<script setup>
const { width } = useWindowSize()
</script>

<template>
<UButtonGroup :orientation="width < 640 ? 'vertical' : 'horizontal'">
  <!-- Button items -->
</UButtonGroup>
</template>

Additional context

No response

@maximepvrt maximepvrt added the enhancement New feature or request label May 20, 2024
@noook
Copy link
Collaborator

noook commented May 21, 2024

I think this falls out of the scope of Nuxt UI. However, I can suggest using Vueuse's useElementSize to get the size of an element (say, a container) or directly the responsive breakpoint as you mentioned it using Vueuse's useBreakpoints

@MuhammadM1998
Copy link
Contributor

Not related to your request but the code you're using would produce a hydration mismatch if you're using SSR. I'd suggest passing tailwind breakpoints to ButtonGroup's ui prop instead. It's monkey patching but wouldn't produce mismatches if that's what you want.

<!-- orientation="vertical" has `flex-col` by default  -->
<UButtonGroup :ui={ wrapper: { vertical: 'sm:flex-row' }} orientation="vertical">
  ...
</UButtonGroup>

@maximepvrt
Copy link
Contributor Author

maximepvrt commented May 21, 2024

@MuhammadM1998 It's important to note that simply changing sm:flex-row to achieve a vertical or horizontal layout for the component is not sufficient. There are other classes that also need to be modified to ensure the component functions correctly in both orientations.

But I agree that handling this only with Tailwind class beakpoints and not javascript would be better

@MuhammadM1998
Copy link
Contributor

I didn't try it before but I think you're right you probably will have to tweak other classes too. I don't think they would be many but It's a hassle indeed

@noook
Copy link
Collaborator

noook commented May 21, 2024

There are actually ... many. 😂

<UButton>'s config
{
  wrapper: {
    horizontal: 'inline-flex -space-x-px',
    vertical: 'inline-flex flex-col -space-y-px',
  },
  rounded: 'rounded-md',
  shadow: 'shadow-sm',
  orientation: {
    'rounded-none': {
      horizontal: {
        start: 'rounded-s-none',
        end: 'rounded-e-none',
      },
      vertical: {
        start: 'rounded-t-none',
        end: 'rounded-b-none',
      },
    },
    'rounded-sm': {
      horizontal: {
        start: 'rounded-s-sm',
        end: 'rounded-e-sm',
      },
      vertical: {
        start: 'rounded-t-sm',
        end: 'rounded-b-sm',
      },
    },
    rounded: {
      horizontal: {
        start: 'rounded-s',
        end: 'rounded-e',
      },
      vertical: {
        start: 'rounded-t',
        end: 'rounded-b',
      },
    },
    'rounded-md': {
      horizontal: {
        start: 'rounded-s-md',
        end: 'rounded-e-md',
      },
      vertical: {
        start: 'rounded-t-md',
        end: 'rounded-b-md',
      },
    },
    'rounded-lg': {
      horizontal: {
        start: 'rounded-s-lg',
        end: 'rounded-e-lg',
      },
      vertical: {
        start: 'rounded-t-lg',
        end: 'rounded-b-lg',
      },
    },
    'rounded-xl': {
      horizontal: {
        start: 'rounded-s-xl',
        end: 'rounded-e-xl',
      },
      vertical: {
        start: 'rounded-t-xl',
        end: 'rounded-b-xl',
      },
    },
    'rounded-2xl': {
      horizontal: {
        start: 'rounded-s-2xl',
        end: 'rounded-e-2xl',
      },
      vertical: {
        start: 'rounded-t-2xl',
        end: 'rounded-b-2xl',
      },
    },
    'rounded-3xl': {
      horizontal: {
        start: 'rounded-s-3xl',
        end: 'rounded-e-3xl',
      },
      vertical: {
        start: 'rounded-t-3xl',
        end: 'rounded-b-3xl',
      },
    },
    'rounded-full': {
      horizontal: {
        start: 'rounded-s-full',
        end: 'rounded-e-full',
      },
      vertical: {
        start: 'rounded-t-full',
        end: 'rounded-b-full',
      },
    },
  },
}

@MuhammadM1998 That's right about hydration mismatch, I haven't thought of that

@MuhammadM1998
Copy link
Contributor

And here I thought it would be simple. Maybe a mismatch isn't a bad idea 😂

@maximepvrt
Copy link
Contributor Author

maximepvrt commented May 22, 2024

The class management for the button group has been rewritten for version 3 (https://github.com/benjamincanac/ui3/blob/dev/src/theme/button-group.ts), and it might be simpler to add it in this version. Additionally, we need orientation management to correct the button group design on the mobile version of the site scripts.nuxt.com (https://github.com/nuxt/scripts/blob/main/docs/pages/index.vue#L229).

Capture d’écran 2024-05-22 à 17 41 49
Capture d’écran 2024-05-22 à 17 41 42

@maximepvrt maximepvrt changed the title Automatic Breakpoint for UButtonGroup Orientation Automatic Breakpoint for UButtonGroup and UTabs Orientation May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants