@khanacademy/wonder-blocks-dropdown 2.10.7 → 2.10.9

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.
Files changed (85) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/components/__mocks__/dropdown-core-virtualized.d.ts +14 -0
  3. package/dist/components/__mocks__/dropdown-core-virtualized.js.flow +22 -0
  4. package/dist/components/action-item.d.ts +94 -0
  5. package/dist/components/action-item.js.flow +112 -0
  6. package/dist/components/action-menu-opener-core.d.ts +31 -0
  7. package/dist/components/action-menu-opener-core.js.flow +47 -0
  8. package/dist/components/action-menu.d.ts +109 -0
  9. package/dist/components/action-menu.js.flow +139 -0
  10. package/dist/components/check.d.ts +22 -0
  11. package/dist/components/check.js.flow +45 -0
  12. package/dist/components/checkbox.d.ts +22 -0
  13. package/dist/components/checkbox.js.flow +45 -0
  14. package/dist/components/dropdown-core-virtualized-item.d.ts +30 -0
  15. package/dist/components/dropdown-core-virtualized-item.js.flow +41 -0
  16. package/dist/components/dropdown-core-virtualized.d.ts +9 -0
  17. package/dist/components/dropdown-core-virtualized.js.flow +20 -0
  18. package/dist/components/dropdown-core.d.ts +123 -0
  19. package/dist/components/dropdown-core.js.flow +153 -0
  20. package/dist/components/dropdown-opener.d.ts +40 -0
  21. package/dist/components/dropdown-opener.js.flow +62 -0
  22. package/dist/components/dropdown-popper.d.ts +31 -0
  23. package/dist/components/dropdown-popper.js.flow +43 -0
  24. package/dist/components/multi-select.d.ts +198 -0
  25. package/dist/components/multi-select.js.flow +258 -0
  26. package/dist/components/option-item.d.ts +75 -0
  27. package/dist/components/option-item.js.flow +95 -0
  28. package/dist/components/select-opener.d.ts +55 -0
  29. package/dist/components/select-opener.js.flow +75 -0
  30. package/dist/components/separator-item.d.ts +17 -0
  31. package/dist/components/separator-item.js.flow +29 -0
  32. package/dist/components/single-select.d.ts +206 -0
  33. package/dist/components/single-select.js.flow +261 -0
  34. package/dist/es/index.js +474 -575
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.js +515 -618
  37. package/dist/index.js.flow +24 -2
  38. package/dist/util/constants.d.ts +33 -0
  39. package/dist/util/constants.js.flow +44 -0
  40. package/dist/util/dropdown-menu-styles.d.ts +21 -0
  41. package/dist/util/dropdown-menu-styles.js.flow +33 -0
  42. package/dist/util/helpers.d.ts +16 -0
  43. package/dist/util/helpers.js.flow +25 -0
  44. package/dist/util/types.d.ts +17 -0
  45. package/dist/util/types.js.flow +39 -0
  46. package/package.json +14 -14
  47. package/src/components/__mocks__/{dropdown-core-virtualized.js → dropdown-core-virtualized.tsx} +6 -10
  48. package/src/components/__tests__/{action-item.test.js → action-item.test.tsx} +0 -1
  49. package/src/components/__tests__/{action-menu.test.js → action-menu.test.tsx} +14 -12
  50. package/src/components/__tests__/{dropdown-core-virtualized.test.js → dropdown-core-virtualized.test.tsx} +19 -18
  51. package/src/components/__tests__/{dropdown-core.test.js → dropdown-core.test.tsx} +2 -3
  52. package/src/components/__tests__/{dropdown-popper.test.js → dropdown-popper.test.tsx} +2 -3
  53. package/src/components/__tests__/{multi-select.test.js → multi-select.test.tsx} +74 -46
  54. package/src/components/__tests__/{single-select.test.js → single-select.test.tsx} +29 -24
  55. package/src/components/{action-item.js → action-item.tsx} +25 -35
  56. package/src/components/{action-menu-opener-core.js → action-menu-opener-core.tsx} +23 -29
  57. package/src/components/{action-menu.js → action-menu.tsx} +40 -48
  58. package/src/components/{check.js → check.tsx} +11 -11
  59. package/src/components/{checkbox.js → checkbox.tsx} +11 -11
  60. package/src/components/{dropdown-core-virtualized-item.js → dropdown-core-virtualized-item.ts} +7 -11
  61. package/src/components/{dropdown-core-virtualized.js → dropdown-core-virtualized.tsx} +27 -45
  62. package/src/components/{dropdown-core.js → dropdown-core.tsx} +136 -99
  63. package/src/components/{dropdown-opener.js → dropdown-opener.tsx} +15 -21
  64. package/src/components/{dropdown-popper.js → dropdown-popper.tsx} +17 -17
  65. package/src/components/{multi-select.js → multi-select.tsx} +133 -143
  66. package/src/components/{option-item.js → option-item.tsx} +25 -37
  67. package/src/components/{select-opener.js → select-opener.tsx} +22 -33
  68. package/src/components/{separator-item.js → separator-item.tsx} +7 -7
  69. package/src/components/{single-select.js → single-select.tsx} +112 -124
  70. package/src/{index.js → index.ts} +0 -1
  71. package/src/util/__tests__/{dropdown-menu-styles.test.js → dropdown-menu-styles.test.tsx} +1 -2
  72. package/src/util/__tests__/{helpers.test.js → helpers.test.ts} +0 -1
  73. package/src/util/{constants.js → constants.ts} +4 -5
  74. package/src/util/{dropdown-menu-styles.js → dropdown-menu-styles.ts} +1 -2
  75. package/src/util/{helpers.js → helpers.ts} +3 -2
  76. package/src/util/types.ts +34 -0
  77. package/tsconfig.json +21 -0
  78. package/tsconfig.tsbuildinfo +1 -0
  79. package/src/components/__docs__/action-menu.argtypes.js +0 -44
  80. package/src/components/__docs__/action-menu.stories.js +0 -435
  81. package/src/components/__docs__/base-select.argtypes.js +0 -54
  82. package/src/components/__docs__/multi-select.stories.js +0 -509
  83. package/src/components/__docs__/single-select.accessibility.stories.mdx +0 -59
  84. package/src/components/__docs__/single-select.stories.js +0 -671
  85. package/src/util/types.js +0 -29
