playbook_ui 13.23.0 → 13.24.0.pre.alpha.PBNTR261NewKitDropdown2681
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/_playbook.scss +2 -0
- data/app/pb_kits/playbook/index.js +1 -0
- data/app/pb_kits/playbook/pb_avatar/avatar.html.erb +1 -6
- data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +41 -6
- data/app/pb_kits/playbook/pb_bar_graph/bar_graph.rb +4 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_negative_numbers.html.erb +23 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_negative_numbers.jsx +35 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_secondary_y_axis.html.erb +26 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_secondary_y_axis.jsx +36 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_secondary_y_axis.md +3 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_stacked.html.erb +22 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_stacked.jsx +34 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_stacked.md +1 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/example.yml +6 -0
- data/app/pb_kits/playbook/pb_bar_graph/docs/index.js +3 -0
- data/app/pb_kits/playbook/pb_body/_body.scss +3 -3
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +92 -0
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +152 -0
- data/app/pb_kits/playbook/pb_dropdown/context/index.tsx +5 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.jsx +53 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +104 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.jsx +69 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.jsx +78 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +4 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +17 -0
- data/app/pb_kits/playbook/pb_dropdown/hooks/useDropdown.tsx +17 -0
- data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +53 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownContainer.tsx +95 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +91 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +118 -0
- data/app/pb_kits/playbook/pb_list/_list_item.tsx +2 -2
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +27 -19
- data/app/pb_kits/playbook/pb_typeahead/components/MenuList.tsx +4 -2
- data/app/pb_kits/playbook/pb_typeahead/components/index.tsx +19 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_custom_menu_list.jsx +51 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_highlight.jsx +1 -1
- data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/index.js +1 -0
- data/app/pb_kits/playbook/playbook-doc.js +2 -0
- data/app/pb_kits/playbook/tokens/_colors.scss +1 -1
- data/dist/menu.yml +5 -1
- data/dist/playbook-rails.js +6 -6
- data/lib/playbook/kit_base.rb +21 -1
- data/lib/playbook/version.rb +2 -2
- metadata +30 -29
@@ -0,0 +1,118 @@
|
|
1
|
+
import React, { useContext } from "react";
|
2
|
+
import classnames from "classnames";
|
3
|
+
import {
|
4
|
+
buildAriaProps,
|
5
|
+
buildCss,
|
6
|
+
buildDataProps,
|
7
|
+
} from "../../utilities/props";
|
8
|
+
import { globalProps } from "../../utilities/globalProps";
|
9
|
+
import { useHandleOnKeyDown } from "../hooks/useHandleOnKeydown";
|
10
|
+
|
11
|
+
import DropdownContext from "../context";
|
12
|
+
|
13
|
+
import Body from "../../pb_body/_body";
|
14
|
+
import Icon from "../../pb_icon/_icon";
|
15
|
+
import Flex from "../../pb_flex/_flex";
|
16
|
+
import FlexItem from "../../pb_flex/_flex_item";
|
17
|
+
|
18
|
+
type DropdownTriggerProps = {
|
19
|
+
aria?: { [key: string]: string };
|
20
|
+
children?: React.ReactChild[] | React.ReactChild;
|
21
|
+
className?: string;
|
22
|
+
customDisplay?: React.ReactChild[] | React.ReactChild;
|
23
|
+
data?: { [key: string]: string };
|
24
|
+
id?: string;
|
25
|
+
};
|
26
|
+
|
27
|
+
const DropdownTrigger = (props: DropdownTriggerProps) => {
|
28
|
+
const { aria = {}, className, children, customDisplay, data = {}, id } = props;
|
29
|
+
|
30
|
+
const {
|
31
|
+
handleWrapperClick,
|
32
|
+
selected,
|
33
|
+
filterItem,
|
34
|
+
handleChange,
|
35
|
+
toggleDropdown,
|
36
|
+
isDropDownClosed,
|
37
|
+
inputRef,
|
38
|
+
isInputFocused,
|
39
|
+
setIsInputFocused
|
40
|
+
} = useContext(DropdownContext);
|
41
|
+
|
42
|
+
const handleKeyDown = useHandleOnKeyDown();
|
43
|
+
|
44
|
+
const ariaProps = buildAriaProps(aria);
|
45
|
+
const dataProps = buildDataProps(data);
|
46
|
+
const classes = classnames(
|
47
|
+
buildCss("pb_dropdown_trigger"),
|
48
|
+
globalProps(props),
|
49
|
+
className
|
50
|
+
);
|
51
|
+
|
52
|
+
return (
|
53
|
+
<div {...ariaProps}
|
54
|
+
{...dataProps}
|
55
|
+
className={classes}
|
56
|
+
id={id}
|
57
|
+
>
|
58
|
+
{children ? (
|
59
|
+
<div
|
60
|
+
onClick={() => toggleDropdown()}
|
61
|
+
style={{ display: "inline-block" }}
|
62
|
+
>
|
63
|
+
{children}
|
64
|
+
</div>
|
65
|
+
) : (
|
66
|
+
<>
|
67
|
+
<Flex align="center"
|
68
|
+
borderRadius="lg"
|
69
|
+
className={`dropdown_trigger_wrapper ${isInputFocused && 'dropdown_trigger_wrapper_focus'}`}
|
70
|
+
cursor="text"
|
71
|
+
htmlOptions={{ onClick: () => handleWrapperClick(), tabIndex:"0" }}
|
72
|
+
justify="between"
|
73
|
+
paddingX="sm"
|
74
|
+
paddingY="xs"
|
75
|
+
>
|
76
|
+
<FlexItem>
|
77
|
+
<Flex align="center">
|
78
|
+
{customDisplay ? (
|
79
|
+
<Flex align="center">
|
80
|
+
{customDisplay}
|
81
|
+
<Body paddingLeft="xs">
|
82
|
+
<b>{selected.label}</b>
|
83
|
+
</Body>
|
84
|
+
</Flex>
|
85
|
+
) : (
|
86
|
+
selected.label && <Body text={selected.label} />
|
87
|
+
)
|
88
|
+
}
|
89
|
+
<input
|
90
|
+
className="dropdown_input"
|
91
|
+
onChange={handleChange}
|
92
|
+
onClick={() => toggleDropdown()}
|
93
|
+
onFocus={() => setIsInputFocused(true)}
|
94
|
+
onKeyDown={handleKeyDown}
|
95
|
+
placeholder={selected.label ? "" : "Select..."}
|
96
|
+
ref={inputRef}
|
97
|
+
value={filterItem}
|
98
|
+
/>
|
99
|
+
</Flex>
|
100
|
+
</FlexItem>
|
101
|
+
<FlexItem>
|
102
|
+
<Body color="light"
|
103
|
+
key={`${isDropDownClosed ? "chevron-down" : 'chevron-up'}`}
|
104
|
+
>
|
105
|
+
<Icon cursor="pointer"
|
106
|
+
icon={`${isDropDownClosed ? "chevron-down" : 'chevron-up'}`}
|
107
|
+
size="sm"
|
108
|
+
/>
|
109
|
+
</Body>
|
110
|
+
</FlexItem>
|
111
|
+
</Flex>
|
112
|
+
</>
|
113
|
+
)}
|
114
|
+
</div>
|
115
|
+
);
|
116
|
+
};
|
117
|
+
|
118
|
+
export default DropdownTrigger;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import classnames from 'classnames'
|
3
3
|
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
|
4
|
-
import { globalProps } from '../utilities/globalProps'
|
4
|
+
import { globalProps, GlobalProps } from '../utilities/globalProps'
|
5
5
|
|
6
6
|
type ListItemProps = {
|
7
7
|
aria?: { [key: string]: string },
|
@@ -11,7 +11,7 @@ type ListItemProps = {
|
|
11
11
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
12
12
|
id?: string,
|
13
13
|
tabIndex?: number,
|
14
|
-
}
|
14
|
+
} & GlobalProps
|
15
15
|
|
16
16
|
const ListItem = (props: ListItemProps) => {
|
17
17
|
const {
|
@@ -7,17 +7,21 @@ import { get, isString, uniqueId } from 'lodash'
|
|
7
7
|
import { globalProps } from '../utilities/globalProps'
|
8
8
|
import classnames from 'classnames'
|
9
9
|
|
10
|
-
import
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
import {
|
11
|
+
Control,
|
12
|
+
ClearIndicator,
|
13
|
+
IndicatorsContainer,
|
14
|
+
MenuList,
|
15
|
+
MultiValue,
|
16
|
+
Option,
|
17
|
+
Placeholder,
|
18
|
+
ValueContainer,
|
19
|
+
} from "./components"
|
20
|
+
|
21
|
+
import * as kitComponents from "./components"
|
18
22
|
|
19
23
|
import { noop, buildDataProps, buildHtmlProps } from '../utilities/props'
|
20
|
-
import { Noop } from '../types'
|
24
|
+
import { GenericObject, Noop } from '../types'
|
21
25
|
|
22
26
|
/**
|
23
27
|
* @typedef {object} Props
|
@@ -29,7 +33,7 @@ import { Noop } from '../types'
|
|
29
33
|
type TypeaheadProps = {
|
30
34
|
async?: boolean,
|
31
35
|
className?: string,
|
32
|
-
components?:
|
36
|
+
components?: GenericObject,
|
33
37
|
createable?: boolean,
|
34
38
|
dark?: boolean,
|
35
39
|
data?: { [key: string]: string },
|
@@ -100,7 +104,7 @@ const Typeahead = ({
|
|
100
104
|
multiKit: '',
|
101
105
|
onCreateOption: null as null,
|
102
106
|
plusIcon: false,
|
103
|
-
onMultiValueClick: (_option: SelectValueType) =>
|
107
|
+
onMultiValueClick: (_option: SelectValueType): any => undefined,
|
104
108
|
...props,
|
105
109
|
}
|
106
110
|
|
@@ -137,19 +141,23 @@ const Typeahead = ({
|
|
137
141
|
const inlineClass = selectProps.inline ? 'inline' : null
|
138
142
|
|
139
143
|
return (
|
140
|
-
<div
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
+
<div
|
145
|
+
{...dataProps}
|
146
|
+
{...htmlProps}
|
147
|
+
className={classnames(classes, inlineClass)}
|
144
148
|
>
|
145
149
|
<Tag
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
+
classNamePrefix="typeahead-kit-select"
|
151
|
+
error={error}
|
152
|
+
onChange={handleOnChange}
|
153
|
+
{...selectProps}
|
150
154
|
/>
|
151
155
|
</div>
|
152
156
|
)
|
153
157
|
}
|
154
158
|
|
159
|
+
Object.keys(kitComponents).forEach((k) => {
|
160
|
+
(Typeahead as GenericObject)[k] = (kitComponents as {[key: string]: unknown})[k]
|
161
|
+
})
|
162
|
+
|
155
163
|
export default Typeahead
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import { components } from 'react-select'
|
3
3
|
|
4
|
-
const MenuList = (props: any) =>
|
4
|
+
const MenuList = (props: any) => {
|
5
|
+
return (
|
5
6
|
<components.MenuList {...props}>
|
6
7
|
{props.children}
|
8
|
+
{props.footer}
|
7
9
|
</components.MenuList>
|
8
|
-
)
|
10
|
+
)}
|
9
11
|
|
10
12
|
export default MenuList
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import Control from './Control'
|
2
|
+
import ClearIndicator from './ClearIndicator'
|
3
|
+
import IndicatorsContainer from './IndicatorsContainer'
|
4
|
+
import MenuList from './MenuList'
|
5
|
+
import MultiValue from './MultiValue'
|
6
|
+
import Option from './Option'
|
7
|
+
import Placeholder from './Placeholder'
|
8
|
+
import ValueContainer from './ValueContainer'
|
9
|
+
|
10
|
+
export {
|
11
|
+
Control,
|
12
|
+
ClearIndicator,
|
13
|
+
IndicatorsContainer,
|
14
|
+
MenuList,
|
15
|
+
MultiValue,
|
16
|
+
Option,
|
17
|
+
Placeholder,
|
18
|
+
ValueContainer,
|
19
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import React, { useState } from 'react'
|
2
|
+
|
3
|
+
import {
|
4
|
+
Button,
|
5
|
+
} from '../..'
|
6
|
+
|
7
|
+
import Typeahead from '../_typeahead'
|
8
|
+
|
9
|
+
const options = [
|
10
|
+
{ label: 'Orange', value: '#FFA500' },
|
11
|
+
{ label: 'Red', value: '#FF0000' },
|
12
|
+
{ label: 'Green', value: '#00FF00' },
|
13
|
+
{ label: 'Blue', value: '#0000FF' },
|
14
|
+
{ label: 'Amaranth', value: '#9F2B68' },
|
15
|
+
{ label: 'Key Lime', value: '#DAF7A6' },
|
16
|
+
{ label: 'Turquois', value: '#00FFD0' },
|
17
|
+
]
|
18
|
+
|
19
|
+
const TypeaheadCustomMenuList = (props) => {
|
20
|
+
const defaultColorOptions = options.slice(0, 3)
|
21
|
+
const [colorOptions, setColorOptions] = useState(defaultColorOptions)
|
22
|
+
|
23
|
+
const moreToLoad = colorOptions.length == defaultColorOptions.length
|
24
|
+
const loadColors = moreToLoad ? () => setColorOptions(options) : () => setColorOptions(defaultColorOptions)
|
25
|
+
|
26
|
+
const menuListProps = {
|
27
|
+
footer: (<Button
|
28
|
+
margin="sm"
|
29
|
+
onClick={loadColors}
|
30
|
+
text={`Load ${moreToLoad ? "More" : "Less"}`}
|
31
|
+
/>)
|
32
|
+
}
|
33
|
+
|
34
|
+
const MenuList = (props) => (
|
35
|
+
<Typeahead.MenuList
|
36
|
+
{...menuListProps}
|
37
|
+
{...props}
|
38
|
+
/>
|
39
|
+
)
|
40
|
+
|
41
|
+
return (
|
42
|
+
<Typeahead
|
43
|
+
components={{ MenuList }}
|
44
|
+
label="Colors"
|
45
|
+
options={colorOptions}
|
46
|
+
{...props}
|
47
|
+
/>
|
48
|
+
)
|
49
|
+
}
|
50
|
+
|
51
|
+
export default TypeaheadCustomMenuList
|
@@ -9,3 +9,4 @@ export { default as TypeaheadMultiKit } from './_typeahead_multi_kit.jsx'
|
|
9
9
|
export { default as TypeaheadCreateable } from './_typeahead_createable.jsx'
|
10
10
|
export { default as TypeaheadAsyncCreateable } from './_typeahead_async_createable.jsx'
|
11
11
|
export { default as TypeaheadErrorState } from './_typeahead_error_state.jsx'
|
12
|
+
export { default as TypeaheadCustomMenuList } from './_typeahead_custom_menu_list.jsx'
|
@@ -34,6 +34,7 @@ import * as DateYearStacked from 'pb_date_year_stacked/docs'
|
|
34
34
|
import * as Detail from 'pb_detail/docs'
|
35
35
|
import * as Dialog from 'pb_dialog/docs'
|
36
36
|
import * as DistributionBarDocs from 'pb_distribution_bar/docs'
|
37
|
+
import * as Dropdown from 'pb_dropdown/docs'
|
37
38
|
import * as FileUpload from 'pb_file_upload/docs'
|
38
39
|
import * as Filter from 'pb_filter/docs'
|
39
40
|
import * as FixedConfirmationToast from 'pb_fixed_confirmation_toast/docs'
|
@@ -136,6 +137,7 @@ WebpackerReact.registerComponents({
|
|
136
137
|
...Detail,
|
137
138
|
...Dialog,
|
138
139
|
...DistributionBarDocs,
|
140
|
+
...Dropdown,
|
139
141
|
...FileUpload,
|
140
142
|
...Filter,
|
141
143
|
...FixedConfirmationToast,
|
data/dist/menu.yml
CHANGED
@@ -254,6 +254,10 @@ kits:
|
|
254
254
|
platforms: *web
|
255
255
|
description: Playbook's date picker is built using flatpickr, a vanilla js library. Common date picker use cases and features have been adapted into simple prop based configuration detailed in the docs below.
|
256
256
|
status: "stable"
|
257
|
+
- name: dropdown
|
258
|
+
platforms: *react_only
|
259
|
+
description: ""
|
260
|
+
status: "beta"
|
257
261
|
- name: "multi_level_select"
|
258
262
|
platforms: *web
|
259
263
|
description: The MultiLevelSelect kit renders a multi leveled select dropdown based on data from the user.
|
@@ -460,4 +464,4 @@ kits:
|
|
460
464
|
- name: "user"
|
461
465
|
platforms: *web
|
462
466
|
description: This kit was created for having a systematic way of displaying users with avatar, titles, name and territory. This is a versatile kit with features than can be added to display more info.
|
463
|
-
status: "stable"
|
467
|
+
status: "stable"
|