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

[PM-16102] Increase clickable area for bit-item actions #12450

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 3 additions & 0 deletions libs/components/src/badge/badge.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span [ngClass]="{ 'tw-truncate tw-block': truncate }">
<ng-content></ng-content>
</span>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Directive, ElementRef, HostBinding, Input } from "@angular/core";
import { Component, ElementRef, HostBinding, Input } from "@angular/core";

import { FocusableElement } from "../shared/focusable-element";

Expand Down Expand Up @@ -28,11 +28,12 @@ const hoverStyles: Record<BadgeVariant, string[]> = {
info: ["hover:tw-bg-info-600", "hover:tw-border-info-600", "hover:!tw-text-black"],
};

@Directive({
@Component({
selector: "span[bitBadge], a[bitBadge], button[bitBadge]",
providers: [{ provide: FocusableElement, useExisting: BadgeDirective }],
providers: [{ provide: FocusableElement, useExisting: BadgeComponent }],
templateUrl: "badge.component.html",
})
export class BadgeDirective implements FocusableElement {
export class BadgeComponent implements FocusableElement {
@HostBinding("class") get classList() {
return [
"tw-inline-block",
Expand Down Expand Up @@ -62,7 +63,7 @@ export class BadgeDirective implements FocusableElement {
]
.concat(styles[this.variant])
.concat(this.hasHoverEffects ? hoverStyles[this.variant] : [])
.concat(this.truncate ? ["tw-truncate", this.maxWidthClass] : []);
.concat(this.truncate ? this.maxWidthClass : []);
}
@HostBinding("attr.title") get titleAttr() {
if (this.title !== undefined) {
Expand Down
6 changes: 3 additions & 3 deletions libs/components/src/badge/badge.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";

import { BadgeDirective } from "./badge.directive";
import { BadgeComponent } from "./badge.component";

@NgModule({
imports: [CommonModule],
exports: [BadgeDirective],
declarations: [BadgeDirective],
exports: [BadgeComponent],
declarations: [BadgeComponent],
})
export class BadgeModule {}
10 changes: 5 additions & 5 deletions libs/components/src/badge/badge.stories.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { CommonModule } from "@angular/common";
import { Meta, moduleMetadata, StoryObj } from "@storybook/angular";

import { BadgeDirective } from "./badge.directive";
import { BadgeComponent } from "./badge.component";

Check warning on line 4 in libs/components/src/badge/badge.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/badge/badge.stories.ts#L4

Added line #L4 was not covered by tests

export default {
title: "Component Library/Badge",
component: BadgeDirective,
component: BadgeComponent,
decorators: [
moduleMetadata({
imports: [CommonModule],
declarations: [BadgeDirective],
declarations: [BadgeComponent],
}),
],
args: {
Expand All @@ -22,9 +22,9 @@
url: "https://www.figma.com/file/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=1881%3A16956",
},
},
} as Meta<BadgeDirective>;
} as Meta<BadgeComponent>;

type Story = StoryObj<BadgeDirective>;
type Story = StoryObj<BadgeComponent>;

export const Variants: Story = {
render: (args) => ({
Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/badge/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { BadgeDirective, BadgeVariant } from "./badge.directive";
export { BadgeComponent, BadgeVariant } from "./badge.component";
export * from "./badge.module";
4 changes: 4 additions & 0 deletions libs/components/src/item/item-action.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ import { A11yCellDirective } from "../a11y/a11y-cell.directive";
imports: [],
template: `<ng-content></ng-content>`,
providers: [{ provide: A11yCellDirective, useExisting: ItemActionComponent }],
host: {
class:
"[&>button]:tw-relative [&>button:not([bit-item-content])]:before:tw-content-[''] [&>button]:before:tw-absolute [&>button]:before:tw-block [&>button]:before:tw-top-[-0.75rem] [&>button]:before:tw-bottom-[-0.75rem] [&>button]:before:tw-right-[-0.25rem] [&>button]:before:tw-left-[-0.25rem]",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

โ„น๏ธ The not([bit-item-content]) is to prevent the :before area being added to the main item action, which also uses the item-action component.

Copy link
Contributor

Choose a reason for hiding this comment

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

โ“

In bit-item-content, we define the Y padding as tw-py-2 bit-compact:tw-py-1.5. The padding hooks into compact mode. My understanding is that the position properties here should be 1:1 with the padding, right? p-1.5 === .375rem and p-2 === .5rem

And if these values are meant to be coupled, would it be helpful to represent them as a shared CSS variable? --bit-item-x-padding etc? Then we could use the same variable in both places? Just wondering if we are worried about accidentally breaking this in the future if it is meant to be lockstep, but not actually lockstep.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm yeah it probably should be. I think I was eyeballing whether or not it looked like the right height and never went back and updated it

Copy link
Contributor Author

@vleague2 vleague2 Dec 19, 2024

Choose a reason for hiding this comment

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

For posterity, they don't match because the padding units have a different origin point than the positioning units, but they are updated to be more accurate and responsive to compact mode in this commit: fc4c0eb

},
})
export class ItemActionComponent extends A11yCellDirective {}
Loading