Skip to content

Commit cec3188

Browse files
authored
feat(uui-menu-item): add flatten css var to hide chevron column (#665)
* remove grid column on flatten * add --uui-menu-item-flat-structure css var * add story * fix story docs
1 parent 23900eb commit cec3188

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

packages/uui-menu-item/lib/uui-menu-item.element.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { UUIMenuItemEvent } from './UUIMenuItemEvent';
1616
/**
1717
* @element uui-menu-item
1818
* @cssprop --uui-menu-item-indent - set indentation of the menu items
19+
* @cssprop --uui-menu-item-flat-structure - set to 1 to remove the indentation of the chevron. Use this when you have a flat menu structure
1920
* @fires {UUIMenuItemEvent} show-children - fires when the expand icon is clicked to show nested menu items
2021
* @fires {UUIMenuItemEvent} hide-children - fires when the expend icon is clicked to hide nested menu items
2122
* @fires {UUIMenuItemEvent} click-label - fires when the label is clicked
@@ -200,13 +201,18 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
200201
display: block;
201202
--uui-menu-item-child-indent: calc(var(--uui-menu-item-indent, 0) + 1);
202203
user-select: none;
204+
--flat-structure-reversed: calc(
205+
1 - var(--uui-menu-item-flat-structure, 0)
206+
);
203207
}
204208
205209
#menu-item {
206210
position: relative;
207211
padding-left: calc(var(--uui-menu-item-indent, 0) * var(--uui-size-4));
208212
display: grid;
209-
grid-template-columns: var(--uui-size-8) 1fr;
213+
grid-template-columns:
214+
calc(var(--flat-structure-reversed) * var(--uui-size-8))
215+
1fr;
210216
grid-template-rows: 1fr;
211217
white-space: nowrap;
212218
}
@@ -389,7 +395,10 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
389395
grid-column-start: 2;
390396
white-space: nowrap;
391397
overflow: hidden;
392-
398+
padding-right: var(--uui-size-space-3);
399+
padding-left: calc(
400+
var(--uui-menu-item-flat-structure) * var(--uui-size-space-3)
401+
);
393402
display: inline-flex;
394403
align-items: center;
395404
text-decoration: none;
@@ -407,10 +416,6 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
407416
pointer-events: none; /* avoid hovering state on this. */
408417
}
409418
410-
#caret-button + #label-button {
411-
padding-left: 0;
412-
}
413-
414419
#caret-button {
415420
position: relative;
416421
width: 100%;

packages/uui-menu-item/lib/uui-menu-item.story.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default {
3232
},
3333
argTypes: {
3434
'--uui-menu-item-indent': { control: { type: 'text' } },
35+
'--uui-menu-item-flat-structure': { control: { type: 'text' } },
3536
selectMode: {
3637
control: {
3738
type: 'select',
@@ -397,6 +398,36 @@ ItemIndentation.parameters = {
397398
},
398399
};
399400

401+
export const FlatStructure: Story = (props: any) => html`
402+
<uui-icon-registry-essential>
403+
<uui-menu-item
404+
style="--uui-menu-item-flat-structure: 1"
405+
label=${props.label}
406+
?loading=${props.loading}
407+
?disabled=${props.disabled}
408+
?has-children=${props.hasChildren}
409+
?show-children=${props.showChildren}
410+
?selected=${props.selected}
411+
?active=${props.active}
412+
?selectable=${props.selectable}
413+
href=${props.href}
414+
target=${props.target}>
415+
</uui-menu-item>
416+
</uui-icon-registry-essential>
417+
`;
418+
FlatStructure.parameters = {
419+
docs: {
420+
source: {
421+
code: html`
422+
<uui-menu-item
423+
style="--uui-menu-item-flat-structure: 1"
424+
label="Menu Item 1">
425+
</uui-menu-item>
426+
`.strings,
427+
},
428+
},
429+
};
430+
400431
export const SelectMode = (props: any) =>
401432
html`<uui-menu-item
402433
label="Parent"

0 commit comments

Comments
 (0)