@khanacademy/wonder-blocks-dropdown 2.6.9 → 2.6.10
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.
- package/CHANGELOG.md +6 -0
- package/dist/es/index.js +33 -25
- package/dist/index.js +181 -137
- package/package.json +1 -1
- package/src/components/__tests__/single-select.test.js +102 -1
- package/src/components/dropdown-core-virtualized.js +11 -34
- package/src/components/dropdown-core.js +17 -1
- package/src/components/single-select.stories.js +1 -0
- package/src/util/__tests__/dropdown-menu-styles.test.js +100 -0
- package/src/util/constants.js +7 -1
- package/src/util/dropdown-menu-styles.js +65 -0
package/CHANGELOG.md
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -31,14 +31,14 @@ const selectDropdownStyle = {
|
|
|
31
31
|
marginBottom: Spacing.xSmall_8
|
|
32
32
|
};
|
|
33
33
|
const filterableDropdownStyle = {
|
|
34
|
-
minHeight: 100
|
|
35
|
-
maxHeight: 384
|
|
34
|
+
minHeight: 100
|
|
36
35
|
};
|
|
37
36
|
const searchInputStyle = {
|
|
38
37
|
margin: Spacing.xSmall_8,
|
|
39
38
|
marginTop: Spacing.xxxSmall_4
|
|
40
39
|
};
|
|
41
40
|
const DROPDOWN_ITEM_HEIGHT = 40;
|
|
41
|
+
const MAX_VISIBLE_ITEMS = 9;
|
|
42
42
|
const SEPARATOR_ITEM_HEIGHT = 9;
|
|
43
43
|
const SEARCH_ITEM_HEIGHT = DROPDOWN_ITEM_HEIGHT + searchInputStyle.margin + searchInputStyle.marginTop;
|
|
44
44
|
const defaultLabels = {
|
|
@@ -637,15 +637,30 @@ const styles$4 = StyleSheet.create({
|
|
|
637
637
|
}
|
|
638
638
|
});
|
|
639
639
|
|
|
640
|
-
|
|
640
|
+
function getDropdownMenuHeight(items, initialHeight = 0) {
|
|
641
|
+
return items.slice(0, MAX_VISIBLE_ITEMS).reduce((sum, item) => {
|
|
642
|
+
if (SeparatorItem.isClassOf(item.component)) {
|
|
643
|
+
return sum + SEPARATOR_ITEM_HEIGHT;
|
|
644
|
+
} else if (SearchTextInput.isClassOf(item.component)) {
|
|
645
|
+
return sum + SEARCH_ITEM_HEIGHT;
|
|
646
|
+
} else {
|
|
647
|
+
return sum + DROPDOWN_ITEM_HEIGHT;
|
|
648
|
+
}
|
|
649
|
+
}, initialHeight);
|
|
650
|
+
}
|
|
651
|
+
function generateDropdownMenuStyles(minWidth, maxHeight) {
|
|
652
|
+
const styles = StyleSheet.create({
|
|
653
|
+
dropdownMenu: {
|
|
654
|
+
minWidth,
|
|
655
|
+
maxHeight
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
return styles.dropdownMenu;
|
|
659
|
+
}
|
|
641
660
|
|
|
642
661
|
class DropdownCoreVirtualized extends React.Component {
|
|
643
|
-
constructor(
|
|
644
|
-
super(
|
|
645
|
-
this.state = {
|
|
646
|
-
height: this.getHeight(),
|
|
647
|
-
width: this.props.width
|
|
648
|
-
};
|
|
662
|
+
constructor(props) {
|
|
663
|
+
super(props);
|
|
649
664
|
|
|
650
665
|
this.getItemSize = index => {
|
|
651
666
|
const item = this.props.data[index];
|
|
@@ -658,6 +673,11 @@ class DropdownCoreVirtualized extends React.Component {
|
|
|
658
673
|
return DROPDOWN_ITEM_HEIGHT;
|
|
659
674
|
}
|
|
660
675
|
};
|
|
676
|
+
|
|
677
|
+
this.state = {
|
|
678
|
+
height: getDropdownMenuHeight(props.data),
|
|
679
|
+
width: props.width
|
|
680
|
+
};
|
|
661
681
|
}
|
|
662
682
|
|
|
663
683
|
componentDidMount() {
|
|
@@ -697,24 +717,12 @@ class DropdownCoreVirtualized extends React.Component {
|
|
|
697
717
|
}
|
|
698
718
|
|
|
699
719
|
setHeight() {
|
|
700
|
-
const height = this.
|
|
720
|
+
const height = getDropdownMenuHeight(this.props.data);
|
|
701
721
|
this.setState({
|
|
702
722
|
height
|
|
703
723
|
});
|
|
704
724
|
}
|
|
705
725
|
|
|
706
|
-
getHeight() {
|
|
707
|
-
return this.props.data.slice(0, MAX_VISIBLE_ITEMS).reduce((sum, item) => {
|
|
708
|
-
if (SeparatorItem.isClassOf(item.component)) {
|
|
709
|
-
return sum + SEPARATOR_ITEM_HEIGHT;
|
|
710
|
-
} else if (SearchTextInput.isClassOf(item.component)) {
|
|
711
|
-
return sum + SEARCH_ITEM_HEIGHT;
|
|
712
|
-
} else {
|
|
713
|
-
return sum + DROPDOWN_ITEM_HEIGHT;
|
|
714
|
-
}
|
|
715
|
-
}, 0);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
726
|
renderInitialItems() {
|
|
719
727
|
const {
|
|
720
728
|
data
|
|
@@ -1273,12 +1281,12 @@ class DropdownCore extends React.Component {
|
|
|
1273
1281
|
} = this.props;
|
|
1274
1282
|
const openerStyle = openerElement && window.getComputedStyle(openerElement);
|
|
1275
1283
|
const minDropdownWidth = openerStyle ? openerStyle.getPropertyValue("width") : 0;
|
|
1284
|
+
const initialHeight = 12;
|
|
1285
|
+
const maxDropdownHeight = getDropdownMenuHeight(this.props.items, initialHeight);
|
|
1276
1286
|
return React.createElement(View, {
|
|
1277
1287
|
onMouseUp: this.handleDropdownMouseUp,
|
|
1278
1288
|
role: this.props.role,
|
|
1279
|
-
style: [styles$3.dropdown, light && styles$3.light, isReferenceHidden && styles$3.hidden,
|
|
1280
|
-
minWidth: minDropdownWidth
|
|
1281
|
-
}, dropdownStyle]
|
|
1289
|
+
style: [styles$3.dropdown, light && styles$3.light, isReferenceHidden && styles$3.hidden, generateDropdownMenuStyles(minDropdownWidth, maxDropdownHeight), dropdownStyle]
|
|
1282
1290
|
}, listRenderer, this.maybeRenderNoResults());
|
|
1283
1291
|
}
|
|
1284
1292
|
|