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: resolved border collapse issue #1626 when border variants are mixed in button group #1637

Merged
merged 20 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
jguddas marked this conversation as resolved.
Show resolved Hide resolved
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)]"],
};
Loading