@zendeskgarden/react-buttons 8.69.3 → 8.69.5
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/index.cjs.js +45 -21
- package/dist/index.esm.js +46 -23
- package/dist/typings/index.d.ts +1 -2
- package/package.json +7 -6
package/dist/index.cjs.js
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var PropTypes = require('prop-types');
|
|
12
|
+
var mergeRefs = require('react-merge-refs');
|
|
12
13
|
var styled = require('styled-components');
|
|
13
14
|
var reactTheming = require('@zendeskgarden/react-theming');
|
|
14
15
|
var polished = require('polished');
|
|
15
|
-
var
|
|
16
|
+
var containerSelection = require('@zendeskgarden/container-selection');
|
|
17
|
+
var containerUtilities = require('@zendeskgarden/container-utilities');
|
|
16
18
|
|
|
17
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
20
|
|
|
@@ -36,6 +38,7 @@ function _interopNamespace(e) {
|
|
|
36
38
|
|
|
37
39
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
38
40
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
41
|
+
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
39
42
|
var styled__default = /*#__PURE__*/_interopDefault(styled);
|
|
40
43
|
|
|
41
44
|
function _extends$2() {
|
|
@@ -58,7 +61,7 @@ const SIZE = ['small', 'medium', 'large'];
|
|
|
58
61
|
const COMPONENT_ID$5 = 'buttons.button_group_view';
|
|
59
62
|
const StyledButtonGroup = styled__default.default.div.attrs({
|
|
60
63
|
'data-garden-id': COMPONENT_ID$5,
|
|
61
|
-
'data-garden-version': '8.69.
|
|
64
|
+
'data-garden-version': '8.69.5'
|
|
62
65
|
}).withConfig({
|
|
63
66
|
displayName: "StyledButtonGroup",
|
|
64
67
|
componentId: "sc-1fbpzef-0"
|
|
@@ -87,7 +90,7 @@ const StyledIcon = styled__default.default(_ref => {
|
|
|
87
90
|
return React__namespace.default.cloneElement(React.Children.only(children), props);
|
|
88
91
|
}).attrs({
|
|
89
92
|
'data-garden-id': COMPONENT_ID$4,
|
|
90
|
-
'data-garden-version': '8.69.
|
|
93
|
+
'data-garden-version': '8.69.5'
|
|
91
94
|
}).withConfig({
|
|
92
95
|
displayName: "StyledIcon",
|
|
93
96
|
componentId: "sc-19meqgg-0"
|
|
@@ -225,7 +228,7 @@ const sizeStyles = props => {
|
|
|
225
228
|
};
|
|
226
229
|
const StyledButton = styled__default.default.button.attrs(props => ({
|
|
227
230
|
'data-garden-id': COMPONENT_ID$3,
|
|
228
|
-
'data-garden-version': '8.69.
|
|
231
|
+
'data-garden-version': '8.69.5',
|
|
229
232
|
type: props.type || 'button'
|
|
230
233
|
})).withConfig({
|
|
231
234
|
displayName: "StyledButton",
|
|
@@ -238,7 +241,7 @@ StyledButton.defaultProps = {
|
|
|
238
241
|
const COMPONENT_ID$2 = 'buttons.anchor';
|
|
239
242
|
const StyledAnchor = styled__default.default(StyledButton).attrs(props => ({
|
|
240
243
|
'data-garden-id': COMPONENT_ID$2,
|
|
241
|
-
'data-garden-version': '8.69.
|
|
244
|
+
'data-garden-version': '8.69.5',
|
|
242
245
|
as: 'a',
|
|
243
246
|
dir: props.theme.rtl ? 'rtl' : undefined,
|
|
244
247
|
isLink: true,
|
|
@@ -272,7 +275,7 @@ var SvgNewWindowStroke = function SvgNewWindowStroke(props) {
|
|
|
272
275
|
const COMPONENT_ID$1 = 'buttons.external_icon';
|
|
273
276
|
const StyledExternalIcon = styled__default.default(SvgNewWindowStroke).attrs({
|
|
274
277
|
'data-garden-id': COMPONENT_ID$1,
|
|
275
|
-
'data-garden-version': '8.69.
|
|
278
|
+
'data-garden-version': '8.69.5'
|
|
276
279
|
}).withConfig({
|
|
277
280
|
displayName: "StyledExternalIcon",
|
|
278
281
|
componentId: "sc-16oz07e-0"
|
|
@@ -299,7 +302,7 @@ const iconStyles = props => {
|
|
|
299
302
|
};
|
|
300
303
|
const StyledIconButton = styled__default.default(StyledButton).attrs({
|
|
301
304
|
'data-garden-id': COMPONENT_ID,
|
|
302
|
-
'data-garden-version': '8.69.
|
|
305
|
+
'data-garden-version': '8.69.5'
|
|
303
306
|
}).withConfig({
|
|
304
307
|
displayName: "StyledIconButton",
|
|
305
308
|
componentId: "sc-1t0ughp-0"
|
|
@@ -333,6 +336,7 @@ const EndIcon = EndIconComponent;
|
|
|
333
336
|
const ButtonComponent = React.forwardRef((props, ref) => {
|
|
334
337
|
const buttonGroupContext = useButtonGroupContext();
|
|
335
338
|
const splitButtonContext = useSplitButtonContext();
|
|
339
|
+
let computedRef = ref;
|
|
336
340
|
let computedProps = {
|
|
337
341
|
...props,
|
|
338
342
|
focusInset: props.focusInset || buttonGroupContext !== undefined || splitButtonContext
|
|
@@ -342,15 +346,15 @@ const ButtonComponent = React.forwardRef((props, ref) => {
|
|
|
342
346
|
throw new Error('"value" prop must be provided to Button when used within a ButtonGroup');
|
|
343
347
|
}
|
|
344
348
|
computedProps = buttonGroupContext.getButtonProps({
|
|
345
|
-
item: props.value,
|
|
346
|
-
focusRef: React__namespace.default.createRef(),
|
|
347
349
|
isSelected: props.value === buttonGroupContext.selectedItem,
|
|
348
350
|
...computedProps
|
|
349
351
|
});
|
|
352
|
+
computedRef = mergeRefs__default.default([
|
|
353
|
+
computedProps.ref, ref]);
|
|
350
354
|
}
|
|
351
|
-
return React__namespace.default.createElement(StyledButton, _extends$2({
|
|
352
|
-
ref:
|
|
353
|
-
}
|
|
355
|
+
return React__namespace.default.createElement(StyledButton, _extends$2({}, computedProps, {
|
|
356
|
+
ref: computedRef
|
|
357
|
+
}));
|
|
354
358
|
});
|
|
355
359
|
ButtonComponent.displayName = 'Button';
|
|
356
360
|
ButtonComponent.propTypes = {
|
|
@@ -413,22 +417,42 @@ const ButtonGroup = React.forwardRef((_ref, ref) => {
|
|
|
413
417
|
let {
|
|
414
418
|
children,
|
|
415
419
|
onSelect,
|
|
416
|
-
selectedItem:
|
|
420
|
+
selectedItem: controlledSelectedValue,
|
|
417
421
|
...otherProps
|
|
418
422
|
} = _ref;
|
|
419
423
|
const {
|
|
420
|
-
|
|
421
|
-
|
|
424
|
+
rtl
|
|
425
|
+
} = React.useContext(styled.ThemeContext) || reactTheming.DEFAULT_THEME;
|
|
426
|
+
const [internalSelectedValue, setInternalSelectedValue] = React.useState();
|
|
427
|
+
const selectedValue = containerUtilities.getControlledValue(controlledSelectedValue, internalSelectedValue);
|
|
428
|
+
const values = React.useMemo(() => React.Children.toArray(children).reduce((buttons, child) => {
|
|
429
|
+
if ( React.isValidElement(child) && child.type !== 'string' && !child.props.disabled) {
|
|
430
|
+
buttons.push(child.props.value);
|
|
431
|
+
}
|
|
432
|
+
return buttons;
|
|
433
|
+
}, []), [children]);
|
|
434
|
+
const {
|
|
435
|
+
selectedValue: selectedItem,
|
|
436
|
+
getElementProps,
|
|
422
437
|
getGroupProps
|
|
423
|
-
} =
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
438
|
+
} = containerSelection.useSelection({
|
|
439
|
+
rtl,
|
|
440
|
+
values,
|
|
441
|
+
defaultSelectedValue: values[0],
|
|
442
|
+
selectedValue,
|
|
443
|
+
onSelect: React.useCallback(value => {
|
|
444
|
+
onSelect && onSelect(value);
|
|
445
|
+
setInternalSelectedValue(value);
|
|
446
|
+
}, [onSelect])
|
|
427
447
|
});
|
|
428
448
|
const contextValue = React.useMemo(() => ({
|
|
429
449
|
selectedItem,
|
|
430
|
-
getButtonProps
|
|
431
|
-
|
|
450
|
+
getButtonProps: props => getElementProps({
|
|
451
|
+
role: 'button',
|
|
452
|
+
selectedAriaKey: 'aria-pressed',
|
|
453
|
+
...props
|
|
454
|
+
})
|
|
455
|
+
}), [selectedItem, getElementProps]);
|
|
432
456
|
return React__namespace.default.createElement(ButtonGroupContext.Provider, {
|
|
433
457
|
value: contextValue
|
|
434
458
|
}, React__namespace.default.createElement(StyledButtonGroup, _extends$2({
|
package/dist/index.esm.js
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import * as React from 'react';
|
|
9
|
-
import React__default, { Children, createContext, useContext, forwardRef, useMemo } from 'react';
|
|
9
|
+
import React__default, { Children, createContext, useContext, forwardRef, useState, useMemo, isValidElement, useCallback } from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
|
-
import
|
|
11
|
+
import mergeRefs from 'react-merge-refs';
|
|
12
|
+
import styled, { css, ThemeContext } from 'styled-components';
|
|
12
13
|
import { retrieveComponentStyles, DEFAULT_THEME, SELECTOR_FOCUS_VISIBLE, getColor, focusStyles, getFocusBoxShadow, useText } from '@zendeskgarden/react-theming';
|
|
13
14
|
import { rgba, math, em } from 'polished';
|
|
14
|
-
import {
|
|
15
|
+
import { useSelection } from '@zendeskgarden/container-selection';
|
|
16
|
+
import { getControlledValue } from '@zendeskgarden/container-utilities';
|
|
15
17
|
|
|
16
18
|
function _extends$2() {
|
|
17
19
|
_extends$2 = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -33,7 +35,7 @@ const SIZE = ['small', 'medium', 'large'];
|
|
|
33
35
|
const COMPONENT_ID$5 = 'buttons.button_group_view';
|
|
34
36
|
const StyledButtonGroup = styled.div.attrs({
|
|
35
37
|
'data-garden-id': COMPONENT_ID$5,
|
|
36
|
-
'data-garden-version': '8.69.
|
|
38
|
+
'data-garden-version': '8.69.5'
|
|
37
39
|
}).withConfig({
|
|
38
40
|
displayName: "StyledButtonGroup",
|
|
39
41
|
componentId: "sc-1fbpzef-0"
|
|
@@ -62,7 +64,7 @@ const StyledIcon = styled(_ref => {
|
|
|
62
64
|
return React__default.cloneElement(Children.only(children), props);
|
|
63
65
|
}).attrs({
|
|
64
66
|
'data-garden-id': COMPONENT_ID$4,
|
|
65
|
-
'data-garden-version': '8.69.
|
|
67
|
+
'data-garden-version': '8.69.5'
|
|
66
68
|
}).withConfig({
|
|
67
69
|
displayName: "StyledIcon",
|
|
68
70
|
componentId: "sc-19meqgg-0"
|
|
@@ -200,7 +202,7 @@ const sizeStyles = props => {
|
|
|
200
202
|
};
|
|
201
203
|
const StyledButton = styled.button.attrs(props => ({
|
|
202
204
|
'data-garden-id': COMPONENT_ID$3,
|
|
203
|
-
'data-garden-version': '8.69.
|
|
205
|
+
'data-garden-version': '8.69.5',
|
|
204
206
|
type: props.type || 'button'
|
|
205
207
|
})).withConfig({
|
|
206
208
|
displayName: "StyledButton",
|
|
@@ -213,7 +215,7 @@ StyledButton.defaultProps = {
|
|
|
213
215
|
const COMPONENT_ID$2 = 'buttons.anchor';
|
|
214
216
|
const StyledAnchor = styled(StyledButton).attrs(props => ({
|
|
215
217
|
'data-garden-id': COMPONENT_ID$2,
|
|
216
|
-
'data-garden-version': '8.69.
|
|
218
|
+
'data-garden-version': '8.69.5',
|
|
217
219
|
as: 'a',
|
|
218
220
|
dir: props.theme.rtl ? 'rtl' : undefined,
|
|
219
221
|
isLink: true,
|
|
@@ -247,7 +249,7 @@ var SvgNewWindowStroke = function SvgNewWindowStroke(props) {
|
|
|
247
249
|
const COMPONENT_ID$1 = 'buttons.external_icon';
|
|
248
250
|
const StyledExternalIcon = styled(SvgNewWindowStroke).attrs({
|
|
249
251
|
'data-garden-id': COMPONENT_ID$1,
|
|
250
|
-
'data-garden-version': '8.69.
|
|
252
|
+
'data-garden-version': '8.69.5'
|
|
251
253
|
}).withConfig({
|
|
252
254
|
displayName: "StyledExternalIcon",
|
|
253
255
|
componentId: "sc-16oz07e-0"
|
|
@@ -274,7 +276,7 @@ const iconStyles = props => {
|
|
|
274
276
|
};
|
|
275
277
|
const StyledIconButton = styled(StyledButton).attrs({
|
|
276
278
|
'data-garden-id': COMPONENT_ID,
|
|
277
|
-
'data-garden-version': '8.69.
|
|
279
|
+
'data-garden-version': '8.69.5'
|
|
278
280
|
}).withConfig({
|
|
279
281
|
displayName: "StyledIconButton",
|
|
280
282
|
componentId: "sc-1t0ughp-0"
|
|
@@ -308,6 +310,7 @@ const EndIcon = EndIconComponent;
|
|
|
308
310
|
const ButtonComponent = forwardRef((props, ref) => {
|
|
309
311
|
const buttonGroupContext = useButtonGroupContext();
|
|
310
312
|
const splitButtonContext = useSplitButtonContext();
|
|
313
|
+
let computedRef = ref;
|
|
311
314
|
let computedProps = {
|
|
312
315
|
...props,
|
|
313
316
|
focusInset: props.focusInset || buttonGroupContext !== undefined || splitButtonContext
|
|
@@ -317,15 +320,15 @@ const ButtonComponent = forwardRef((props, ref) => {
|
|
|
317
320
|
throw new Error('"value" prop must be provided to Button when used within a ButtonGroup');
|
|
318
321
|
}
|
|
319
322
|
computedProps = buttonGroupContext.getButtonProps({
|
|
320
|
-
item: props.value,
|
|
321
|
-
focusRef: React__default.createRef(),
|
|
322
323
|
isSelected: props.value === buttonGroupContext.selectedItem,
|
|
323
324
|
...computedProps
|
|
324
325
|
});
|
|
326
|
+
computedRef = mergeRefs([
|
|
327
|
+
computedProps.ref, ref]);
|
|
325
328
|
}
|
|
326
|
-
return React__default.createElement(StyledButton, _extends$2({
|
|
327
|
-
ref:
|
|
328
|
-
}
|
|
329
|
+
return React__default.createElement(StyledButton, _extends$2({}, computedProps, {
|
|
330
|
+
ref: computedRef
|
|
331
|
+
}));
|
|
329
332
|
});
|
|
330
333
|
ButtonComponent.displayName = 'Button';
|
|
331
334
|
ButtonComponent.propTypes = {
|
|
@@ -388,22 +391,42 @@ const ButtonGroup = forwardRef((_ref, ref) => {
|
|
|
388
391
|
let {
|
|
389
392
|
children,
|
|
390
393
|
onSelect,
|
|
391
|
-
selectedItem:
|
|
394
|
+
selectedItem: controlledSelectedValue,
|
|
392
395
|
...otherProps
|
|
393
396
|
} = _ref;
|
|
394
397
|
const {
|
|
395
|
-
|
|
396
|
-
|
|
398
|
+
rtl
|
|
399
|
+
} = useContext(ThemeContext) || DEFAULT_THEME;
|
|
400
|
+
const [internalSelectedValue, setInternalSelectedValue] = useState();
|
|
401
|
+
const selectedValue = getControlledValue(controlledSelectedValue, internalSelectedValue);
|
|
402
|
+
const values = useMemo(() => Children.toArray(children).reduce((buttons, child) => {
|
|
403
|
+
if ( isValidElement(child) && child.type !== 'string' && !child.props.disabled) {
|
|
404
|
+
buttons.push(child.props.value);
|
|
405
|
+
}
|
|
406
|
+
return buttons;
|
|
407
|
+
}, []), [children]);
|
|
408
|
+
const {
|
|
409
|
+
selectedValue: selectedItem,
|
|
410
|
+
getElementProps,
|
|
397
411
|
getGroupProps
|
|
398
|
-
} =
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
412
|
+
} = useSelection({
|
|
413
|
+
rtl,
|
|
414
|
+
values,
|
|
415
|
+
defaultSelectedValue: values[0],
|
|
416
|
+
selectedValue,
|
|
417
|
+
onSelect: useCallback(value => {
|
|
418
|
+
onSelect && onSelect(value);
|
|
419
|
+
setInternalSelectedValue(value);
|
|
420
|
+
}, [onSelect])
|
|
402
421
|
});
|
|
403
422
|
const contextValue = useMemo(() => ({
|
|
404
423
|
selectedItem,
|
|
405
|
-
getButtonProps
|
|
406
|
-
|
|
424
|
+
getButtonProps: props => getElementProps({
|
|
425
|
+
role: 'button',
|
|
426
|
+
selectedAriaKey: 'aria-pressed',
|
|
427
|
+
...props
|
|
428
|
+
})
|
|
429
|
+
}), [selectedItem, getElementProps]);
|
|
407
430
|
return React__default.createElement(ButtonGroupContext.Provider, {
|
|
408
431
|
value: contextValue
|
|
409
432
|
}, React__default.createElement(StyledButtonGroup, _extends$2({
|
package/dist/typings/index.d.ts
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
|
-
export { Button } from './elements/Button';
|
|
8
|
-
export type { IIconProps } from './elements/Button';
|
|
7
|
+
export { Button, type IIconProps } from './elements/Button';
|
|
9
8
|
export { Anchor } from './elements/Anchor';
|
|
10
9
|
export { ButtonGroup } from './elements/ButtonGroup';
|
|
11
10
|
export { ChevronButton } from './elements/ChevronButton';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zendeskgarden/react-buttons",
|
|
3
|
-
"version": "8.69.
|
|
3
|
+
"version": "8.69.5",
|
|
4
4
|
"description": "Components relating to buttons in the Garden Design System",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Zendesk Garden <garden@zendesk.com>",
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"types": "dist/typings/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zendeskgarden/container-
|
|
25
|
-
"@zendeskgarden/container-
|
|
24
|
+
"@zendeskgarden/container-selection": "^3.0.0",
|
|
25
|
+
"@zendeskgarden/container-utilities": "^1.0.6",
|
|
26
26
|
"polished": "^4.0.0",
|
|
27
|
-
"prop-types": "^15.5.7"
|
|
27
|
+
"prop-types": "^15.5.7",
|
|
28
|
+
"react-merge-refs": "^1.1.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"@zendeskgarden/react-theming": "^8.67.0",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"styled-components": "^4.2.0 || ^5.0.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@zendeskgarden/react-theming": "^8.69.
|
|
37
|
+
"@zendeskgarden/react-theming": "^8.69.5",
|
|
37
38
|
"@zendeskgarden/svg-icons": "6.33.0"
|
|
38
39
|
},
|
|
39
40
|
"keywords": [
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"access": "public"
|
|
47
48
|
},
|
|
48
49
|
"zendeskgarden:src": "src/index.ts",
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "610a2e79728debaa8ea03de256d81b83cf4e595f"
|
|
50
51
|
}
|