@react-native-aria/button 0.2.2 → 0.2.5-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/lib/commonjs/useButton.js +5 -8
- package/lib/commonjs/useButton.js.map +1 -1
- package/lib/commonjs/useToggleButton.js +3 -5
- package/lib/commonjs/useToggleButton.js.map +1 -1
- package/lib/commonjs/useToggleButton.web.js +3 -6
- package/lib/commonjs/useToggleButton.web.js.map +1 -1
- package/lib/module/useButton.js +7 -10
- package/lib/module/useButton.js.map +1 -1
- package/lib/module/useToggleButton.js +5 -7
- package/lib/module/useToggleButton.js.map +1 -1
- package/lib/module/useToggleButton.web.js +3 -6
- package/lib/module/useToggleButton.web.js.map +1 -1
- package/lib/typescript/useButton.d.ts +4 -4
- package/lib/typescript/useToggleButton.d.ts +5 -6
- package/lib/typescript/useToggleButton.web.d.ts +2 -2
- package/package.json +3 -3
- package/src/useButton.ts +8 -14
- package/src/useToggleButton.ts +11 -18
- package/src/useToggleButton.web.ts +6 -14
- package/.DS_Store +0 -0
@@ -9,7 +9,7 @@ var _interactions = require("@react-native-aria/interactions");
|
|
9
9
|
|
10
10
|
var _utils = require("@react-aria/utils");
|
11
11
|
|
12
|
-
function useButton(props
|
12
|
+
function useButton(props) {
|
13
13
|
let {
|
14
14
|
isDisabled,
|
15
15
|
onPress,
|
@@ -26,15 +26,12 @@ function useButton(props, ref) {
|
|
26
26
|
onPressEnd,
|
27
27
|
onPressChange,
|
28
28
|
onPress,
|
29
|
-
isDisabled
|
30
|
-
ref
|
29
|
+
isDisabled
|
31
30
|
});
|
32
31
|
const mergedProps = (0, _utils.mergeProps)(pressProps, rest, {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
accessibilityRole: "button",
|
37
|
-
disabled: isDisabled
|
32
|
+
'aria-disabled': isDisabled,
|
33
|
+
'role': 'button',
|
34
|
+
'disabled': isDisabled
|
38
35
|
});
|
39
36
|
return {
|
40
37
|
isPressed,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useButton.ts"],"names":["useButton","props","
|
1
|
+
{"version":3,"sources":["useButton.ts"],"names":["useButton","props","isDisabled","onPress","onPressStart","onPressEnd","onPressChange","rest","pressProps","isPressed","mergedProps","buttonProps"],"mappings":";;;;;;;AACA;;AAEA;;AAkBO,SAASA,SAAT,CAAmBC,KAAnB,EAAyD;AAC9D,MAAI;AACFC,IAAAA,UADE;AAEFC,IAAAA,OAFE;AAGFC,IAAAA,YAHE;AAIFC,IAAAA,UAJE;AAKFC,IAAAA,aALE;AAMF,OAAGC;AAND,MAOAN,KAPJ;AASA,MAAI;AAAEO,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA4B,4BAAS;AACvCL,IAAAA,YADuC;AAEvCC,IAAAA,UAFuC;AAGvCC,IAAAA,aAHuC;AAIvCH,IAAAA,OAJuC;AAKvCD,IAAAA;AALuC,GAAT,CAAhC;AAQA,QAAMQ,WAAW,GAAG,uBAAWF,UAAX,EAAuBD,IAAvB,EAA6B;AAC/C,qBAAiBL,UAD8B;AAE/C,YAAQ,QAFuC;AAG/C,gBAAYA;AAHmC,GAA7B,CAApB;AAMA,SAAO;AACLO,IAAAA,SADK;AAELE,IAAAA,WAAW,EAAED;AAFR,GAAP;AAID","sourcesContent":["import { ReactNode } from 'react';\nimport { PressEvents, usePress } from '@react-native-aria/interactions';\nimport { AccessibilityProps, PressableProps } from 'react-native';\nimport { mergeProps } from '@react-aria/utils';\n\ninterface ButtonProps extends PressEvents {\n /** Whether the button is disabled. */\n isDisabled?: boolean;\n /** The content to display in the button. */\n children?: ReactNode;\n}\n\nexport interface RNAriaButtonProps extends AccessibilityProps, ButtonProps {}\n\nexport interface ButtonAria {\n /** Props for the button element. */\n buttonProps: PressableProps;\n /** Whether the button is currently pressed. */\n isPressed: boolean;\n}\n\nexport function useButton(props: RNAriaButtonProps): ButtonAria {\n let {\n isDisabled,\n onPress,\n onPressStart,\n onPressEnd,\n onPressChange,\n ...rest\n } = props;\n\n let { pressProps, isPressed } = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n isDisabled,\n });\n\n const mergedProps = mergeProps(pressProps, rest, {\n 'aria-disabled': isDisabled,\n 'role': 'button',\n 'disabled': isDisabled,\n });\n\n return {\n isPressed,\n buttonProps: mergedProps,\n };\n}\n"]}
|
@@ -9,7 +9,7 @@ var _useButton = require("./useButton");
|
|
9
9
|
|
10
10
|
var _utils = require("@react-aria/utils");
|
11
11
|
|
12
|
-
function useToggleButton(props, state
|
12
|
+
function useToggleButton(props, state) {
|
13
13
|
const {
|
14
14
|
isSelected
|
15
15
|
} = state;
|
@@ -18,13 +18,11 @@ function useToggleButton(props, state, ref) {
|
|
18
18
|
buttonProps
|
19
19
|
} = (0, _useButton.useButton)({ ...props,
|
20
20
|
onPress: (0, _utils.chain)(state.toggle, props.onPress)
|
21
|
-
}
|
21
|
+
});
|
22
22
|
return {
|
23
23
|
isPressed,
|
24
24
|
buttonProps: (0, _utils.mergeProps)(buttonProps, {
|
25
|
-
|
26
|
-
selected: isSelected
|
27
|
-
}
|
25
|
+
'aria-selected': isSelected
|
28
26
|
})
|
29
27
|
};
|
30
28
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useToggleButton.ts"],"names":["useToggleButton","props","state","
|
1
|
+
{"version":3,"sources":["useToggleButton.ts"],"names":["useToggleButton","props","state","isSelected","isPressed","buttonProps","onPress","toggle"],"mappings":";;;;;;;AAAA;;AAEA;;AAkBO,SAASA,eAAT,CACLC,KADK,EAELC,KAFK,EAGO;AACZ,QAAM;AAAEC,IAAAA;AAAF,MAAiBD,KAAvB;AACA,QAAM;AAAEE,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6B,0BAAU,EAC3C,GAAGJ,KADwC;AAE3CK,IAAAA,OAAO,EAAE,kBAAMJ,KAAK,CAACK,MAAZ,EAAoBN,KAAK,CAACK,OAA1B;AAFkC,GAAV,CAAnC;AAKA,SAAO;AACLF,IAAAA,SADK;AAELC,IAAAA,WAAW,EAAE,uBAAWA,WAAX,EAAwB;AACnC,uBAAiBF;AADkB,KAAxB;AAFR,GAAP;AAMD","sourcesContent":["import { ButtonAria, useButton } from './useButton';\nimport type { ToggleState } from '@react-stately/toggle';\nimport { chain, mergeProps } from '@react-aria/utils';\nimport type { PressEvents } from '@react-native-aria/interactions';\nimport type { PressableProps } from 'react-native';\n\nexport type AriaButtonProps = PressableProps &\n PressEvents & {\n isDisabled: boolean;\n };\n\nexport interface AriaToggleButtonProps extends AriaButtonProps {\n /** Whether the element should be selected (controlled). */\n isSelected?: boolean;\n /** Whether the element should be selected (uncontrolled). */\n defaultSelected?: boolean;\n /** Handler that is called when the element's selection state changes. */\n onChange?: (isSelected: boolean) => void;\n}\n\nexport function useToggleButton(\n props: AriaToggleButtonProps,\n state: ToggleState\n): ButtonAria {\n const { isSelected } = state;\n const { isPressed, buttonProps } = useButton({\n ...props,\n onPress: chain(state.toggle, props.onPress),\n });\n\n return {\n isPressed,\n buttonProps: mergeProps(buttonProps, {\n 'aria-selected': isSelected,\n }),\n };\n}\n"]}
|
@@ -25,7 +25,7 @@ var _utils = require("@react-aria/utils");
|
|
25
25
|
* Provides the behavior and accessibility implementation for a toggle button component.
|
26
26
|
* ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.
|
27
27
|
*/
|
28
|
-
function useToggleButton(props, state
|
28
|
+
function useToggleButton(props, state) {
|
29
29
|
/* eslint-enable no-redeclare */
|
30
30
|
const {
|
31
31
|
isSelected
|
@@ -35,14 +35,11 @@ function useToggleButton(props, state, ref) {
|
|
35
35
|
buttonProps
|
36
36
|
} = (0, _useButton.useButton)({ ...props,
|
37
37
|
onPress: (0, _utils.chain)(state.toggle, props.onPress)
|
38
|
-
}
|
38
|
+
});
|
39
39
|
return {
|
40
40
|
isPressed,
|
41
41
|
buttonProps: (0, _utils.mergeProps)(buttonProps, {
|
42
|
-
|
43
|
-
'aria-pressed': isSelected,
|
44
|
-
// For v0.15+
|
45
|
-
accessibilityPressed: isSelected
|
42
|
+
'aria-pressed': isSelected
|
46
43
|
})
|
47
44
|
};
|
48
45
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useToggleButton.web.ts"],"names":["useToggleButton","props","state","
|
1
|
+
{"version":3,"sources":["useToggleButton.web.ts"],"names":["useToggleButton","props","state","isSelected","isPressed","buttonProps","onPress","toggle"],"mappings":";;;;;;;AAcA;;AACA;;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACO,SAASA,eAAT,CACLC,KADK,EAELC,KAFK,EAGA;AACL;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAiBD,KAAvB;AACA,QAAM;AAAEE,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6B,0BAAU,EAC3C,GAAGJ,KADwC;AAE3CK,IAAAA,OAAO,EAAE,kBAAMJ,KAAK,CAACK,MAAZ,EAAoBN,KAAK,CAACK,OAA1B;AAFkC,GAAV,CAAnC;AAKA,SAAO;AACLF,IAAAA,SADK;AAELC,IAAAA,WAAW,EAAE,uBAAWA,WAAX,EAAwB;AACnC,sBAAgBF;AADmB,KAAxB;AAFR,GAAP;AAMD","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { ElementType } from 'react';\nimport { AriaToggleButtonProps } from '@react-types/button';\nimport { useButton } from './useButton';\nimport { chain } from '@react-aria/utils';\nimport { mergeProps } from '@react-aria/utils';\nimport { ToggleState } from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a toggle button component.\n * ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.\n */\nexport function useToggleButton(\n props: AriaToggleButtonProps<ElementType>,\n state: ToggleState\n): any {\n /* eslint-enable no-redeclare */\n const { isSelected } = state;\n const { isPressed, buttonProps } = useButton({\n ...props,\n onPress: chain(state.toggle, props.onPress),\n });\n\n return {\n isPressed,\n buttonProps: mergeProps(buttonProps, {\n 'aria-pressed': isSelected,\n }),\n };\n}\n"]}
|
package/lib/module/useButton.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { usePress } from
|
2
|
-
import { mergeProps } from
|
3
|
-
export function useButton(props
|
1
|
+
import { usePress } from '@react-native-aria/interactions';
|
2
|
+
import { mergeProps } from '@react-aria/utils';
|
3
|
+
export function useButton(props) {
|
4
4
|
let {
|
5
5
|
isDisabled,
|
6
6
|
onPress,
|
@@ -17,15 +17,12 @@ export function useButton(props, ref) {
|
|
17
17
|
onPressEnd,
|
18
18
|
onPressChange,
|
19
19
|
onPress,
|
20
|
-
isDisabled
|
21
|
-
ref
|
20
|
+
isDisabled
|
22
21
|
});
|
23
22
|
const mergedProps = mergeProps(pressProps, rest, {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
accessibilityRole: "button",
|
28
|
-
disabled: isDisabled
|
23
|
+
'aria-disabled': isDisabled,
|
24
|
+
'role': 'button',
|
25
|
+
'disabled': isDisabled
|
29
26
|
});
|
30
27
|
return {
|
31
28
|
isPressed,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useButton.ts"],"names":["usePress","mergeProps","useButton","props","
|
1
|
+
{"version":3,"sources":["useButton.ts"],"names":["usePress","mergeProps","useButton","props","isDisabled","onPress","onPressStart","onPressEnd","onPressChange","rest","pressProps","isPressed","mergedProps","buttonProps"],"mappings":"AACA,SAAsBA,QAAtB,QAAsC,iCAAtC;AAEA,SAASC,UAAT,QAA2B,mBAA3B;AAkBA,OAAO,SAASC,SAAT,CAAmBC,KAAnB,EAAyD;AAC9D,MAAI;AACFC,IAAAA,UADE;AAEFC,IAAAA,OAFE;AAGFC,IAAAA,YAHE;AAIFC,IAAAA,UAJE;AAKFC,IAAAA,aALE;AAMF,OAAGC;AAND,MAOAN,KAPJ;AASA,MAAI;AAAEO,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA4BX,QAAQ,CAAC;AACvCM,IAAAA,YADuC;AAEvCC,IAAAA,UAFuC;AAGvCC,IAAAA,aAHuC;AAIvCH,IAAAA,OAJuC;AAKvCD,IAAAA;AALuC,GAAD,CAAxC;AAQA,QAAMQ,WAAW,GAAGX,UAAU,CAACS,UAAD,EAAaD,IAAb,EAAmB;AAC/C,qBAAiBL,UAD8B;AAE/C,YAAQ,QAFuC;AAG/C,gBAAYA;AAHmC,GAAnB,CAA9B;AAMA,SAAO;AACLO,IAAAA,SADK;AAELE,IAAAA,WAAW,EAAED;AAFR,GAAP;AAID","sourcesContent":["import { ReactNode } from 'react';\nimport { PressEvents, usePress } from '@react-native-aria/interactions';\nimport { AccessibilityProps, PressableProps } from 'react-native';\nimport { mergeProps } from '@react-aria/utils';\n\ninterface ButtonProps extends PressEvents {\n /** Whether the button is disabled. */\n isDisabled?: boolean;\n /** The content to display in the button. */\n children?: ReactNode;\n}\n\nexport interface RNAriaButtonProps extends AccessibilityProps, ButtonProps {}\n\nexport interface ButtonAria {\n /** Props for the button element. */\n buttonProps: PressableProps;\n /** Whether the button is currently pressed. */\n isPressed: boolean;\n}\n\nexport function useButton(props: RNAriaButtonProps): ButtonAria {\n let {\n isDisabled,\n onPress,\n onPressStart,\n onPressEnd,\n onPressChange,\n ...rest\n } = props;\n\n let { pressProps, isPressed } = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n isDisabled,\n });\n\n const mergedProps = mergeProps(pressProps, rest, {\n 'aria-disabled': isDisabled,\n 'role': 'button',\n 'disabled': isDisabled,\n });\n\n return {\n isPressed,\n buttonProps: mergedProps,\n };\n}\n"]}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { useButton } from
|
2
|
-
import { chain, mergeProps } from
|
3
|
-
export function useToggleButton(props, state
|
1
|
+
import { useButton } from './useButton';
|
2
|
+
import { chain, mergeProps } from '@react-aria/utils';
|
3
|
+
export function useToggleButton(props, state) {
|
4
4
|
const {
|
5
5
|
isSelected
|
6
6
|
} = state;
|
@@ -9,13 +9,11 @@ export function useToggleButton(props, state, ref) {
|
|
9
9
|
buttonProps
|
10
10
|
} = useButton({ ...props,
|
11
11
|
onPress: chain(state.toggle, props.onPress)
|
12
|
-
}
|
12
|
+
});
|
13
13
|
return {
|
14
14
|
isPressed,
|
15
15
|
buttonProps: mergeProps(buttonProps, {
|
16
|
-
|
17
|
-
selected: isSelected
|
18
|
-
}
|
16
|
+
'aria-selected': isSelected
|
19
17
|
})
|
20
18
|
};
|
21
19
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useToggleButton.ts"],"names":["useButton","chain","mergeProps","useToggleButton","props","state","
|
1
|
+
{"version":3,"sources":["useToggleButton.ts"],"names":["useButton","chain","mergeProps","useToggleButton","props","state","isSelected","isPressed","buttonProps","onPress","toggle"],"mappings":"AAAA,SAAqBA,SAArB,QAAsC,aAAtC;AAEA,SAASC,KAAT,EAAgBC,UAAhB,QAAkC,mBAAlC;AAkBA,OAAO,SAASC,eAAT,CACLC,KADK,EAELC,KAFK,EAGO;AACZ,QAAM;AAAEC,IAAAA;AAAF,MAAiBD,KAAvB;AACA,QAAM;AAAEE,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAS,CAAC,EAC3C,GAAGI,KADwC;AAE3CK,IAAAA,OAAO,EAAER,KAAK,CAACI,KAAK,CAACK,MAAP,EAAeN,KAAK,CAACK,OAArB;AAF6B,GAAD,CAA5C;AAKA,SAAO;AACLF,IAAAA,SADK;AAELC,IAAAA,WAAW,EAAEN,UAAU,CAACM,WAAD,EAAc;AACnC,uBAAiBF;AADkB,KAAd;AAFlB,GAAP;AAMD","sourcesContent":["import { ButtonAria, useButton } from './useButton';\nimport type { ToggleState } from '@react-stately/toggle';\nimport { chain, mergeProps } from '@react-aria/utils';\nimport type { PressEvents } from '@react-native-aria/interactions';\nimport type { PressableProps } from 'react-native';\n\nexport type AriaButtonProps = PressableProps &\n PressEvents & {\n isDisabled: boolean;\n };\n\nexport interface AriaToggleButtonProps extends AriaButtonProps {\n /** Whether the element should be selected (controlled). */\n isSelected?: boolean;\n /** Whether the element should be selected (uncontrolled). */\n defaultSelected?: boolean;\n /** Handler that is called when the element's selection state changes. */\n onChange?: (isSelected: boolean) => void;\n}\n\nexport function useToggleButton(\n props: AriaToggleButtonProps,\n state: ToggleState\n): ButtonAria {\n const { isSelected } = state;\n const { isPressed, buttonProps } = useButton({\n ...props,\n onPress: chain(state.toggle, props.onPress),\n });\n\n return {\n isPressed,\n buttonProps: mergeProps(buttonProps, {\n 'aria-selected': isSelected,\n }),\n };\n}\n"]}
|
@@ -17,7 +17,7 @@ import { mergeProps } from '@react-aria/utils';
|
|
17
17
|
* Provides the behavior and accessibility implementation for a toggle button component.
|
18
18
|
* ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.
|
19
19
|
*/
|
20
|
-
export function useToggleButton(props, state
|
20
|
+
export function useToggleButton(props, state) {
|
21
21
|
/* eslint-enable no-redeclare */
|
22
22
|
const {
|
23
23
|
isSelected
|
@@ -27,14 +27,11 @@ export function useToggleButton(props, state, ref) {
|
|
27
27
|
buttonProps
|
28
28
|
} = useButton({ ...props,
|
29
29
|
onPress: chain(state.toggle, props.onPress)
|
30
|
-
}
|
30
|
+
});
|
31
31
|
return {
|
32
32
|
isPressed,
|
33
33
|
buttonProps: mergeProps(buttonProps, {
|
34
|
-
|
35
|
-
'aria-pressed': isSelected,
|
36
|
-
// For v0.15+
|
37
|
-
accessibilityPressed: isSelected
|
34
|
+
'aria-pressed': isSelected
|
38
35
|
})
|
39
36
|
};
|
40
37
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useToggleButton.web.ts"],"names":["useButton","chain","mergeProps","useToggleButton","props","state","
|
1
|
+
{"version":3,"sources":["useToggleButton.web.ts"],"names":["useButton","chain","mergeProps","useToggleButton","props","state","isSelected","isPressed","buttonProps","onPress","toggle"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,SAASA,SAAT,QAA0B,aAA1B;AACA,SAASC,KAAT,QAAsB,mBAAtB;AACA,SAASC,UAAT,QAA2B,mBAA3B;;AAGA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAT,CACLC,KADK,EAELC,KAFK,EAGA;AACL;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAiBD,KAAvB;AACA,QAAM;AAAEE,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAS,CAAC,EAC3C,GAAGI,KADwC;AAE3CK,IAAAA,OAAO,EAAER,KAAK,CAACI,KAAK,CAACK,MAAP,EAAeN,KAAK,CAACK,OAArB;AAF6B,GAAD,CAA5C;AAKA,SAAO;AACLF,IAAAA,SADK;AAELC,IAAAA,WAAW,EAAEN,UAAU,CAACM,WAAD,EAAc;AACnC,sBAAgBF;AADmB,KAAd;AAFlB,GAAP;AAMD","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { ElementType } from 'react';\nimport { AriaToggleButtonProps } from '@react-types/button';\nimport { useButton } from './useButton';\nimport { chain } from '@react-aria/utils';\nimport { mergeProps } from '@react-aria/utils';\nimport { ToggleState } from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a toggle button component.\n * ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.\n */\nexport function useToggleButton(\n props: AriaToggleButtonProps<ElementType>,\n state: ToggleState\n): any {\n /* eslint-enable no-redeclare */\n const { isSelected } = state;\n const { isPressed, buttonProps } = useButton({\n ...props,\n onPress: chain(state.toggle, props.onPress),\n });\n\n return {\n isPressed,\n buttonProps: mergeProps(buttonProps, {\n 'aria-pressed': isSelected,\n }),\n };\n}\n"]}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { ReactNode
|
2
|
-
import { PressEvents } from
|
3
|
-
import { AccessibilityProps, PressableProps } from
|
1
|
+
import { ReactNode } from 'react';
|
2
|
+
import { PressEvents } from '@react-native-aria/interactions';
|
3
|
+
import { AccessibilityProps, PressableProps } from 'react-native';
|
4
4
|
interface ButtonProps extends PressEvents {
|
5
5
|
/** Whether the button is disabled. */
|
6
6
|
isDisabled?: boolean;
|
@@ -15,5 +15,5 @@ export interface ButtonAria {
|
|
15
15
|
/** Whether the button is currently pressed. */
|
16
16
|
isPressed: boolean;
|
17
17
|
}
|
18
|
-
export declare function useButton(props: RNAriaButtonProps
|
18
|
+
export declare function useButton(props: RNAriaButtonProps): ButtonAria;
|
19
19
|
export {};
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import { ButtonAria } from
|
2
|
-
import type { ToggleState } from
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type { PressableProps } from "react-native";
|
1
|
+
import { ButtonAria } from './useButton';
|
2
|
+
import type { ToggleState } from '@react-stately/toggle';
|
3
|
+
import type { PressEvents } from '@react-native-aria/interactions';
|
4
|
+
import type { PressableProps } from 'react-native';
|
6
5
|
export declare type AriaButtonProps = PressableProps & PressEvents & {
|
7
6
|
isDisabled: boolean;
|
8
7
|
};
|
@@ -14,4 +13,4 @@ export interface AriaToggleButtonProps extends AriaButtonProps {
|
|
14
13
|
/** Handler that is called when the element's selection state changes. */
|
15
14
|
onChange?: (isSelected: boolean) => void;
|
16
15
|
}
|
17
|
-
export declare function useToggleButton(props: AriaToggleButtonProps, state: ToggleState
|
16
|
+
export declare function useToggleButton(props: AriaToggleButtonProps, state: ToggleState): ButtonAria;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { ElementType
|
1
|
+
import { ElementType } from 'react';
|
2
2
|
import { AriaToggleButtonProps } from '@react-types/button';
|
3
3
|
import { ToggleState } from '@react-stately/toggle';
|
4
4
|
/**
|
5
5
|
* Provides the behavior and accessibility implementation for a toggle button component.
|
6
6
|
* ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.
|
7
7
|
*/
|
8
|
-
export declare function useToggleButton(props: AriaToggleButtonProps<ElementType>, state: ToggleState
|
8
|
+
export declare function useToggleButton(props: AriaToggleButtonProps<ElementType>, state: ToggleState): any;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-native-aria/button",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.5-alpha.0",
|
4
4
|
"description": "mono repo setup with bob",
|
5
5
|
"main": "lib/commonjs/index",
|
6
6
|
"module": "lib/module/index",
|
@@ -47,8 +47,8 @@
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|
48
48
|
},
|
49
49
|
"dependencies": {
|
50
|
-
"@react-aria/utils": "^3.
|
51
|
-
"@react-native-aria/interactions": "^0.2.
|
50
|
+
"@react-aria/utils": "^3.6.0",
|
51
|
+
"@react-native-aria/interactions": "^0.2.3",
|
52
52
|
"@react-stately/toggle": "^3.2.1",
|
53
53
|
"@react-types/checkbox": "^3.2.1"
|
54
54
|
},
|
package/src/useButton.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { ReactNode
|
2
|
-
import { PressEvents, usePress } from
|
3
|
-
import { AccessibilityProps, PressableProps } from
|
4
|
-
import { mergeProps } from
|
1
|
+
import { ReactNode } from 'react';
|
2
|
+
import { PressEvents, usePress } from '@react-native-aria/interactions';
|
3
|
+
import { AccessibilityProps, PressableProps } from 'react-native';
|
4
|
+
import { mergeProps } from '@react-aria/utils';
|
5
5
|
|
6
6
|
interface ButtonProps extends PressEvents {
|
7
7
|
/** Whether the button is disabled. */
|
@@ -19,10 +19,7 @@ export interface ButtonAria {
|
|
19
19
|
isPressed: boolean;
|
20
20
|
}
|
21
21
|
|
22
|
-
export function useButton(
|
23
|
-
props: RNAriaButtonProps,
|
24
|
-
ref: RefObject<any>
|
25
|
-
): ButtonAria {
|
22
|
+
export function useButton(props: RNAriaButtonProps): ButtonAria {
|
26
23
|
let {
|
27
24
|
isDisabled,
|
28
25
|
onPress,
|
@@ -38,15 +35,12 @@ export function useButton(
|
|
38
35
|
onPressChange,
|
39
36
|
onPress,
|
40
37
|
isDisabled,
|
41
|
-
ref,
|
42
38
|
});
|
43
39
|
|
44
40
|
const mergedProps = mergeProps(pressProps, rest, {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
accessibilityRole: "button",
|
49
|
-
disabled: isDisabled,
|
41
|
+
'aria-disabled': isDisabled,
|
42
|
+
'role': 'button',
|
43
|
+
'disabled': isDisabled,
|
50
44
|
});
|
51
45
|
|
52
46
|
return {
|
package/src/useToggleButton.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
import { ButtonAria, useButton } from
|
2
|
-
import type { ToggleState } from
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
import type {
|
6
|
-
import type { PressableProps } from "react-native";
|
1
|
+
import { ButtonAria, useButton } from './useButton';
|
2
|
+
import type { ToggleState } from '@react-stately/toggle';
|
3
|
+
import { chain, mergeProps } from '@react-aria/utils';
|
4
|
+
import type { PressEvents } from '@react-native-aria/interactions';
|
5
|
+
import type { PressableProps } from 'react-native';
|
7
6
|
|
8
7
|
export type AriaButtonProps = PressableProps &
|
9
8
|
PressEvents & {
|
@@ -21,24 +20,18 @@ export interface AriaToggleButtonProps extends AriaButtonProps {
|
|
21
20
|
|
22
21
|
export function useToggleButton(
|
23
22
|
props: AriaToggleButtonProps,
|
24
|
-
state: ToggleState
|
25
|
-
ref: RefObject<any>
|
23
|
+
state: ToggleState
|
26
24
|
): ButtonAria {
|
27
25
|
const { isSelected } = state;
|
28
|
-
const { isPressed, buttonProps } = useButton(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
},
|
33
|
-
ref
|
34
|
-
);
|
26
|
+
const { isPressed, buttonProps } = useButton({
|
27
|
+
...props,
|
28
|
+
onPress: chain(state.toggle, props.onPress),
|
29
|
+
});
|
35
30
|
|
36
31
|
return {
|
37
32
|
isPressed,
|
38
33
|
buttonProps: mergeProps(buttonProps, {
|
39
|
-
|
40
|
-
selected: isSelected,
|
41
|
-
},
|
34
|
+
'aria-selected': isSelected,
|
42
35
|
}),
|
43
36
|
};
|
44
37
|
}
|
@@ -10,7 +10,7 @@
|
|
10
10
|
* governing permissions and limitations under the License.
|
11
11
|
*/
|
12
12
|
|
13
|
-
import { ElementType
|
13
|
+
import { ElementType } from 'react';
|
14
14
|
import { AriaToggleButtonProps } from '@react-types/button';
|
15
15
|
import { useButton } from './useButton';
|
16
16
|
import { chain } from '@react-aria/utils';
|
@@ -23,27 +23,19 @@ import { ToggleState } from '@react-stately/toggle';
|
|
23
23
|
*/
|
24
24
|
export function useToggleButton(
|
25
25
|
props: AriaToggleButtonProps<ElementType>,
|
26
|
-
state: ToggleState
|
27
|
-
ref: RefObject<any>
|
26
|
+
state: ToggleState
|
28
27
|
): any {
|
29
28
|
/* eslint-enable no-redeclare */
|
30
29
|
const { isSelected } = state;
|
31
|
-
const { isPressed, buttonProps } = useButton(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
},
|
36
|
-
ref
|
37
|
-
);
|
30
|
+
const { isPressed, buttonProps } = useButton({
|
31
|
+
...props,
|
32
|
+
onPress: chain(state.toggle, props.onPress),
|
33
|
+
});
|
38
34
|
|
39
35
|
return {
|
40
36
|
isPressed,
|
41
37
|
buttonProps: mergeProps(buttonProps, {
|
42
|
-
// For v0.14+
|
43
38
|
'aria-pressed': isSelected,
|
44
|
-
|
45
|
-
// For v0.15+
|
46
|
-
accessibilityPressed: isSelected,
|
47
39
|
}),
|
48
40
|
};
|
49
41
|
}
|
package/.DS_Store
DELETED
Binary file
|