package/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # @khanacademy/wonder-blocks-dropdown
2
2
 
3
+ ## 2.10.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [779b031d]
8
+ - @khanacademy/wonder-blocks-core@4.9.0
9
+ - @khanacademy/wonder-blocks-clickable@2.4.7
10
+ - @khanacademy/wonder-blocks-icon@1.2.39
11
+ - @khanacademy/wonder-blocks-layout@1.4.18
12
+ - @khanacademy/wonder-blocks-modal@3.0.9
13
+ - @khanacademy/wonder-blocks-search-field@1.0.21
14
+ - @khanacademy/wonder-blocks-typography@1.1.40
15
+
16
+ ## 2.10.8
17
+
18
+ ### Patch Changes
19
+
20
+ - d816af08: Update build and test configs use TypeScript
21
+ - 3891f544: Update babel config to include plugins that Storybook needed
22
+ - 0d28bb1c: Configured TypeScript
23
+ - 3d05f764: Fix HOCs and other type errors
24
+ - c2ec4902: Update eslint configuration, fix lint
25
+ - 2983c05b: Include 'types' field in package.json
26
+ - 77ff6a66: Generate Flow types from TypeScript types
27
+ - ec8d4b7f: Fix miscellaneous TypeScript errors
28
+ - Updated dependencies [d816af08]
29
+ - Updated dependencies [3891f544]
30
+ - Updated dependencies [3813715d]
31
+ - Updated dependencies [0d28bb1c]
32
+ - Updated dependencies [873f4a14]
33
+ - Updated dependencies [3d05f764]
34
+ - Updated dependencies [c2ec4902]
35
+ - Updated dependencies [2983c05b]
36
+ - Updated dependencies [77ff6a66]
37
+ - Updated dependencies [ec8d4b7f]
38
+ - @khanacademy/wonder-blocks-clickable@2.4.6
39
+ - @khanacademy/wonder-blocks-color@1.2.2
40
+ - @khanacademy/wonder-blocks-core@4.8.0
41
+ - @khanacademy/wonder-blocks-icon@1.2.38
42
+ - @khanacademy/wonder-blocks-layout@1.4.17
43
+ - @khanacademy/wonder-blocks-modal@3.0.8
44
+ - @khanacademy/wonder-blocks-search-field@1.0.20
45
+ - @khanacademy/wonder-blocks-spacing@3.0.6
46
+ - @khanacademy/wonder-blocks-timing@2.1.2
47
+ - @khanacademy/wonder-blocks-typography@1.1.39
48
+
3
49
  ## 2.10.7
