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

Improve Creation Menu items logic | Fixes #749 #750

Merged
merged 13 commits into from
Mar 16, 2018
Prev Previous commit
Next Next commit
Remake creation menu api | Fixes #749
  • Loading branch information
Carlos Lancha committed Mar 16, 2018
commit 3c1a51e0f712d479fa00cae2513a5cd448eec047
79 changes: 51 additions & 28 deletions packages/clay-dropdown/src/ClayCreationMenuDropdown.soy
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
{@param? secondaryItems: list<?>}
{@param? triggerClasses: string}

{let $secondaryItemsFirstGroup: $secondaryItems and $secondaryItems[0] ? $secondaryItems[0] : null /}
{let $secondaryItemsSecondGroup: $secondaryItems and $secondaryItems[1] ? $secondaryItems[1] : null /}

{let $totalPrimaryItems: length($primaryItems) /}
{let $totalSecondaryItems: $secondaryItems ? length($secondaryItems) : 0 /}
{let $totalItems: ($secondaryItems ? length($secondaryItems) : 0) + length($primaryItems) /}
{let $totalSecondaryItemsFirstGroup: $secondaryItemsFirstGroup and $secondaryItemsFirstGroup.items ? length($secondaryItemsFirstGroup.items) : 0 /}
{let $totalSecondaryItemsSecondGroup: $secondaryItemsSecondGroup and $secondaryItemsSecondGroup.items ? length($secondaryItemsSecondGroup.items) : 0 /}
{let $totalSecondaryItems: $totalSecondaryItemsFirstGroup + $totalSecondaryItemsSecondGroup /}
{let $totalItems: $totalPrimaryItems + $totalSecondaryItems /}

{let $defaultMaxPrimaryItems: $maxPrimaryItems ?: 8 /}
{let $defaultMaxSecondaryItems: $maxSecondaryItems ?: 7 /}
Expand All @@ -32,46 +37,64 @@
($totalPrimaryItems > $defaultMaxPrimaryItems ? $defaultMaxPrimaryItems : $totalPrimaryItems)) +
($totalSecondaryItems > $defaultMaxSecondaryItems ? $defaultMaxSecondaryItems : $totalSecondaryItems) /}

{let $trigger kind="html"}
{call ClayIcon.render}
{param spritemap: $spritemap /}
{param symbol: 'plus' /}
{/call}
{/let}

{let $items: $secondaryItems ? [[
{let $primaryDropdownItems: [
'items': $primaryItems,
'maxItems': $defaultMaxPrimaryItems,
'separator': true,
'maxItems': $totalSecondaryItems > 0 ? $defaultMaxPrimaryItems : $defaultMaxTotalItems,
'separator': $totalSecondaryItems > 0,
'type': 'group'
],[
'items': $secondaryItems,
'label': 'Favorites',
'maxItems': $defaultMaxSecondaryItems,
] /}

{let $secondaryDropdownItemsSecondGroup: $secondaryItemsSecondGroup and $totalSecondaryItemsFirstGroup < $defaultMaxSecondaryItems ? [
'items': $secondaryItemsSecondGroup.items,
'label': $secondaryItemsSecondGroup.label,
'maxItems': $defaultMaxSecondaryItems - $totalSecondaryItemsFirstGroup,
'type': 'group'
]] : [[
'items': $primaryItems,
'maxItems': $defaultMaxTotalItems,
'separator': false,
] : null /}

{let $secondaryDropdownItemsFirstGroup: $secondaryItemsFirstGroup ? [
'items': $secondaryItemsFirstGroup.items,
'label': $secondaryItemsFirstGroup.label,
'maxItems': $defaultMaxSecondaryItems,
'separator': $secondaryItemsFirstGroup.separator and isNonnull($secondaryDropdownItemsSecondGroup),
'type': 'group'
]] /}
] : null /}

{let $items: $secondaryDropdownItemsFirstGroup and $secondaryDropdownItemsSecondGroup ? [
$primaryDropdownItems,
$secondaryDropdownItemsFirstGroup,
$secondaryDropdownItemsSecondGroup
] : $secondaryDropdownItemsFirstGroup ? [
$primaryDropdownItems,
$secondaryDropdownItemsFirstGroup
] : [
$primaryDropdownItems
] /}

{let $showMoreButton: $showingItems < $totalItems ? [
'label': 'More',
'style': 'secondary'
] : null /}

{let $caption: $showMoreButton ? 'Showing ' + $showingItems + ' of ' + $totalItems + ' elements' : null/}

{let $showMoreButton: $showingItems < $totalItems /}
{let $trigger kind="html"}
{call ClayIcon.render}
{param spritemap: $spritemap /}
{param symbol: 'plus' /}
{/call}
{/let}

{call ClayDropdownBase.render}
{param button: $showMoreButton ? [
'label': 'More',
'style': 'secondary'
] : null /}
{param caption: $showMoreButton ? 'Showing ' + $showingItems + ' of ' + $totalItems + ' elements' : null /}
{param button: $showMoreButton /}
{param caption: $caption /}
{param disabled: $disabled /}
{param elementClasses: $elementClasses /}
{param events: [
'buttonClicked': $_handleButtonClick,
'itemClicked': $_handleItemClick
]/}
{param expanded: $expanded /}
{param helpText: $helpText /}
{param helpText: $showMoreButton ? $helpText : null /}
{param id: $id /}
{param items: $items /}
{param itemsIconAlignment: $itemsIconAlignment /}
Expand Down