Skip to content
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
18 changes: 16 additions & 2 deletions docgen/src/guides/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,11 +718,25 @@ With the redo button:
| ----------------------------- | ---------------------------- |
| `attributeName` | `attribute` |
| `showMore.limit` | `showMoreLimit` |
| `showMore.templates.active` | `templates.showMoreActive` |
| `showMore.templates.inactive` | `templates.showMoreInactive` |
| `showMore.templates.active` | `templates.showMoreText` |
| `showMore.templates.inactive` | `templates.showMoreText` |

- `showMore` is now a boolean option (`showMore.templates` are now in `templates`)
- `sortBy` defaults to `['isRefined', 'name:asc']`
- An object containing `isShowingMore` is passed to `showMoreText` template to toggle between the two states:

```
{
showMoreText: `
{{#isShowingMore}}
Show less
{{/isShowingMore}}
{{^isShowingMore}}
Show more
{{/isShowingMore}}
`
}
```

#### CSS classes

Expand Down
26 changes: 18 additions & 8 deletions src/widgets/menu/__tests__/__snapshots__/menu-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ exports[`menu render renders transformed items 1`] = `
Object {
"templates": Object {
"item": "<a class=\\"{{cssClasses.link}}\\" href=\\"{{url}}\\"><span class=\\"{{cssClasses.label}}\\">{{label}}</span><span class=\\"{{cssClasses.count}}\\">{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}}</span></a>",
"showMoreActive": "Show less",
"showMoreInactive": "Show more",
"showMoreText": "
{{#isShowingMore}}
Show less
{{/isShowingMore}}
{{^isShowingMore}}
Show more
{{/isShowingMore}}
",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"item": false,
"showMoreActive": false,
"showMoreInactive": false,
"showMoreText": false,
},
}
}
Expand Down Expand Up @@ -96,14 +101,19 @@ exports[`menu render snapshot 1`] = `
Object {
"templates": Object {
"item": "<a class=\\"{{cssClasses.link}}\\" href=\\"{{url}}\\"><span class=\\"{{cssClasses.label}}\\">{{label}}</span><span class=\\"{{cssClasses.count}}\\">{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}}</span></a>",
"showMoreActive": "Show less",
"showMoreInactive": "Show more",
"showMoreText": "
{{#isShowingMore}}
Show less
{{/isShowingMore}}
{{^isShowingMore}}
Show more
{{/isShowingMore}}
",
},
"templatesConfig": undefined,
"useCustomCompileOptions": Object {
"item": false,
"showMoreActive": false,
"showMoreInactive": false,
"showMoreText": false,
},
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/widgets/menu/defaultTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default {
'<span class="{{cssClasses.label}}">{{label}}</span>' +
'<span class="{{cssClasses.count}}">{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}}</span>' +
'</a>',
showMoreActive: 'Show less',
showMoreInactive: 'Show more',
showMoreText: `
{{#isShowingMore}}
Show less
{{/isShowingMore}}
{{^isShowingMore}}
Show more
{{/isShowingMore}}
`,
};
5 changes: 2 additions & 3 deletions src/widgets/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ menu({
[ showMore = false ],
[ showMoreLimit = 10 ],
[ cssClasses.{root, noRefinementRoot, list, item, selectedItem, link, label, count, showMore, disabledShowMore} ],
[ templates.{item, showMoreActive, showMoreInactive} ],
[ templates.{item, showMoreText} ],
[ transformItems ]
})`;

Expand All @@ -86,8 +86,7 @@ menu({
/**
* @typedef {Object} MenuTemplates
* @property {string|function({count: number, cssClasses: object, isRefined: boolean, label: string, url: string, value: string}):string} [item] Item template. The string template gets the same values as the function.
* @property {string} [showMoreActive] Template used when showMore was clicked.
* @property {string} [showMoreInactive] Template used when showMore not clicked.
* @property {string} [showMoreText] Template used for the show more text, provided with `isShowingMore` data property.
*/

/**
Expand Down
9 changes: 7 additions & 2 deletions storybook/app/builtin/stories/menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ export default () => {
showMore: true,
showMoreLimit: 10,
templates: {
showMoreActive: 'Show way less',
showMoreInactive: 'Show way more',
showMoreText: `
{{#isShowingMore}}
⬆️
{{/isShowingMore}}
{{^isShowingMore}}
⬇️
{{/isShowingMore}}`,
},
})
);
Expand Down