Skip to content

Commit

Permalink
fix: resolved border collapse issue #1626 when border variants are mi…
Browse files Browse the repository at this point in the history
…xed in button group (#1637)

* fix(button-group): radius not work

* fix(button): not show the correct borders

* fix(changeset): button issue

* fix(changeset): fix typo

* fix(changeset): tweak changeset message

* fix(button-groups): add miss undefined radius

* fix: make changeset clearly

* test(button-group): add variant button

* refactor: button-group variant handling in button-group.stories.tsx

* test: update button variant to 'bordered'

* refactor: rename isIsolate to isIsolated

* Revert "fix(button-group): radius not work"

This reverts commit 6233690.

* fix: remove isIsolate because using a negative value for the margin will always cover the neighbor

* fix(changeset): remove radius part for another PR

* test: add multiple variant buttons on storybook

* fix: remove unused attribute

* feat: use adjacent selector to remove doubles border

* test: make variantButtons theme consistency

* refactor: use collapseAdjacentVariantBorders to wrap an adjacent selector

* Added RTL support.

---------

Co-authored-by: Jakob Guddas <[email protected]>
  • Loading branch information
chongruei and jguddas authored Oct 4, 2023
1 parent 95c8fda commit 3aac9ba
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/chilly-trainers-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@nextui-org/button": patch
"@nextui-org/theme": patch
---

Fix #1626 The 'border-left' is obscured by 'margin-left ml-[calc(theme(borderWidth.medium)*-1)]', and the border is not covered by its neighbor when the button is set to variant='bordered' in the ButtonGroup.

42 changes: 42 additions & 0 deletions packages/components/button/stories/button-group.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,52 @@ const Template = (args: ButtonGroupProps) => (
</ButtonGroup>
);

const VariantButtonTemplate = (args: ButtonGroupProps) => (
<ButtonGroup {...args}>
<Button>One</Button>
<Button>Two</Button>
<Button>Three</Button>
<Button variant="bordered">Four</Button>
<Button>Five</Button>
<Button>Six</Button>
</ButtonGroup>
);

const VariantButtonsTemplate = (args: ButtonGroupProps) => (
<ButtonGroup {...args}>
<Button color="success" variant="bordered">
One
</Button>
<Button color="success">Two</Button>
<Button variant="bordered">Three</Button>
<Button variant="bordered">Four</Button>
<Button variant="bordered">Five</Button>
<Button variant="bordered">Six</Button>
</ButtonGroup>
);

export const Default = {
render: Template,

args: {
...defaultProps,
},
};

export const VariantButton = {
render: VariantButtonTemplate,

args: {
...defaultProps,
variant: "solid",
},
};

export const VariantButtons = {
render: VariantButtonsTemplate,

args: {
...defaultProps,
variant: "solid",
},
};
43 changes: 39 additions & 4 deletions packages/core/theme/src/components/button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {VariantProps} from "tailwind-variants";

import {tv} from "../utils/tv";
import {colorVariants, dataFocusVisibleClasses} from "../utils";
import {collapseAdjacentVariantBorders, colorVariants, dataFocusVisibleClasses} from "../utils";

/**
* Button wrapper **Tailwind Variants** component
Expand Down Expand Up @@ -316,7 +316,11 @@ const button = tv({
color: "danger",
class: colorVariants.ghost.danger,
},
// isInGroup / size
// isInGroup / radius
{
isInGroup: true,
class: "rounded-none first:rounded-l-medium last:rounded-r-medium",
},
{
isInGroup: true,
size: "sm",
Expand All @@ -340,8 +344,39 @@ const button = tv({
// isInGroup / bordered / ghost
{
isInGroup: true,
variant: ["bordered", "ghost"],
class: "[&:not(:first-child)]:ml-[calc(theme(borderWidth.medium)*-1)]",
variant: ["ghost", "bordered"],
color: "default",
className: collapseAdjacentVariantBorders.default,
},
{
isInGroup: true,
variant: ["ghost", "bordered"],
color: "primary",
className: collapseAdjacentVariantBorders.primary,
},
{
isInGroup: true,
variant: ["ghost", "bordered"],
color: "secondary",
className: collapseAdjacentVariantBorders.secondary,
},
{
isInGroup: true,
variant: ["ghost", "bordered"],
color: "success",
className: collapseAdjacentVariantBorders.success,
},
{
isInGroup: true,
variant: ["ghost", "bordered"],
color: "warning",
className: collapseAdjacentVariantBorders.warning,
},
{
isInGroup: true,
variant: ["ghost", "bordered"],
color: "danger",
className: collapseAdjacentVariantBorders.danger,
},
{
isIconOnly: true,
Expand Down
13 changes: 13 additions & 0 deletions packages/core/theme/src/utils/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ export const translateCenterClasses = [
];

export const absoluteFullClasses = ["absolute", "inset-0"];

/**
* This object defines CSS classes for collapsing adjacent variant borders.
* It includes classes for different variants like default, primary, secondary, etc.
*/
export const collapseAdjacentVariantBorders = {
default: ["[&+.border-medium.border-default]:ms-[calc(theme(borderWidth.medium)*-1)]"],
primary: ["[&+.border-medium.border-primary]:ms-[calc(theme(borderWidth.medium)*-1)]"],
secondary: ["[&+.border-medium.border-secondary]:ms-[calc(theme(borderWidth.medium)*-1)]"],
success: ["[&+.border-medium.border-success]:ms-[calc(theme(borderWidth.medium)*-1)]"],
warning: ["[&+.border-medium.border-warning]:ms-[calc(theme(borderWidth.medium)*-1)]"],
danger: ["[&+.border-medium.border-danger]:ms-[calc(theme(borderWidth.medium)*-1)]"],
};

2 comments on commit 3aac9ba

@vercel
Copy link

@vercel vercel bot commented on 3aac9ba Oct 4, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 3aac9ba Oct 4, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.