@instructure/ui-truncate-list 8.27.1-snapshot-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.TruncateList = void 0;
9
+
10
+ var _react = require("react");
11
+
12
+ var _debounce = require("@instructure/debounce");
13
+
14
+ var _px = require("@instructure/ui-utils/lib/px.js");
15
+
16
+ var _testable = require("@instructure/ui-testable/lib/testable.js");
17
+
18
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
19
+
20
+ var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
21
+
22
+ var _emotion = require("@instructure/emotion");
23
+
24
+ var _styles = _interopRequireDefault(require("./styles"));
25
+
26
+ var _props = require("./props");
27
+
28
+ var _dec, _dec2, _class, _class2;
29
+
30
+ /**
31
+ ---
32
+ category: components/utilities
33
+ ---
34
+ @tsProps
35
+ **/
36
+ let TruncateList = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class TruncateList extends _react.Component {
37
+ constructor(props) {
38
+ super(props);
39
+ this.ref = null;
40
+ this._menuTriggerRef = null;
41
+ this._debouncedHandleResize = void 0;
42
+ this._resizeListener = void 0;
43
+
44
+ this.handleRef = el => {
45
+ const elementRef = this.props.elementRef;
46
+ this.ref = el;
47
+
48
+ if (typeof elementRef === 'function') {
49
+ elementRef(el);
50
+ }
51
+ };
52
+
53
+ this.measureItems = () => {
54
+ const _this$props = this.props,
55
+ fixMenuTriggerWidth = _this$props.fixMenuTriggerWidth,
56
+ itemSpacing = _this$props.itemSpacing;
57
+ const itemSpacingPx = (0, _px.px)(itemSpacing);
58
+ const menuTriggerWidthPx = (0, _px.px)(fixMenuTriggerWidth || this.state.menuTriggerWidth);
59
+ let visibleItemsCount = 0;
60
+
61
+ if (this.ref) {
62
+ const _getBoundingClientRec = (0, _getBoundingClientRect.getBoundingClientRect)(this.ref),
63
+ navWidth = _getBoundingClientRec.width;
64
+
65
+ const itemWidths = Array.from(this.ref.getElementsByTagName('li')).map(item => {
66
+ const _getBoundingClientRec2 = (0, _getBoundingClientRect.getBoundingClientRect)(item),
67
+ width = _getBoundingClientRec2.width;
68
+
69
+ return width;
70
+ });
71
+ let currentWidth = 0;
72
+
73
+ for (let i = 0; i < itemWidths.length; i++) {
74
+ currentWidth += itemWidths[i]; // for the last item we don't need to calculate with the menu trigger
75
+
76
+ const maxWidth = i === itemWidths.length - 1 ? navWidth : navWidth - (menuTriggerWidthPx + itemSpacingPx);
77
+
78
+ if (currentWidth <= maxWidth) {
79
+ visibleItemsCount++;
80
+ } else {
81
+ break;
82
+ }
83
+ }
84
+ }
85
+
86
+ return {
87
+ visibleItemsCount
88
+ };
89
+ };
90
+
91
+ this.handleResize = () => {
92
+ this.setState({
93
+ isMeasuring: true
94
+ }, () => {
95
+ const _this$measureItems = this.measureItems(),
96
+ visibleItemsCount = _this$measureItems.visibleItemsCount;
97
+
98
+ if (typeof this.props.onUpdate === 'function') {
99
+ this.props.onUpdate({
100
+ visibleItemsCount
101
+ });
102
+ }
103
+
104
+ this.setState({
105
+ isMeasuring: false
106
+ });
107
+ });
108
+ };
109
+
110
+ this.state = {
111
+ isMeasuring: false,
112
+ menuTriggerWidth: void 0
113
+ };
114
+ }
115
+
116
+ componentDidMount() {
117
+ var _this$props$makeStyle, _this$props2;
118
+
119
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
120
+
121
+ const _getBoundingClientRec3 = (0, _getBoundingClientRect.getBoundingClientRect)(this.ref),
122
+ origWidth = _getBoundingClientRec3.width;
123
+
124
+ this._debouncedHandleResize = (0, _debounce.debounce)(this.handleResize, this.props.debounce, {
125
+ leading: true,
126
+ trailing: true
127
+ });
128
+ this._resizeListener = new ResizeObserver(entries => {
129
+ for (const entry of entries) {
130
+ const width = entry.contentRect.width;
131
+
132
+ if (origWidth !== width) {
133
+ var _this$_debouncedHandl;
134
+
135
+ (_this$_debouncedHandl = this._debouncedHandleResize) === null || _this$_debouncedHandl === void 0 ? void 0 : _this$_debouncedHandl.call(this);
136
+ }
137
+ }
138
+ }); // On first render we only render the trigger to measure it
139
+
140
+ const menuTriggerWidth = this.props.fixMenuTriggerWidth ? (0, _px.px)(this.props.fixMenuTriggerWidth) : this.calcMenuTriggerWidth();
141
+ this.setState({
142
+ menuTriggerWidth
143
+ }, () => {
144
+ var _this$_resizeListener, _this$_debouncedHandl2;
145
+
146
+ (_this$_resizeListener = this._resizeListener) === null || _this$_resizeListener === void 0 ? void 0 : _this$_resizeListener.observe(this.ref);
147
+ (_this$_debouncedHandl2 = this._debouncedHandleResize) === null || _this$_debouncedHandl2 === void 0 ? void 0 : _this$_debouncedHandl2.call(this);
148
+ });
149
+ }
150
+
151
+ componentDidUpdate(prevProps, prevState) {
152
+ var _this$props$makeStyle2, _this$props3;
153
+
154
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
155
+
156
+ if (prevProps.fixMenuTriggerWidth !== this.props.fixMenuTriggerWidth || prevProps.itemSpacing !== this.props.itemSpacing) {
157
+ var _this$_debouncedHandl3;
158
+
159
+ (_this$_debouncedHandl3 = this._debouncedHandleResize) === null || _this$_debouncedHandl3 === void 0 ? void 0 : _this$_debouncedHandl3.call(this);
160
+ }
161
+
162
+ if (this.ref && prevState.isMeasuring && prevState.isMeasuring !== this.state.isMeasuring) {
163
+ const menuTriggerWidth = this.calcMenuTriggerWidth();
164
+
165
+ if (menuTriggerWidth && this.state.menuTriggerWidth !== menuTriggerWidth) {
166
+ this.setState({
167
+ menuTriggerWidth
168
+ }, () => {
169
+ var _this$_debouncedHandl4;
170
+
171
+ (_this$_debouncedHandl4 = this._debouncedHandleResize) === null || _this$_debouncedHandl4 === void 0 ? void 0 : _this$_debouncedHandl4.call(this);
172
+ });
173
+ }
174
+ }
175
+ }
176
+
177
+ componentWillUnmount() {
178
+ if (this._resizeListener) {
179
+ this._resizeListener.disconnect();
180
+ }
181
+
182
+ if (this._debouncedHandleResize) {
183
+ this._debouncedHandleResize.cancel();
184
+ }
185
+ }
186
+
187
+ get childrenArray() {
188
+ return _react.Children.toArray(this.props.children);
189
+ }
190
+
191
+ get visibleChildren() {
192
+ const visibleItemsCount = this.props.visibleItemsCount;
193
+ const _this$state = this.state,
194
+ isMeasuring = _this$state.isMeasuring,
195
+ menuTriggerWidth = _this$state.menuTriggerWidth; // for the first render we need to measure the trigger width
196
+
197
+ if (typeof menuTriggerWidth === 'undefined') {
198
+ return [];
199
+ }
200
+
201
+ const visibleChildren = typeof visibleItemsCount === 'undefined' ? this.childrenArray : this.childrenArray.splice(0, visibleItemsCount);
202
+ return isMeasuring ? this.childrenArray : visibleChildren;
203
+ }
204
+
205
+ get hiddenChildren() {
206
+ const isMeasuring = this.state.isMeasuring;
207
+ return isMeasuring ? [] : this.childrenArray.splice(this.visibleChildren.length, this.childrenArray.length);
208
+ }
209
+
210
+ calcMenuTriggerWidth() {
211
+ const fixMenuTriggerWidth = this.props.fixMenuTriggerWidth;
212
+
213
+ if (!this._menuTriggerRef) {
214
+ return 0;
215
+ }
216
+
217
+ if (fixMenuTriggerWidth) {
218
+ return (0, _px.px)(fixMenuTriggerWidth);
219
+ }
220
+
221
+ const children = this._menuTriggerRef.children;
222
+ let width = 0;
223
+ Array.from(children).forEach(child => {
224
+ width += (0, _getBoundingClientRect.getBoundingClientRect)(child).width;
225
+ });
226
+ return width;
227
+ }
228
+
229
+ render() {
230
+ const _this$props4 = this.props,
231
+ styles = _this$props4.styles,
232
+ className = _this$props4.className,
233
+ style = _this$props4.style,
234
+ renderHiddenItemMenu = _this$props4.renderHiddenItemMenu;
235
+ const visibleChildren = this.visibleChildren,
236
+ hiddenChildren = this.hiddenChildren;
237
+ return (0, _emotion.jsx)("ul", Object.assign({
238
+ ref: this.handleRef
239
+ }, (0, _omitProps.omitProps)(this.props, _props.allowedProps), {
240
+ // we have to pass style and className
241
+ // (e.g. if emotion style is provided, it will be passed as a className)
242
+ className: className,
243
+ style: style,
244
+ css: styles === null || styles === void 0 ? void 0 : styles.truncateList
245
+ }), visibleChildren.map((child, index) => {
246
+ return (0, _emotion.jsx)("li", {
247
+ key: index,
248
+ css: styles === null || styles === void 0 ? void 0 : styles.listItem
249
+ }, child);
250
+ }), typeof renderHiddenItemMenu === 'function' && hiddenChildren && hiddenChildren.length > 0 && (0, _emotion.jsx)("li", {
251
+ key: "menuTrigger",
252
+ css: [styles === null || styles === void 0 ? void 0 : styles.listItem, styles === null || styles === void 0 ? void 0 : styles.menuTrigger],
253
+ ref: e => {
254
+ this._menuTriggerRef = e;
255
+ }
256
+ }, renderHiddenItemMenu(hiddenChildren)));
257
+ }
258
+
259
+ }, _class2.displayName = "TruncateList", _class2.componentId = 'TruncateList', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
260
+ itemSpacing: '0',
261
+ debounce: 300
262
+ }, _class2)) || _class) || _class);
263
+ exports.TruncateList = TruncateList;
264
+ var _default = TruncateList;
265
+ exports.default = _default;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.propTypes = exports.allowedProps = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ const propTypes = {
36
+ children: _propTypes.default.node,
37
+ visibleItemsCount: _propTypes.default.number,
38
+ onUpdate: _propTypes.default.func,
39
+ renderHiddenItemMenu: _propTypes.default.func,
40
+ itemSpacing: _propTypes.default.string,
41
+ fixMenuTriggerWidth: _propTypes.default.string,
42
+ debounce: _propTypes.default.number,
43
+ elementRef: _propTypes.default.func
44
+ };
45
+ exports.propTypes = propTypes;
46
+ const allowedProps = ['children', 'renderHiddenItemMenu', 'visibleItemsCount', 'itemSpacing', 'fixMenuTriggerWidth', 'debounce', 'onUpdate', 'elementRef'];
47
+ exports.allowedProps = allowedProps;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * private: true
35
+ * ---
36
+ * Generates the style object from the theme and provided additional information
37
+ * @param {Object} componentTheme The theme variable object.
38
+ * @param {Object} props the props of the component, the style is applied to
39
+ * @param {Object} state the state of the component, the style is applied to
40
+ * @return {Object} The final style object, which will be used in the component
41
+ */
42
+ const generateStyle = (_componentTheme, props) => {
43
+ const itemSpacing = props.itemSpacing,
44
+ fixMenuTriggerWidth = props.fixMenuTriggerWidth;
45
+ const listItemStyle = {
46
+ minWidth: '0.0625rem',
47
+ flexShrink: 0,
48
+ flexGrow: 0
49
+ };
50
+ return {
51
+ truncateList: {
52
+ label: 'truncateList',
53
+ boxSizing: 'border-box',
54
+ listStyleType: 'none',
55
+ margin: '0',
56
+ padding: '0',
57
+ display: 'flex',
58
+ justifyContent: 'flex-start',
59
+ alignItems: 'center'
60
+ },
61
+ listItem: {
62
+ label: 'truncateList__listItem',
63
+ ...listItemStyle,
64
+ '& + &': {
65
+ paddingInlineStart: itemSpacing
66
+ }
67
+ },
68
+ menuTrigger: {
69
+ label: 'truncateList__menuTrigger',
70
+ maxWidth: '100%',
71
+ ...(fixMenuTriggerWidth && {
72
+ width: fixMenuTriggerWidth
73
+ }),
74
+ paddingInlineStart: itemSpacing,
75
+ '&:first-of-type': {
76
+ paddingInlineStart: 0
77
+ }
78
+ }
79
+ };
80
+ };
81
+
82
+ var _default = generateStyle;
83
+ exports.default = _default;
package/lib/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "TruncateList", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _TruncateList.TruncateList;
10
+ }
11
+ });
12
+
13
+ var _TruncateList = require("./TruncateList");
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@instructure/ui-truncate-list",
3
+ "version": "8.27.1-snapshot-13",
4
+ "description": "A TruncateList component made by Instructure Inc.",
5
+ "author": "Instructure, Inc. Engineering and Product Design",
6
+ "module": "./es/index.js",
7
+ "main": "./lib/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/instructure/instructure-ui.git"
12
+ },
13
+ "homepage": "https://instructure.github.io/instructure-ui/",
14
+ "bugs": "https://github.com/instructure/instructure-ui/issues",
15
+ "scripts": {
16
+ "lint": "run -T ui-test --lint",
17
+ "lint:fix": "run -T ui-test --lint --fix",
18
+ "clean": "run -T ui-build --clean",
19
+ "build": "run -T ui-build --modules es,cjs",
20
+ "build:watch": "yarn ts:check --watch & run -T ui-build --watch",
21
+ "build:types": "run -T tsc -p tsconfig.build.json",
22
+ "ts:check": "run -T tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
23
+ },
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "@babel/runtime": "^7.13.10",
27
+ "@instructure/console": "8.27.1-snapshot-13",
28
+ "@instructure/debounce": "8.27.1-snapshot-13",
29
+ "@instructure/emotion": "8.27.1-snapshot-13",
30
+ "@instructure/shared-types": "8.27.1-snapshot-13",
31
+ "@instructure/ui-dom-utils": "8.27.1-snapshot-13",
32
+ "@instructure/ui-react-utils": "8.27.1-snapshot-13",
33
+ "@instructure/ui-testable": "8.27.1-snapshot-13",
34
+ "@instructure/ui-utils": "8.27.1-snapshot-13",
35
+ "prop-types": "^15"
36
+ },
37
+ "devDependencies": {
38
+ "@instructure/ui-babel-preset": "8.27.1-snapshot-13",
39
+ "@instructure/ui-color-utils": "8.27.1-snapshot-13",
40
+ "@instructure/ui-test-locator": "8.27.1-snapshot-13",
41
+ "@instructure/ui-test-queries": "8.27.1-snapshot-13",
42
+ "@instructure/ui-test-utils": "8.27.1-snapshot-13",
43
+ "@instructure/ui-themes": "8.27.1-snapshot-13"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=16.8 <=18"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "sideEffects": false
52
+ }
@@ -0,0 +1,201 @@
1
+ ---
2
+ describes: TruncateList
3
+ ---
4
+
5
+ `TruncateList` is a special kind of list component that can be configured to adapt to small screen widths by truncating its items that don’t fit within the available space. It is a utility component that can be used on its own, but its intended use is to handle the truncation logic of menu items in navigation bars.
6
+
7
+ ### Visible items
8
+
9
+ The `onUpdate` function prop returns the number of visible items, and the `visibleItemsCount` prop controls how many items are currently visible.
10
+
11
+ It is a controlled component, so without and `onUpdate` prop it won't be responsive to changes. When `visibleItemsCount` is not set, the list is not truncated.
12
+
13
+ When the list is truncated, it is recommended to pass an element that lists the rest of the hidden items. The `renderHiddenItemMenu` prop accepts a function with the `hiddenChildren` as its parameter, and it should return a dropdown menu (e.g.: [Drilldown](/#Drilldown), [Menu](/#Menu)) or link, etc.
14
+
15
+ ```js
16
+ ---
17
+ example: true
18
+ render: false
19
+ ---
20
+ class Example extends React.Component {
21
+ state = { visibleItemsCount: undefined }
22
+
23
+ render() {
24
+ return (
25
+ <View as="div" background="primary" padding="x-small">
26
+ <TruncateList
27
+ itemSpacing='0.25rem'
28
+ visibleItemsCount={this.state.visibleItemsCount}
29
+ onUpdate={({ visibleItemsCount }) => {
30
+ this.setState({ visibleItemsCount })
31
+ }}
32
+ renderHiddenItemMenu={(hiddenChildren) => {
33
+ return (
34
+ <Drilldown
35
+ rootPageId="root"
36
+ trigger={(
37
+ <Button margin="0 0 0 small">
38
+ {hiddenChildren.length} More
39
+ </Button>
40
+ )}
41
+ width="15rem"
42
+ maxHeight="10rem"
43
+ placement='bottom'
44
+ >
45
+ <Drilldown.Page id="root">
46
+ {hiddenChildren.map((child, idx) => {
47
+ return (
48
+ <Drilldown.Option
49
+ key={`option-${idx}`}
50
+ id={`option-${idx}`}
51
+ >
52
+ {child}
53
+ </Drilldown.Option>
54
+ )
55
+ })}
56
+ </Drilldown.Page>
57
+ </Drilldown>
58
+ )
59
+ }}
60
+ >
61
+ {Array.from(Array(16)).map((item, idx) => {
62
+ return (
63
+ <View
64
+ key={idx}
65
+ padding="x-small"
66
+ >
67
+ Item {idx + 1}
68
+ </View>
69
+ )
70
+ })}
71
+ </TruncateList>
72
+ </View>
73
+ )
74
+ }
75
+ }
76
+
77
+ render(<Example />)
78
+ ```
79
+
80
+ ### Layout settings
81
+
82
+ The `itemSpacing` prop adds spacing between the items. The width of the list item containing the menu trigger can be set to a fixed value with the `fixMenuTriggerWidth` prop.
83
+
84
+ ```js
85
+ ---
86
+ example: true
87
+ render: false
88
+ ---
89
+ class Example extends React.Component {
90
+ state = {
91
+ visibleItemsCount: undefined,
92
+ spacing: '0.5rem',
93
+ menuTriggerWidth: 'none'
94
+ }
95
+
96
+ render() {
97
+ return (
98
+ <View as="div" padding="medium">
99
+ <View display="block" margin="small none large">
100
+ <FormFieldGroup
101
+ description="Settings"
102
+ rowSpacing="small"
103
+ layout='columns'
104
+ >
105
+ <RadioInputGroup
106
+ name="spacing"
107
+ description="Spacing"
108
+ value={this.state.spacing}
109
+ onChange={(event, value) => {
110
+ this.setState({ spacing: value })
111
+ }}>
112
+ {[
113
+ '0',
114
+ '0.5rem',
115
+ '1em',
116
+ '48px'
117
+ ].map((spacingValue) => (
118
+ <RadioInput
119
+ key={spacingValue}
120
+ label={spacingValue}
121
+ value={spacingValue}
122
+ />
123
+ ))}
124
+ </RadioInputGroup>
125
+
126
+ <RadioInputGroup
127
+ name="menuTriggerWidth"
128
+ description="Fix menu trigger width"
129
+ value={this.state.menuTriggerWidth}
130
+ onChange={(event, value) => {
131
+ this.setState({ menuTriggerWidth: value })
132
+ }}>
133
+ {[
134
+ 'none',
135
+ '10rem',
136
+ '8em',
137
+ '240px'
138
+ ].map((menuTriggerWidthValue) => (
139
+ <RadioInput
140
+ key={menuTriggerWidthValue}
141
+ label={menuTriggerWidthValue}
142
+ value={menuTriggerWidthValue}
143
+ />
144
+ ))}
145
+ </RadioInputGroup>
146
+ </FormFieldGroup>
147
+ </View>
148
+
149
+ <View as="div" background="primary" padding="x-small">
150
+ <TruncateList
151
+ itemSpacing={this.state.spacing}
152
+ fixMenuTriggerWidth={this.state.menuTriggerWidth === 'none'
153
+ ? undefined
154
+ : this.state.menuTriggerWidth
155
+ }
156
+ visibleItemsCount={this.state.visibleItemsCount}
157
+ onUpdate={({ visibleItemsCount }) => {
158
+ this.setState({ visibleItemsCount })
159
+ }}
160
+ renderHiddenItemMenu={(hiddenChildren) => {
161
+ return (
162
+ <Drilldown
163
+ rootPageId="root"
164
+ trigger={(
165
+ <Button display="block">
166
+ {hiddenChildren.length} More
167
+ </Button>
168
+ )}
169
+ positionContainerDisplay="block"
170
+ width="15rem"
171
+ maxHeight="10rem"
172
+ placement='bottom'
173
+ >
174
+ <Drilldown.Page id="root">
175
+ {hiddenChildren.map((child, idx) => {
176
+ return (
177
+ <Drilldown.Option
178
+ key={`option-${idx}`}
179
+ id={`option-${idx}`}
180
+ >
181
+ {child}
182
+ </Drilldown.Option>
183
+ )
184
+ })}
185
+ </Drilldown.Page>
186
+ </Drilldown>
187
+ )
188
+ }}
189
+ >
190
+ {Array.from(Array(16)).map((item, idx) => {
191
+ return <div key={idx}>Item {idx + 1}</div>
192
+ })}
193
+ </TruncateList>
194
+ </View>
195
+ </View>
196
+ )
197
+ }
198
+ }
199
+
200
+ render(<Example />)
201
+ ```