Skip to content

feat(dropdown-item): update spacing of icons #9330

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

Merged
merged 8 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
.container--s {
@apply text-n2h py-1;
padding-inline-end: theme("padding.2");
padding-inline-start: theme("padding.6");
}

.container--m {
@apply text-n1h py-2;
padding-inline-end: theme("padding.3");
padding-inline-start: theme("padding.8");
}

.container--l {
@apply text-0h py-2.5;
padding-inline-end: theme("padding.4");
padding-inline-start: theme("padding.10");
}

// none-selection mode
.container--s.container--none-selection {
padding-inline-start: theme("padding.1");
& .dropdown-link {
padding-inline-start: theme("padding.0");
}
}

.container--m.container--none-selection {
padding-inline-start: theme("padding.2");
& .dropdown-link {
padding-inline-start: theme("padding.0");
}
}

.container--l.container--none-selection {
padding-inline-start: theme("padding.3");
& .dropdown-link {
padding-inline-start: theme("padding.0");
}
}

@mixin itemStyling {
@apply text-color-3
relative
Expand All @@ -54,53 +14,88 @@
@apply relative
flex
flex-grow
items-center;
items-center
focus-base;
}

.container {
@include itemStyling;
text-align: start;
@apply text-start;
}

.dropdown-item-content {
@apply flex-auto py-0.5;
padding-inline-end: theme("margin.auto");
padding-inline-start: theme("margin.1");
}

