@charcoal-ui/react 5.5.0-beta.3 → 5.6.0-beta.0
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/dist/components/DropdownSelector/index.d.ts +21 -2
- package/dist/components/DropdownSelector/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/DropdownSelector/index.tsx +119 -106
- package/src/components/Pagination/Pagination.story.tsx +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0-beta.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"react-compiler-runtime": "1.0.0",
|
|
55
55
|
"react-stately": "^3.26.0",
|
|
56
56
|
"warning": "^4.0.3",
|
|
57
|
-
"@charcoal-ui/foundation": "5.
|
|
58
|
-
"@charcoal-ui/icons": "5.
|
|
59
|
-
"@charcoal-ui/theme": "5.
|
|
60
|
-
"@charcoal-ui/utils": "5.
|
|
57
|
+
"@charcoal-ui/foundation": "5.6.0-beta.0",
|
|
58
|
+
"@charcoal-ui/icons": "5.6.0-beta.0",
|
|
59
|
+
"@charcoal-ui/theme": "5.6.0-beta.0",
|
|
60
|
+
"@charcoal-ui/utils": "5.6.0-beta.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=17.0.0"
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import './index.css'
|
|
2
2
|
|
|
3
|
-
import React, {
|
|
3
|
+
import React, {
|
|
4
|
+
ReactNode,
|
|
5
|
+
useState,
|
|
6
|
+
useRef,
|
|
7
|
+
useMemo,
|
|
8
|
+
useCallback,
|
|
9
|
+
forwardRef,
|
|
10
|
+
} from 'react'
|
|
4
11
|
import Icon from '../Icon'
|
|
5
12
|
import FieldLabel from '../FieldLabel'
|
|
6
13
|
import { DropdownPopover } from './DropdownPopover'
|
|
@@ -33,118 +40,124 @@ export type DropdownSelectorProps = {
|
|
|
33
40
|
className?: string
|
|
34
41
|
} & Pick<PopoverProps, 'inertWorkaround'>
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
onChange,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
42
|
-
const [isOpen, setIsOpen] = useState(false)
|
|
43
|
-
const preview = findPreviewRecursive(props.children, props.value)
|
|
43
|
+
const DropdownSelector = forwardRef<HTMLSelectElement, DropdownSelectorProps>(
|
|
44
|
+
({ onChange, showLabel = false, ...props }: DropdownSelectorProps, ref) => {
|
|
45
|
+
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
46
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
47
|
+
const preview = findPreviewRecursive(props.children, props.value)
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const isPlaceholder = useMemo(
|
|
50
|
+
() => props.placeholder !== undefined && preview === undefined,
|
|
51
|
+
[preview, props.placeholder],
|
|
52
|
+
)
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
const propsArray = getValuesRecursive(props.children)
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
const { visuallyHiddenProps } = useVisuallyHidden()
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const handleChange = useCallback(
|
|
59
|
+
(e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
60
|
+
onChange(e.target.value)
|
|
61
|
+
},
|
|
62
|
+
[onChange],
|
|
63
|
+
)
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
const labelId = useId()
|
|
66
|
+
const describedbyId = useId()
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
const classNames = useClassNames(
|
|
69
|
+
'charcoal-dropdown-selector-root',
|
|
70
|
+
props.className,
|
|
71
|
+
)
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<span
|
|
117
|
-
className="charcoal-ui-dropdown-selector-text"
|
|
118
|
-
data-placeholder={isPlaceholder}
|
|
119
|
-
>
|
|
120
|
-
{isPlaceholder ? props.placeholder : preview}
|
|
121
|
-
</span>
|
|
122
|
-
<Icon className="charcoal-ui-dropdown-selector-icon" name="16/Menu" />
|
|
123
|
-
</button>
|
|
124
|
-
{isOpen && (
|
|
125
|
-
<DropdownPopover
|
|
126
|
-
isOpen={isOpen}
|
|
127
|
-
onClose={() => setIsOpen(false)}
|
|
128
|
-
triggerRef={triggerRef}
|
|
129
|
-
value={props.value}
|
|
130
|
-
inertWorkaround={props.inertWorkaround}
|
|
73
|
+
return (
|
|
74
|
+
<div className={classNames} aria-disabled={props.disabled}>
|
|
75
|
+
<FieldLabel
|
|
76
|
+
id={labelId}
|
|
77
|
+
label={props.label}
|
|
78
|
+
required={props.required}
|
|
79
|
+
requiredText={props.requiredText}
|
|
80
|
+
subLabel={props.subLabel}
|
|
81
|
+
{...(!showLabel ? visuallyHiddenProps : {})}
|
|
82
|
+
/>
|
|
83
|
+
<div {...visuallyHiddenProps} aria-hidden="true">
|
|
84
|
+
<select
|
|
85
|
+
ref={ref}
|
|
86
|
+
name={props.name}
|
|
87
|
+
value={props.value}
|
|
88
|
+
onChange={handleChange}
|
|
89
|
+
tabIndex={-1}
|
|
90
|
+
>
|
|
91
|
+
{propsArray.map((itemProps) => {
|
|
92
|
+
return (
|
|
93
|
+
<option
|
|
94
|
+
key={itemProps.value}
|
|
95
|
+
value={itemProps.value}
|
|
96
|
+
disabled={itemProps.disabled}
|
|
97
|
+
>
|
|
98
|
+
{itemProps.value}
|
|
99
|
+
</option>
|
|
100
|
+
)
|
|
101
|
+
})}
|
|
102
|
+
</select>
|
|
103
|
+
</div>
|
|
104
|
+
{/* eslint-disable-next-line jsx-a11y/role-supports-aria-props */}
|
|
105
|
+
<button
|
|
106
|
+
className="charcoal-dropdown-selector-button"
|
|
107
|
+
aria-labelledby={labelId}
|
|
108
|
+
aria-invalid={props.invalid}
|
|
109
|
+
aria-describedby={
|
|
110
|
+
props.assistiveText !== undefined ? describedbyId : undefined
|
|
111
|
+
}
|
|
112
|
+
disabled={props.disabled}
|
|
113
|
+
onClick={() => {
|
|
114
|
+
if (props.disabled === true) return
|
|
115
|
+
setIsOpen(true)
|
|
116
|
+
}}
|
|
117
|
+
ref={triggerRef}
|
|
118
|
+
type="button"
|
|
119
|
+
data-active={isOpen}
|
|
131
120
|
>
|
|
132
|
-
<
|
|
121
|
+
<span
|
|
122
|
+
className="charcoal-ui-dropdown-selector-text"
|
|
123
|
+
data-placeholder={isPlaceholder}
|
|
124
|
+
>
|
|
125
|
+
{isPlaceholder ? props.placeholder : preview}
|
|
126
|
+
</span>
|
|
127
|
+
<Icon className="charcoal-ui-dropdown-selector-icon" name="16/Menu" />
|
|
128
|
+
</button>
|
|
129
|
+
{isOpen && (
|
|
130
|
+
<DropdownPopover
|
|
131
|
+
isOpen={isOpen}
|
|
132
|
+
onClose={() => setIsOpen(false)}
|
|
133
|
+
triggerRef={triggerRef}
|
|
133
134
|
value={props.value}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
inertWorkaround={props.inertWorkaround}
|
|
136
|
+
>
|
|
137
|
+
<MenuList
|
|
138
|
+
value={props.value}
|
|
139
|
+
onChange={(v) => {
|
|
140
|
+
onChange(v)
|
|
141
|
+
setIsOpen(false)
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
{props.children}
|
|
145
|
+
</MenuList>
|
|
146
|
+
</DropdownPopover>
|
|
147
|
+
)}
|
|
148
|
+
{props.assistiveText !== undefined && (
|
|
149
|
+
<AssistiveText
|
|
150
|
+
data-invalid={props.invalid === true}
|
|
151
|
+
id={describedbyId}
|
|
138
152
|
>
|
|
139
|
-
{props.
|
|
140
|
-
</
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
153
|
+
{props.assistiveText}
|
|
154
|
+
</AssistiveText>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
)
|
|
158
|
+
},
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
DropdownSelector.displayName = 'DropdownSelector'
|
|
162
|
+
|
|
163
|
+
export default DropdownSelector
|
|
@@ -131,3 +131,16 @@ export const LinkPaginationWithLinkProps: StoryObj<typeof Pagination> = {
|
|
|
131
131
|
</div>
|
|
132
132
|
),
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
export const ComponentAStory: StoryObj<typeof Pagination> = {
|
|
136
|
+
render: () => {
|
|
137
|
+
return (
|
|
138
|
+
<Pagination
|
|
139
|
+
page={5}
|
|
140
|
+
pageCount={100}
|
|
141
|
+
component="a"
|
|
142
|
+
makeUrl={(p) => `https://example.com?page=${p}`}
|
|
143
|
+
/>
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
}
|