4
50
 
5
51
  ### Patch Changes
@@ -0,0 +1,14 @@
1
+ import * as React from "react";
2
+ import { VariableSizeList as List } from "react-window";
3
+ import type { DropdownItem } from "../../util/types";
4
+ type Props = {
5
+ data: Array<DropdownItem>;
6
+ listRef?: React.RefObject<List>;
7
+ };
8
+ /**
9
+ * A minimal mocked version of the Virtualized implementation
10
+ */
11
+ declare class DropdownCoreVirtualizedMock extends React.Component<Props> {
12
+ render(): React.ReactElement;
13
+ }
14
+ export default DropdownCoreVirtualizedMock;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Flowtype definitions for dropdown-core-virtualized
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import { VariableSizeList as List } from "react-window";
10
+ import type { DropdownItem } from "../../util/types";
11
+ declare type Props = {
12
+ data: Array<DropdownItem>,
13
+ listRef?: React.RefObject<List>,
14
+ ...
15
+ };
16
+ /**
17
+ * A minimal mocked version of the Virtualized implementation
18
+ */
19
+ declare class DropdownCoreVirtualizedMock extends React.Component<Props> {
20
+ render(): React.Element<>;
21
+ }
22
+ declare export default typeof DropdownCoreVirtualizedMock;
@@ -0,0 +1,94 @@
1
+ import * as React from "react";
2
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
3
+ type ActionProps = {
4
+ /**
5
+ * Display text of the action item.
6
+ */
7
+ label: string;
8
+ /**
9
+ * Whether this action item is disabled.
10
+ */
11
+ disabled: boolean;
12
+ /**
13
+ * URL to navigate to.
14
+ *
15
+ * Note: Either href or onClick must be defined
16
+ */
17
+ href?: string;
18
+ /**
19
+ * Optional attribute to indicate to the Screen Reader which language the
20
+ * item text is in.
21
+ */
22
+ lang?: string;
23
+ /**
24
+ * A target destination window for a link to open in.
25
+ *
26
+ * TODO(WB-1262): only allow this prop when `href` is also set.t
27
+ */
28
+ target?: "_blank";
29
+ /**
30
+ * Whether to avoid using client-side navigation.
31
+ *
32
+ * If the URL passed to href is local to the client-side, e.g.
33
+ * /math/algebra/eval-exprs, then it tries to use react-router-dom's Link
34
+ * component which handles the client-side navigation. You can set
35
+ * `skipClientNav` to true avoid using client-side nav entirely.
36
+ *
37
+ * NOTE: All URLs containing a protocol are considered external, e.g.
38
+ * https://khanacademy.org/math/algebra/eval-exprs will trigger a full
39
+ * page reload.
40
+ */
41
+ skipClientNav?: boolean;
42
+ /**
43
+ * Test ID used for e2e testing.
44
+ */
45
+ testId?: string;
46
+ /**
47
+ * Function to call when button is clicked.
48
+ *
49
+ * This callback should be used for things like marking BigBingo
50
+ * conversions. It should NOT be used to redirect to a different URL or to
51
+ * prevent navigation via e.preventDefault(). The event passed to this
52
+ * handler will have its preventDefault() and stopPropagation() methods
53
+ * stubbed out.
54
+ *
55
+ * Note: onClick is optional if href is present, but must be defined if
56
+ * href is not
57
+ */
58
+ onClick?: () => unknown;
59
+ /**
60
+ * Whether this item should be indented to have menu items left-align in
61
+ * text when an ActionItem is used in the same menu as items that have
62
+ * checks or checkboxes. Auto-populated by menu.
63
+ * @ignore
64
+ */
65
+ indent: boolean;
66
+ /**
67
+ * Aria role to use, defaults to "menuitem".
68
+ */
69
+ role: "menuitem" | "option";
70
+ /**
71
+ * In case we use react-window, this needs to be added in order to inject
72
+ * styles to calculate the position
73
+ * @ignore
74
+ */
75
+ style?: StyleType;
76
+ };
77
+ type DefaultProps = {
78
+ disabled: ActionProps["disabled"];
79
+ indent: ActionProps["indent"];
80
+ role: ActionProps["role"];
81
+ };
82
+ /**
83
+ * The action item trigger actions, such as navigating to a different page or
84
+ * opening a modal. Supply the href and/or onClick props. Used as a child of
85
+ * ActionMenu.
86
+ */
87
+ export default class ActionItem extends React.Component<ActionProps> {
88
+ static isClassOf(instance: React.ReactElement<any>): boolean;
89
+ static defaultProps: DefaultProps;
90
+ static __IS_ACTION_ITEM__: boolean;
91
+ renderClickableBehavior(router: any): React.ReactNode;
92
+ render(): React.ReactElement;
93
+ }
94
+ export {};
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Flowtype definitions for action-item
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
10
+ declare type ActionProps = {
11
+ /**
12
+ * Display text of the action item.
13
+ */
14
+ label: string,
15
+
16
+ /**
17
+ * Whether this action item is disabled.
18
+ */
19
+ disabled: boolean,
20
+
21
+ /**
22
+ * URL to navigate to.
23
+ *
24
+ * Note: Either href or onClick must be defined
25
+ */
26
+ href?: string,
27
+
28
+ /**
29
+ * Optional attribute to indicate to the Screen Reader which language the
30
+ * item text is in.
31
+ */
32
+ lang?: string,
33
+
34
+ /**
35
+ * A target destination window for a link to open in.
36
+ *
37
+ * TODO(WB-1262): only allow this prop when `href` is also set.t
38
+ */
39
+ target?: "_blank",
40
+
41
+ /**
42
+ * Whether to avoid using client-side navigation.
43
+ *
44
+ * If the URL passed to href is local to the client-side, e.g.
45
+ * /math/algebra/eval-exprs, then it tries to use react-router-dom's Link
46
+ * component which handles the client-side navigation. You can set
47
+ * `skipClientNav` to true avoid using client-side nav entirely.
48
+ *
49
+ * NOTE: All URLs containing a protocol are considered external, e.g.
50
+ * https://khanacademy.org/math/algebra/eval-exprs will trigger a full
51
+ * page reload.
52
+ */
53
+ skipClientNav?: boolean,
54
+
55
+ /**
56
+ * Test ID used for e2e testing.
57
+ */
58
+ testId?: string,
59
+
60
+ /**
61
+ * Function to call when button is clicked.
62
+ *
63
+ * This callback should be used for things like marking BigBingo
64
+ * conversions. It should NOT be used to redirect to a different URL or to
65
+ * prevent navigation via e.preventDefault(). The event passed to this
66
+ * handler will have its preventDefault() and stopPropagation() methods
67
+ * stubbed out.
68
+ *
69
+ * Note: onClick is optional if href is present, but must be defined if
70
+ * href is not
71
+ */
72
+ onClick?: () => mixed,
73
+
74
+ /**
75
+ * Whether this item should be indented to have menu items left-align in
76
+ * text when an ActionItem is used in the same menu as items that have
77
+ * checks or checkboxes. Auto-populated by menu.
78
+ * @ignore
79
+ */
80
+ indent: boolean,
81
+
82
+ /**
83
+ * Aria role to use, defaults to "menuitem".
84
+ */
85
+ role: "menuitem" | "option",
86
+
87
+ /**
88
+ * In case we use react-window, this needs to be added in order to inject
89
+ * styles to calculate the position
90
+ * @ignore
91
+ */
92
+ style?: StyleType,
93
+ ...
94
+ };
95
+ declare type DefaultProps = {
96
+ disabled: $PropertyType<ActionProps, "disabled">,
97
+ indent: $PropertyType<ActionProps, "indent">,
98
+ role: $PropertyType<ActionProps, "role">,
99
+ ...
100
+ };
101
+ /**
102
+ * The action item trigger actions, such as navigating to a different page or
103
+ * opening a modal. Supply the href and/or onClick props. Used as a child of
104
+ * ActionMenu.
105
+ */
106
+ declare export default class ActionItem extends React.Component<ActionProps> {
107
+ static isClassOf(instance: React.Element<any>): boolean;
108
+ static defaultProps: DefaultProps;
109
+ static __IS_ACTION_ITEM__: boolean;
110
+ renderClickableBehavior(router: any): React.Node;
111
+ render(): React.Element<>;
112
+ }
@@ -0,0 +1,31 @@
1
+ import * as React from "react";
2
+ import type { AriaProps } from "@khanacademy/wonder-blocks-core";
3
+ import type { ClickableState } from "@khanacademy/wonder-blocks-clickable";
4
+ type Props = Partial<Omit<AriaProps, "aria-disabled">> & ClickableState & {
5
+ /**
6
+ * Display text for the opener.
7
+ */
8
+ children: string;
9
+ /**
10
+ * Whether the opener is disabled. If disabled, disallows interaction.
11
+ */
12
+ disabled?: boolean;
13
+ /**
14
+ * Test ID used for e2e testing.
15
+ */
16
+ testId?: string;
17
+ /**
18
+ * Whether the dropdown is open.
19
+ */
20
+ opened: boolean;
21
+ };
22
+ /**
23
+ * Although this component shares a lot with ButtonCore there are a couple
24
+ * of differences:
25
+ * - the down caret icon appears on the right instead of the left
26
+ * - the down caret icon is smaller that the one that would be used by ButtonCore
27
+ */
28
+ export default class ActionMenuOpenerCore extends React.Component<Props> {
29
+ render(): React.ReactElement;
30
+ }
31
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Flowtype definitions for action-menu-opener-core
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { AriaProps } from "@khanacademy/wonder-blocks-core";
10
+ import type { ClickableState } from "@khanacademy/wonder-blocks-clickable";
11
+ declare type Props = {
12
+ ...$Rest<$Diff<AriaProps, { "aria-disabled": any }>, { ... }>,
13
+ ...ClickableState,
14
+ ...{
15
+ /**
16
+ * Display text for the opener.
17
+ */
18
+ children: string,
19
+
20
+ /**
21
+ * Whether the opener is disabled. If disabled, disallows interaction.
22
+ */
23
+ disabled?: boolean,
24
+
25
+ /**
26
+ * Test ID used for e2e testing.
27
+ */
28
+ testId?: string,
29
+
30
+ /**
31
+ * Whether the dropdown is open.
32
+ */
33
+ opened: boolean,
34
+ ...
35
+ },
36
+ };
37
+ /**
38
+ * Although this component shares a lot with ButtonCore there are a couple
39
+ * of differences:
40
+ * - the down caret icon appears on the right instead of the left
41
+ * - the down caret icon is smaller that the one that would be used by ButtonCore
42
+ */
43
+ declare export default class ActionMenuOpenerCore
44
+ extends React.Component<Props>
45
+ {
46
+ render(): React.Element<>;
47
+ }
@@ -0,0 +1,109 @@
1
+ import * as React from "react";
2
+ import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
3
+ import DropdownOpener from "./dropdown-opener";
4
+ import type { Item, DropdownItem, OpenerProps } from "../util/types";
5
+ type Props = AriaProps & {
6
+ /**
7
+ * The items in this dropdown.
8
+ */
9
+ children?: Array<Item> | Item;
10
+ /**
11
+ * Text for the opener of this menu.
12
+ */
13
+ menuText: string;
14
+ /**
15
+ * Can be used to override the state of the ActionMenu by parent elements
16
+ */
17
+ opened?: boolean;
18
+ /**
19
+ * In controlled mode, use this prop in case the parent needs to be notified
20
+ * when the menu opens/closes.
21
+ */
22
+ onToggle?: (opened: boolean) => unknown;
23
+ /**
24
+ * A callback that returns items that are newly selected. Use only if this
25
+ * menu contains select items (and make sure selectedValues is defined).
26
+ */
27
+ onChange?: (selectedItems: Array<string>) => unknown;
28
+ /**
29
+ * The values of the items that are currently selected. Use only if this
30
+ * menu contains select items (and make sure onChange is defined).
31
+ */
32
+ selectedValues?: Array<string>;
33
+ /**
34
+ * Whether this menu should be left-aligned or right-aligned with the
35
+ * opener component. Defaults to left-aligned.
36
+ */
37
+ alignment: "left" | "right";
38
+ /**
39
+ * Whether this component is disabled. A disabled dropdown may not be opened
40
+ * and does not support interaction. Defaults to false.
41
+ */
42
+ disabled: boolean;
43
+ /**
44
+ * Test ID used for e2e testing.
45
+ */
46
+ testId?: string;
47
+ /**
48
+ * Styling specific to the dropdown component that isn't part of the opener,
49
+ * passed by the specific implementation of the dropdown menu,
50
+ */
51
+ dropdownStyle?: StyleType;
52
+ /**
53
+ * Optional styling for the entire dropdown component.
54
+ */
55
+ style?: StyleType;
56
+ /**
57
+ * Optional CSS classes for the entire dropdown component.
58
+ */
59
+ className?: string;
60
+ /**
61
+ * The child function that returns the anchor the ActionMenu will be
62
+ * activated by. This function takes eventState, which allows the opener
63
+ * element to access pointer event state.
64
+ */
65
+ opener?: (openerProps: OpenerProps) => React.ReactElement<any>;
66
+ };
67
+ type State = {
68
+ /**
69
+ * Whether or not the dropdown is open.
70
+ */
71
+ opened: boolean;
72
+ };
73
+ type DefaultProps = {
74
+ alignment: Props["alignment"];
75
+ disabled: Props["disabled"];
76
+ };
77
+ /**
78
+ * A menu that consists of various types of items.
79
+ *
80
+ * ## Usage
81
+ *
82
+ * ```jsx
83
+ * import {ActionMenu, ActionItem} from "@khanacademy/wonder-blocks-dropdown";
84
+ *
85
+ * <ActionMenu menuText="Menu">
86
+ * <ActionItem href="/profile" label="Profile" />
87
+ * <ActionItem label="Settings" onClick={() => {}} />
88
+ * </ActionMenu>
89
+ * ```
90
+ */
91
+ export default class ActionMenu extends React.Component<Props, State> {
92
+ openerElement: HTMLElement | null | undefined;
93
+ static defaultProps: DefaultProps;
94
+ state: State;
95
+ /**
96
+ * Used to sync the `opened` state when this component acts as a controlled
97
+ * component
98
+ */
99
+ static getDerivedStateFromProps(props: Props, state: State): Partial<State> | null;
100
+ handleItemSelected: () => void;
101
+ handleOpenChanged: (opened: boolean) => void;
102
+ handleOptionSelected: (selectedValue: string) => void;
103
+ getMenuItems(): Array<DropdownItem>;
104
+ handleOpenerRef: (node?: any) => void;
105
+ handleClick: (e: React.SyntheticEvent) => void;
106
+ renderOpener(numItems: number): React.ReactElement<React.ComponentProps<typeof DropdownOpener>>;
107
+ render(): React.ReactElement;
108
+ }
109
+ export {};
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Flowtype definitions for action-menu
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
10
+ import DropdownOpener from "./dropdown-opener";
11
+ import type { Item, DropdownItem, OpenerProps } from "../util/types";
12
+ declare type Props = {
13
+ ...AriaProps,
14
+ ...{
15
+ /**
16
+ * The items in this dropdown.
17
+ */
18
+ children?: Array<Item> | Item,
19
+
20
+ /**
21
+ * Text for the opener of this menu.
22
+ */
23
+ menuText: string,
24
+
25
+ /**
26
+ * Can be used to override the state of the ActionMenu by parent elements
27
+ */
28
+ opened?: boolean,
29
+
30
+ /**
31
+ * In controlled mode, use this prop in case the parent needs to be notified
32
+ * when the menu opens/closes.
33
+ */
34
+ onToggle?: (opened: boolean) => mixed,
35
+
36
+ /**
37
+ * A callback that returns items that are newly selected. Use only if this
38
+ * menu contains select items (and make sure selectedValues is defined).
39
+ */
40
+ onChange?: (selectedItems: Array<string>) => mixed,
41
+
42
+ /**
43
+ * The values of the items that are currently selected. Use only if this
44
+ * menu contains select items (and make sure onChange is defined).
45
+ */
46
+ selectedValues?: Array<string>,
47
+
48
+ /**
49
+ * Whether this menu should be left-aligned or right-aligned with the
50
+ * opener component. Defaults to left-aligned.
51
+ */
52
+ alignment: "left" | "right",
53
+
54
+ /**
55
+ * Whether this component is disabled. A disabled dropdown may not be opened
56
+ * and does not support interaction. Defaults to false.
57
+ */
58
+ disabled: boolean,
59
+
60
+ /**
61
+ * Test ID used for e2e testing.
62
+ */
63
+ testId?: string,
64
+
65
+ /**
66
+ * Styling specific to the dropdown component that isn't part of the opener,
67
+ * passed by the specific implementation of the dropdown menu,
68
+ */
69
+ dropdownStyle?: StyleType,
70
+
71
+ /**
72
+ * Optional styling for the entire dropdown component.
73
+ */
74
+ style?: StyleType,
75
+
76
+ /**
77
+ * Optional CSS classes for the entire dropdown component.
78
+ */
79
+ className?: string,
80
+
81
+ /**
82
+ * The child function that returns the anchor the ActionMenu will be
83
+ * activated by. This function takes eventState, which allows the opener
84
+ * element to access pointer event state.
85
+ */
86
+ opener?: (openerProps: OpenerProps) => React.Element<any>,
87
+ ...
88
+ },
89
+ };
90
+ declare type State = {
91
+ /**
92
+ * Whether or not the dropdown is open.
93
+ */
94
+ opened: boolean,
95
+ ...
96
+ };
97
+ declare type DefaultProps = {
98
+ alignment: $PropertyType<Props, "alignment">,
99
+ disabled: $PropertyType<Props, "disabled">,
100
+ ...
101
+ };
102
+ /**
103
+ * A menu that consists of various types of items.
104
+ *
105
+ * ## Usage
106
+ *
107
+ * ```jsx
108
+ * import {ActionMenu, ActionItem} from "@khanacademy/wonder-blocks-dropdown";
109
+ *
110
+ * <ActionMenu menuText="Menu">
111
+ * <ActionItem href="/profile" label="Profile" />
112
+ * <ActionItem label="Settings" onClick={() => {}} />
113
+ * </ActionMenu>
114
+ * ```
115
+ */
116
+ declare export default class ActionMenu extends React.Component<Props, State> {
117
+ openerElement: HTMLElement | null | void;
118
+ static defaultProps: DefaultProps;
119
+ state: State;
120
+
121
+ /**
122
+ * Used to sync the `opened` state when this component acts as a controlled
123
+ * component
124
+ */
125
+ static getDerivedStateFromProps(
126
+ props: Props,
127
+ state: State
128
+ ): $Rest<State, { ... }> | null;
129
+ handleItemSelected: () => void;
130
+ handleOpenChanged: (opened: boolean) => void;
131
+ handleOptionSelected: (selectedValue: string) => void;
132
+ getMenuItems(): Array<DropdownItem>;
133
+ handleOpenerRef: (node?: any) => void;
134
+ handleClick: (e: React.SyntheticEvent<>) => void;
135
+ renderOpener(
136
+ numItems: number
137
+ ): React.Element<React.ComponentProps<typeof DropdownOpener>>;
138
+ render(): React.Element<>;
139
+ }
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Props describing the state of the OptionItem, shared by the checkbox
4
+ * component,
5
+ */
6
+ type CheckProps = {
7
+ /** Whether option item is disabled. */
8
+ disabled: boolean;
9
+ /** Whether option item is selected. */
10
+ selected: boolean;
11
+ /** Whether option item is pressed. */
12
+ pressed: boolean;
13
+ /** Whether option item is hovered. */
14
+ hovered: boolean;
15
+ /** Whether option item is focused. */
16
+ focused: boolean;
17
+ };
18
+ /**
19
+ * The check component used by OptionItem.
20
+ */
21
+ declare const Check: React.FC<CheckProps>;
22
+ export default Check;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Flowtype definitions for check
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+
10
+ /**
11
+ * Props describing the state of the OptionItem, shared by the checkbox
12
+ * component,
13
+ */
14
+ declare type CheckProps = {
15
+ /**
16
+ * Whether option item is disabled.
17
+ */
18
+ disabled: boolean,
19
+
20
+ /**
21
+ * Whether option item is selected.
22
+ */
23
+ selected: boolean,
24
+
25
+ /**
26
+ * Whether option item is pressed.
27
+ */
28
+ pressed: boolean,
29
+
30
+ /**
31
+ * Whether option item is hovered.
32
+ */
33
+ hovered: boolean,
34
+
35
+ /**
36
+ * Whether option item is focused.
37
+ */
38
+ focused: boolean,
39
+ ...
40
+ };
41
+ /**
42
+ * The check component used by OptionItem.
43
+ */
44
+ declare var Check: React.FC<CheckProps>;
45
+ declare export default typeof Check;