//focus
:host,
.container--link a {
@apply focus-base;
}
:host(:focus) {
@apply focus-inset outline-none;
// item icon
.dropdown-item-icon {
@apply relative
opacity-0
duration-150
ease-in-out;
transform: scale(0.9);
}

// when used as link move styling anchor
// when used as link remove styling anchor
.container--link {
@apply p-0;
& a {
@include itemStyling;
@apply focus-base;
}
}

.container--s .dropdown-link {
@apply text-n2h py-1;
padding-inline-end: theme("padding.2");
padding-inline-start: theme("padding.6");
:host([scale="s"]) {
.container {
@apply text-n2h py-1 px-2;
}

.dropdown-item-icon,
.dropdown-item-icon-start {
padding-inline-end: var(--calcite-spacing-sm);
}

.dropdown-item-icon-end {
padding-inline-start: var(--calcite-spacing-sm);
}
}

.container--m .dropdown-link {
@apply text-n1h py-2;
padding-inline-end: theme("padding.3");
padding-inline-start: theme("padding.8");
:host([scale="m"]) {
.container {
@apply text-n1h py-2 px-3;
}

.dropdown-item-icon,
.dropdown-item-icon-start {
padding-inline-end: var(--calcite-spacing-md);
}

.dropdown-item-icon-end {
padding-inline-start: var(--calcite-spacing-md);
}
}

.container--l .dropdown-link {
@apply text-0h py-3;
padding-inline-end: theme("padding.4");
padding-inline-start: theme("padding.10");
:host([scale="l"]) {
.container {
@apply text-0h py-2.5 px-4;
}

.dropdown-item-icon,
.dropdown-item-icon-start {
padding-inline-end: var(--calcite-spacing-xl);
}

.dropdown-item-icon-end {
padding-inline-start: var(--calcite-spacing-xl);
}
}

//focus
:host(:focus) {
@apply focus-inset outline-none;

.container {
@apply text-color-1 no-underline;
}
}

:host(:hover:not([disabled])),
Expand All @@ -118,10 +113,6 @@
@apply bg-foreground-3;
}

:host(:focus) .container {
@apply text-color-1 no-underline;
}

:host([selected]) .container:not(.container--none-selection),
:host([selected]) .container--link .dropdown-link {
@apply text-color-1 font-medium;
Expand All @@ -130,27 +121,6 @@
}
}

// item icon
.dropdown-item-icon {
@apply absolute
opacity-0
duration-150
ease-in-out;
transform: scale(0.9);
}

.container--s .dropdown-item-icon {
inset-inline-start: theme("spacing.1");
}

.container--m .dropdown-item-icon {
inset-inline-start: theme("spacing.2");
}

.container--l .dropdown-item-icon {
inset-inline-start: theme("spacing.3");
}

:host(:hover:not([disabled])) .dropdown-item-icon {
color: theme("borderColor.color.1");
@apply opacity-100;
Expand All @@ -161,36 +131,5 @@
@apply opacity-100;
}

// icon start & end
.container--s {
.dropdown-item-icon-start {
margin-inline-end: theme("margin.2");
margin-inline-start: theme("margin.1");
}
.dropdown-item-icon-end {
margin-inline-start: theme("margin.2");
}
}

.container--m {
.dropdown-item-icon-start {
margin-inline-end: theme("margin.3");
margin-inline-start: theme("margin.1");
}
.dropdown-item-icon-end {
margin-inline-start: theme("margin.3");
}
}

.container--l {
.dropdown-item-icon-start {
margin-inline-end: theme("margin.4");
margin-inline-start: theme("margin.1");
}
.dropdown-item-icon-end {
margin-inline-start: theme("margin.4");
}
}

@include base-component();
@include disabled();
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class DropdownItem implements InteractiveComponent, LoadableComponent {
*
* @internal
*/
@Prop() scale: Scale = "m";
@Prop({ reflect: true }) scale: Scale = "m";
Copy link
Member

Choose a reason for hiding this comment

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

Per our conversation, let's discuss reflection of internal properties as a pattern, as it simplifies styling without significant trade-offs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reflecting @internal props for styling purposes will help us improves the maintainability and readability of styles. Though it's internal since they aren't document for public use it is safe to reflect and take advantage of the attribute selector in CSS instead of creating dynamic classes.

Considering this PR as example, reflecting prop helped us avoid cumbersome styling code and there are other instance in the repo where internal props are reflected. We can use this as a pattern if the reflection helps improving the code without affecting UI/UX.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah its a trade off discussion...

Is showing an undocumented attribute terrible? No.
Is not showing an undocumented attribute better? Probably.

So its really about if its worth the work to use an internal shadow DOM class vs relying on an attribute.

Copy link
Member

Choose a reason for hiding this comment

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

So its really about if its worth the work to use an internal shadow DOM class vs relying on an attribute.

Agreed. From what I've seen, the extra work of adding root container classes to mimic host and reflected internal attributes (e.g., scale-related styling) can feel like overkill. Since we usually avoid reflecting props on the host element, leveraging the reflection of internal properties seems simpler and cleaner in this case.


//--------------------------------------------------------------------------
//
Expand All @@ -151,7 +151,7 @@ export class DropdownItem implements InteractiveComponent, LoadableComponent {
}

render(): VNode {
const { href, selectionMode, label, iconFlipRtl, scale } = this;
const { href, selectionMode, label, iconFlipRtl } = this;

const iconStartEl = (
<calcite-icon
Expand Down Expand Up @@ -223,7 +223,6 @@ export class DropdownItem implements InteractiveComponent, LoadableComponent {
class={{
[CSS.container]: true,
[CSS.containerLink]: !!href,
[`${CSS.container}--${scale}`]: true,
[CSS.containerMulti]: selectionMode === "multiple",
[CSS.containerSingle]: selectionMode === "single",
[CSS.containerNone]: selectionMode === "none",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const CSS = {
container: "container",
containerNone: "container--none-selection",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SideNote: Sorting is handled in a followup refactor PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

containerLink: "container--link",
containerMulti: "container--multi-selection",
containerSingle: "container--single-selection",
containerNone: "container--none-selection",
icon: "dropdown-item-icon",
iconEnd: "dropdown-item-icon-end",
iconStart: "dropdown-item-icon-start",
Expand Down
Loading