@pingux/astro 2.31.0 → 2.32.0-alpha.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/README.md +11 -4
- package/lib/README.md +11 -4
- package/lib/cjs/components/Breadcrumbs/BreadcrumbItem.js +3 -2
- package/lib/cjs/components/Button/Button.d.ts +4 -0
- package/lib/cjs/components/Button/Button.js +37 -24
- package/lib/cjs/components/Button/Button.stories.d.ts +46 -0
- package/lib/cjs/components/Button/Button.test.d.ts +1 -0
- package/lib/cjs/components/Button/Buttons.styles.d.ts +748 -0
- package/lib/cjs/components/Button/Buttons.styles.js +0 -2
- package/lib/cjs/components/Button/buttonAttributes.d.ts +1 -0
- package/lib/cjs/components/Button/buttonAttributes.js +9 -55
- package/lib/cjs/components/Button/constants.d.ts +4 -0
- package/lib/cjs/components/Button/index.d.ts +1 -0
- package/lib/cjs/hooks/index.d.ts +22 -0
- package/lib/cjs/hooks/index.js +7 -0
- package/lib/cjs/hooks/useDeprecationWarning/index.d.ts +1 -0
- package/lib/cjs/hooks/useDeprecationWarning/useDeprecationWarning.d.ts +21 -0
- package/lib/cjs/hooks/useDeprecationWarning/useDeprecationWarning.js +0 -10
- package/lib/cjs/hooks/useLocalOrForwardRef/index.d.ts +1 -0
- package/lib/cjs/hooks/useLocalOrForwardRef/index.js +14 -0
- package/lib/cjs/hooks/useLocalOrForwardRef/useLocalOrForwardRef.d.ts +7 -0
- package/lib/cjs/hooks/useLocalOrForwardRef/useLocalOrForwardRef.js +21 -0
- package/lib/cjs/hooks/useLocalOrForwardRef/useLocalOrForwardRef.test.d.ts +1 -0
- package/lib/cjs/hooks/useLocalOrForwardRef/useLocalOrForwardRef.test.js +70 -0
- package/lib/cjs/types/button.d.ts +7 -0
- package/lib/cjs/types/button.js +6 -0
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +19 -8
- package/lib/cjs/types/shared/dom.d.ts +2 -1
- package/lib/cjs/types/shared/events.d.ts +5 -0
- package/lib/cjs/types/shared/events.js +6 -0
- package/lib/cjs/types/shared/index.d.ts +1 -0
- package/lib/cjs/types/shared/index.js +14 -3
- package/lib/cjs/utils/docUtils/ariaAttributes.d.ts +105 -0
- package/lib/cjs/utils/docUtils/pressAttributes.d.ts +7 -0
- package/lib/cjs/utils/docUtils/pressAttributes.js +49 -0
- package/lib/components/Breadcrumbs/BreadcrumbItem.js +3 -2
- package/lib/components/Button/Button.js +39 -26
- package/lib/components/Button/Buttons.styles.js +0 -2
- package/lib/components/Button/buttonAttributes.js +9 -55
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/useDeprecationWarning/useDeprecationWarning.js +0 -10
- package/lib/hooks/useLocalOrForwardRef/index.js +1 -0
- package/lib/hooks/useLocalOrForwardRef/useLocalOrForwardRef.js +14 -0
- package/lib/hooks/useLocalOrForwardRef/useLocalOrForwardRef.test.js +61 -0
- package/lib/types/button.js +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/shared/events.js +1 -0
- package/lib/types/shared/index.js +1 -0
- package/lib/utils/docUtils/pressAttributes.js +41 -0
- package/package.json +1 -1
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
4
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
5
|
+
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
6
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
7
|
+
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
8
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
9
|
+
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
10
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
11
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
12
|
+
_Object$defineProperty(exports, "__esModule", {
|
13
|
+
value: true
|
14
|
+
});
|
15
|
+
exports.onPressArgTypes = void 0;
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
17
|
+
var _docArgTypes = require("./docArgTypes");
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
20
|
+
var descriptions = {
|
21
|
+
onPress: 'Handler that is called when the press is released over the target. (e: PressEvent) => void',
|
22
|
+
onPressChange: 'Handler that is called when the press state changes. (isPressed: boolean) => void',
|
23
|
+
onPressEnd: 'Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. (e: PressEvent) => void',
|
24
|
+
onPressStart: 'Handler that is called when a press interaction starts. (e: PressEvent) => void',
|
25
|
+
onPressUp: 'Handler that is called when a press is released over the target, regardless of whether it started on the target or not. (e: PressEvent) => void'
|
26
|
+
};
|
27
|
+
var baseDocSettings = _objectSpread(_objectSpread({}, _docArgTypes.funcArg), {}, {
|
28
|
+
table: {
|
29
|
+
category: 'Press Handlers'
|
30
|
+
}
|
31
|
+
});
|
32
|
+
var onPressArgTypes = {
|
33
|
+
onPress: _objectSpread({
|
34
|
+
description: descriptions.onPress
|
35
|
+
}, baseDocSettings),
|
36
|
+
onPressStart: _objectSpread({
|
37
|
+
description: descriptions.onPressStart
|
38
|
+
}, baseDocSettings),
|
39
|
+
onPressEnd: _objectSpread({
|
40
|
+
description: descriptions.onPressEnd
|
41
|
+
}, baseDocSettings),
|
42
|
+
onPressChange: _objectSpread({
|
43
|
+
description: descriptions.onPressChange
|
44
|
+
}, baseDocSettings),
|
45
|
+
onPressUp: _objectSpread({
|
46
|
+
description: descriptions.onPressUp
|
47
|
+
}, baseDocSettings)
|
48
|
+
};
|
49
|
+
exports.onPressArgTypes = onPressArgTypes;
|
@@ -9,6 +9,7 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
11
11
|
var _excluded = ["children", "elementType", "onAction", "actionKey", "isCurrent"];
|
12
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
12
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
13
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
14
15
|
import React, { forwardRef, Fragment, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
|
@@ -54,10 +55,10 @@ var BreadcrumbItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
54
55
|
onAction(actionKey);
|
55
56
|
}
|
56
57
|
}, [onAction, actionKey]);
|
58
|
+
var elementsWithOnPressProp = ['Button', 'IconButton', 'Link'];
|
57
59
|
var elementProps = useMemo(function () {
|
58
|
-
var _ElementType$propType;
|
59
60
|
var elementTypeProps = _objectSpread({}, mergeProps(itemProps, others));
|
60
|
-
if ((
|
61
|
+
if (_includesInstanceProperty(elementsWithOnPressProp).call(elementsWithOnPressProp, elementType)) {
|
61
62
|
elementTypeProps.onPress = onPressHandler;
|
62
63
|
}
|
63
64
|
if (isCurrent) {
|
@@ -9,57 +9,72 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["className", "isDisabled", "isLoading", "
|
12
|
+
var _excluded = ["children", "className", "isDisabled", "isLoading", "onBlur", "onFocus", "onHoverChange", "onHoverEnd", "onHoverStart", "onKeyDown", "onKeyUp", "onPress", "onPressChange", "onPressEnd", "onPressStart", "onPressUp", "tabIndex", "variant"];
|
13
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
|
-
import React, { forwardRef
|
15
|
+
import React, { forwardRef } from 'react';
|
16
16
|
import { mergeProps, useButton, useFocusRing } from 'react-aria';
|
17
17
|
import { Pressable, useHover, usePress } from '@react-aria/interactions';
|
18
18
|
import { Button as ThemeUIButton } from 'theme-ui';
|
19
|
-
import { useAriaLabelWarning, usePropWarning, useStatusClasses } from '../../hooks';
|
19
|
+
import { useAriaLabelWarning, useLocalOrForwardRef, usePropWarning, useStatusClasses } from '../../hooks';
|
20
20
|
import Loader from '../Loader';
|
21
|
-
import { buttonPropTypes } from './buttonAttributes';
|
22
21
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
23
22
|
var Button = /*#__PURE__*/forwardRef(function (props, ref) {
|
24
|
-
var
|
23
|
+
var children = props.children,
|
24
|
+
className = props.className,
|
25
25
|
isDisabled = props.isDisabled,
|
26
26
|
isLoading = props.isLoading,
|
27
|
-
|
27
|
+
onBlur = props.onBlur,
|
28
|
+
onFocus = props.onFocus,
|
28
29
|
onHoverChange = props.onHoverChange,
|
29
30
|
onHoverEnd = props.onHoverEnd,
|
31
|
+
onHoverStart = props.onHoverStart,
|
32
|
+
onKeyDown = props.onKeyDown,
|
33
|
+
onKeyUp = props.onKeyUp,
|
30
34
|
onPress = props.onPress,
|
31
|
-
onPressStart = props.onPressStart,
|
32
|
-
onPressEnd = props.onPressEnd,
|
33
35
|
onPressChange = props.onPressChange,
|
36
|
+
onPressEnd = props.onPressEnd,
|
37
|
+
onPressStart = props.onPressStart,
|
34
38
|
onPressUp = props.onPressUp,
|
35
|
-
children = props.children,
|
36
|
-
variant = props.variant,
|
37
39
|
tabIndex = props.tabIndex,
|
40
|
+
variant = props.variant,
|
38
41
|
others = _objectWithoutProperties(props, _excluded);
|
39
|
-
var buttonRef =
|
42
|
+
var buttonRef = useLocalOrForwardRef(ref);
|
40
43
|
usePropWarning(props, 'disabled', 'isDisabled');
|
41
|
-
/* istanbul ignore next */
|
42
|
-
useImperativeHandle(ref, function () {
|
43
|
-
return buttonRef.current;
|
44
|
-
});
|
45
44
|
var _useFocusRing = useFocusRing(),
|
46
45
|
isFocusVisible = _useFocusRing.isFocusVisible,
|
47
46
|
focusProps = _useFocusRing.focusProps;
|
48
|
-
var _usePress = usePress(
|
47
|
+
var _usePress = usePress({
|
48
|
+
ref: buttonRef
|
49
|
+
}),
|
49
50
|
isPressedFromContext = _usePress.isPressed;
|
50
51
|
var _useButton = useButton(_objectSpread({
|
51
|
-
elementType: 'button'
|
52
|
-
|
52
|
+
elementType: 'button',
|
53
|
+
isDisabled: isDisabled,
|
54
|
+
onBlur: onBlur,
|
55
|
+
onFocus: onFocus,
|
56
|
+
onKeyDown: onKeyDown,
|
57
|
+
onKeyUp: onKeyUp,
|
58
|
+
onPress: onPress,
|
59
|
+
onPressChange: onPressChange,
|
60
|
+
onPressEnd: onPressEnd,
|
61
|
+
onPressStart: onPressStart,
|
62
|
+
onPressUp: onPressUp
|
63
|
+
}, others), buttonRef),
|
53
64
|
buttonProps = _useButton.buttonProps,
|
54
65
|
isPressed = _useButton.isPressed;
|
55
|
-
var _useHover = useHover(
|
66
|
+
var _useHover = useHover({
|
67
|
+
onHoverChange: onHoverChange,
|
68
|
+
onHoverEnd: onHoverEnd,
|
69
|
+
onHoverStart: onHoverStart
|
70
|
+
}),
|
56
71
|
hoverProps = _useHover.hoverProps,
|
57
72
|
isHovered = _useHover.isHovered;
|
58
73
|
var _useStatusClasses = useStatusClasses(className, {
|
59
|
-
|
60
|
-
isPressed: isPressed || isPressedFromContext,
|
74
|
+
isDisabled: isDisabled,
|
61
75
|
isFocused: isFocusVisible,
|
62
|
-
|
76
|
+
isHovered: isHovered,
|
77
|
+
isPressed: isPressed || isPressedFromContext
|
63
78
|
}),
|
64
79
|
classNames = _useStatusClasses.classNames;
|
65
80
|
var ariaLabel = props['aria-label'];
|
@@ -70,12 +85,11 @@ var Button = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
70
85
|
"aria-label": ariaLabel,
|
71
86
|
className: classNames,
|
72
87
|
role: "button",
|
73
|
-
|
74
|
-
sx: isLoading && {
|
88
|
+
sx: isLoading ? {
|
75
89
|
display: 'flex',
|
76
90
|
justifyContent: 'center',
|
77
91
|
alignItems: 'center'
|
78
|
-
},
|
92
|
+
} : {},
|
79
93
|
variant: variant
|
80
94
|
}, others, mergeProps(_objectSpread(_objectSpread({}, buttonProps), {}, {
|
81
95
|
tabIndex: tabIndex
|
@@ -90,7 +104,6 @@ var Button = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
90
104
|
}
|
91
105
|
})));
|
92
106
|
});
|
93
|
-
Button.propTypes = buttonPropTypes;
|
94
107
|
Button.defaultProps = {
|
95
108
|
isDisabled: false,
|
96
109
|
variant: 'default'
|
@@ -17,12 +17,10 @@ export var base = _objectSpread({
|
|
17
17
|
minWidth: 'min-content',
|
18
18
|
padding: '10px 15px',
|
19
19
|
outline: 'none',
|
20
|
-
display: 'inline-flex',
|
21
20
|
alignItems: 'center',
|
22
21
|
justifyContent: 'center',
|
23
22
|
borderRadius: '2px',
|
24
23
|
flexShrink: 0,
|
25
|
-
wordBreak: 'inherit',
|
26
24
|
whiteSpace: 'nowrap'
|
27
25
|
}, textVariants.buttonLabel);
|
28
26
|
var defaultActive = {
|
@@ -9,33 +9,24 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
11
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
|
-
import
|
13
|
-
import {
|
14
|
-
import { booleanArg, funcArg } from '../../utils/docUtils/docArgTypes';
|
12
|
+
import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
|
13
|
+
import { booleanArg } from '../../utils/docUtils/docArgTypes';
|
15
14
|
import { onHoverArgTypes } from '../../utils/docUtils/hoverProps';
|
16
|
-
|
15
|
+
import { onPressArgTypes } from '../../utils/docUtils/pressAttributes';
|
17
16
|
// add designer approved variants for devs to use here
|
18
17
|
var variantOptions = ['critical', 'default', 'inline', 'inlinePrimary', 'link', 'primary'];
|
19
18
|
var descriptions = {
|
19
|
+
children: 'Button text.',
|
20
20
|
isDisabled: 'Whether the button is disabled.',
|
21
21
|
isLoading: 'Shows loader instead of children',
|
22
|
-
onHoverStart: 'Handler that is called when a hover interaction starts. (e: HoverEvent) => void',
|
23
|
-
onHoverEnd: 'Handler that is called when the hover state changes. (isHovering: boolean) => void',
|
24
|
-
onHoverChange: 'Handler that is called when the press is released over the target. (e: PressEvent) => void',
|
25
|
-
onPress: 'Handler that is called when the press is released over the target. (e: PressEvent) => void',
|
26
|
-
onPressChange: 'Handler that is called when the press state changes. (isPressed: boolean) => void',
|
27
|
-
onPressEnd: 'Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. (e: PressEvent) => void',
|
28
|
-
onPressStart: 'Handler that is called when a press interaction starts. (e: PressEvent) => void',
|
29
|
-
onPressUp: 'Handler that is called when a press is released over the target, regardless of whether it started on the target or not. (e: PressEvent) => void',
|
30
|
-
variant: 'The styling variation of the button.',
|
31
22
|
tabIndex: 'The focus variation of button',
|
32
|
-
|
23
|
+
variant: 'The styling variation of the button.'
|
33
24
|
};
|
34
|
-
export var buttonArgTypes = _objectSpread(_objectSpread({
|
25
|
+
export var buttonArgTypes = _objectSpread(_objectSpread(_objectSpread({
|
35
26
|
variant: {
|
27
|
+
options: variantOptions,
|
36
28
|
control: {
|
37
|
-
type: 'select'
|
38
|
-
options: variantOptions
|
29
|
+
type: 'select'
|
39
30
|
},
|
40
31
|
description: descriptions.variant
|
41
32
|
},
|
@@ -50,22 +41,6 @@ export var buttonArgTypes = _objectSpread(_objectSpread({
|
|
50
41
|
},
|
51
42
|
description: descriptions.children
|
52
43
|
},
|
53
|
-
onPress: _objectSpread({
|
54
|
-
description: descriptions.onPress
|
55
|
-
}, funcArg),
|
56
|
-
onPressStart: _objectSpread({
|
57
|
-
description: descriptions.onPressStart
|
58
|
-
}, funcArg),
|
59
|
-
onPressEnd: _objectSpread({
|
60
|
-
description: descriptions.onPressEnd
|
61
|
-
}, funcArg),
|
62
|
-
onPressChange: _objectSpread({
|
63
|
-
description: descriptions.onPressChange
|
64
|
-
}, funcArg),
|
65
|
-
onPressUp: _objectSpread({
|
66
|
-
description: descriptions.onPressUp
|
67
|
-
}, funcArg)
|
68
|
-
}, onHoverArgTypes), {}, {
|
69
44
|
isLoading: _objectSpread(_objectSpread({}, booleanArg), {}, {
|
70
45
|
description: descriptions.isLoading
|
71
46
|
}),
|
@@ -74,26 +49,5 @@ export var buttonArgTypes = _objectSpread(_objectSpread({
|
|
74
49
|
}),
|
75
50
|
tabIndex: {
|
76
51
|
description: descriptions.tabIndex
|
77
|
-
},
|
78
|
-
'aria-label': {
|
79
|
-
control: {
|
80
|
-
type: 'text'
|
81
|
-
},
|
82
|
-
description: ariaDescriptions.ariaLabel
|
83
52
|
}
|
84
|
-
});
|
85
|
-
export var buttonPropTypes = {
|
86
|
-
'aria-label': PropTypes.string,
|
87
|
-
isDisabled: PropTypes.bool,
|
88
|
-
isLoading: PropTypes.bool,
|
89
|
-
onHoverStart: PropTypes.func,
|
90
|
-
onHoverEnd: PropTypes.func,
|
91
|
-
onHoverChange: PropTypes.func,
|
92
|
-
onPress: PropTypes.func,
|
93
|
-
onPressStart: PropTypes.func,
|
94
|
-
onPressEnd: PropTypes.func,
|
95
|
-
onPressChange: PropTypes.func,
|
96
|
-
onPressUp: PropTypes.func,
|
97
|
-
variant: PropTypes.string,
|
98
|
-
tabIndex: PropTypes.number
|
99
|
-
};
|
53
|
+
}, onPressArgTypes), onHoverArgTypes), ariaAttributeBaseArgTypes);
|
package/lib/hooks/index.js
CHANGED
@@ -8,6 +8,7 @@ export { default as useDevelopmentWarning } from './useDevelopmentWarning';
|
|
8
8
|
export { default as useFallbackImage } from './useFallbackImage';
|
9
9
|
export { default as useField } from './useField';
|
10
10
|
export { default as useLabelHeight } from './useLabelHeight';
|
11
|
+
export { default as useLocalOrForwardRef } from './useLocalOrForwardRef';
|
11
12
|
export { default as useModalState } from './useModalState';
|
12
13
|
export { default as useMountTransition } from './useMountTransition';
|
13
14
|
export { default as useNavBarPress } from './useNavBarPress';
|
@@ -1,16 +1,6 @@
|
|
1
1
|
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
2
2
|
import { useEffect } from 'react';
|
3
3
|
var alreadyShown = new _Set();
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Provides a development-only console warning on component mount.
|
7
|
-
* @param {String} text - The deprecation warning text. It should describe what is being deprecated,
|
8
|
-
* when it is being deprecated (what lib version usually), and what to use instead.
|
9
|
-
* @param {object} options
|
10
|
-
* @param {boolean} options.isActive - whether warning should be shown
|
11
|
-
* @param {boolean} options.onlyOnce - if true then warning will be globally shown just once
|
12
|
-
* e.g. "\`MyField\` will be deprecated in Astro-UI 1.0.0, use \`MyOtherField\` instead."
|
13
|
-
*/
|
14
4
|
var useDeprecationWarning = function useDeprecationWarning() {
|
15
5
|
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
16
6
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useLocalOrForwardRef';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { useImperativeHandle, useRef } from 'react';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Accepts a forwardRef as a parameter and combines it with a
|
5
|
+
* local ref, incase the forwarded wasn't provided
|
6
|
+
*/
|
7
|
+
var useLocalOrForwardRef = function useLocalOrForwardRef(forwardRef) {
|
8
|
+
var localRef = useRef({});
|
9
|
+
useImperativeHandle(forwardRef, function () {
|
10
|
+
return localRef.current;
|
11
|
+
});
|
12
|
+
return localRef;
|
13
|
+
};
|
14
|
+
export default useLocalOrForwardRef;
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React, { forwardRef, useEffect, useRef } from 'react';
|
3
|
+
import { useFocusRing } from 'react-aria';
|
4
|
+
import { render, screen } from '@testing-library/react';
|
5
|
+
import { useStatusClasses } from '../index';
|
6
|
+
import useLocalOrForwardRef from './useLocalOrForwardRef';
|
7
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
|
+
var HAS_REF = 'hasRef';
|
9
|
+
var ForwardRefComponent = /*#__PURE__*/forwardRef(function (props, ref) {
|
10
|
+
var localOrForwardRef = useLocalOrForwardRef(ref);
|
11
|
+
var _useFocusRing = useFocusRing(),
|
12
|
+
isFocusVisible = _useFocusRing.isFocusVisible,
|
13
|
+
focusProps = _useFocusRing.focusProps;
|
14
|
+
var _useStatusClasses = useStatusClasses('className', {
|
15
|
+
isFocused: isFocusVisible
|
16
|
+
}),
|
17
|
+
classNames = _useStatusClasses.classNames;
|
18
|
+
return ___EmotionJSX("button", _extends({
|
19
|
+
className: classNames,
|
20
|
+
ref: localOrForwardRef,
|
21
|
+
type: "button"
|
22
|
+
}, focusProps, props), localOrForwardRef && HAS_REF);
|
23
|
+
});
|
24
|
+
var TestComponentWithRef = function TestComponentWithRef() {
|
25
|
+
var parentRef = useRef({});
|
26
|
+
useEffect(function () {
|
27
|
+
if (!parentRef.current) return;
|
28
|
+
parentRef.current.focus();
|
29
|
+
}, []);
|
30
|
+
return ___EmotionJSX(ForwardRefComponent, {
|
31
|
+
ref: parentRef
|
32
|
+
});
|
33
|
+
};
|
34
|
+
var getComponentWithRef = function getComponentWithRef() {
|
35
|
+
return render(___EmotionJSX(TestComponentWithRef, null));
|
36
|
+
};
|
37
|
+
var TestComponentWithoutRef = function TestComponentWithoutRef() {
|
38
|
+
return ___EmotionJSX(ForwardRefComponent, null);
|
39
|
+
};
|
40
|
+
var getComponentWithoutRef = function getComponentWithoutRef() {
|
41
|
+
return render(___EmotionJSX(TestComponentWithoutRef, null));
|
42
|
+
};
|
43
|
+
describe('localOrForwardRef', function () {
|
44
|
+
describe('When the test component has been provided a forward ref', function () {
|
45
|
+
test('it has a valid ref', function () {
|
46
|
+
getComponentWithRef();
|
47
|
+
screen.getByText(HAS_REF);
|
48
|
+
});
|
49
|
+
test('the test component can access the refs properties', function () {
|
50
|
+
getComponentWithRef();
|
51
|
+
var button = screen.getByRole('button');
|
52
|
+
expect(button).toHaveClass('is-focused');
|
53
|
+
});
|
54
|
+
});
|
55
|
+
describe('When the test component has not been provided a forward ref', function () {
|
56
|
+
test('it has a valid ref', function () {
|
57
|
+
getComponentWithoutRef();
|
58
|
+
screen.getByText(HAS_REF);
|
59
|
+
});
|
60
|
+
});
|
61
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/lib/types/index.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
|
+
import { funcArg } from './docArgTypes';
|
13
|
+
var descriptions = {
|
14
|
+
onPress: 'Handler that is called when the press is released over the target. (e: PressEvent) => void',
|
15
|
+
onPressChange: 'Handler that is called when the press state changes. (isPressed: boolean) => void',
|
16
|
+
onPressEnd: 'Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. (e: PressEvent) => void',
|
17
|
+
onPressStart: 'Handler that is called when a press interaction starts. (e: PressEvent) => void',
|
18
|
+
onPressUp: 'Handler that is called when a press is released over the target, regardless of whether it started on the target or not. (e: PressEvent) => void'
|
19
|
+
};
|
20
|
+
var baseDocSettings = _objectSpread(_objectSpread({}, funcArg), {}, {
|
21
|
+
table: {
|
22
|
+
category: 'Press Handlers'
|
23
|
+
}
|
24
|
+
});
|
25
|
+
export var onPressArgTypes = {
|
26
|
+
onPress: _objectSpread({
|
27
|
+
description: descriptions.onPress
|
28
|
+
}, baseDocSettings),
|
29
|
+
onPressStart: _objectSpread({
|
30
|
+
description: descriptions.onPressStart
|
31
|
+
}, baseDocSettings),
|
32
|
+
onPressEnd: _objectSpread({
|
33
|
+
description: descriptions.onPressEnd
|
34
|
+
}, baseDocSettings),
|
35
|
+
onPressChange: _objectSpread({
|
36
|
+
description: descriptions.onPressChange
|
37
|
+
}, baseDocSettings),
|
38
|
+
onPressUp: _objectSpread({
|
39
|
+
description: descriptions.onPressUp
|
40
|
+
}, baseDocSettings)
|
41
|
+
};
|