react-aria-components 3.0.0-nightly-426bff12a-241106 → 3.0.0-nightly-09ccc53e7-241107

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-aria-components",
3
- "version": "3.0.0-nightly-426bff12a-241106",
3
+ "version": "3.0.0-nightly-09ccc53e7-241107",
4
4
  "description": "A library of styleable components built using React Aria",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -37,38 +37,38 @@
37
37
  "url": "https://github.com/adobe/react-spectrum"
38
38
  },
39
39
  "dependencies": {
40
- "@internationalized/date": "^3.0.0-nightly-426bff12a-241106",
41
- "@internationalized/string": "^3.0.0-nightly-426bff12a-241106",
42
- "@react-aria/accordion": "3.0.0-nightly-426bff12a-241106",
43
- "@react-aria/collections": "3.0.0-nightly-426bff12a-241106",
44
- "@react-aria/color": "^3.0.0-nightly-426bff12a-241106",
45
- "@react-aria/disclosure": "3.0.0-nightly-426bff12a-241106",
46
- "@react-aria/dnd": "^3.0.0-nightly-426bff12a-241106",
47
- "@react-aria/focus": "^3.0.0-nightly-426bff12a-241106",
48
- "@react-aria/interactions": "^3.0.0-nightly-426bff12a-241106",
49
- "@react-aria/live-announcer": "^3.0.0-nightly-426bff12a-241106",
50
- "@react-aria/menu": "^3.0.0-nightly-426bff12a-241106",
51
- "@react-aria/toolbar": "3.0.0-nightly-426bff12a-241106",
52
- "@react-aria/tree": "3.0.0-nightly-426bff12a-241106",
53
- "@react-aria/utils": "^3.0.0-nightly-426bff12a-241106",
54
- "@react-aria/virtualizer": "^3.0.0-nightly-426bff12a-241106",
55
- "@react-stately/color": "^3.0.0-nightly-426bff12a-241106",
56
- "@react-stately/disclosure": "3.0.0-nightly-426bff12a-241106",
57
- "@react-stately/layout": "^3.0.0-nightly-426bff12a-241106",
58
- "@react-stately/menu": "^3.0.0-nightly-426bff12a-241106",
59
- "@react-stately/selection": "^3.0.0-nightly-426bff12a-241106",
60
- "@react-stately/table": "^3.0.0-nightly-426bff12a-241106",
61
- "@react-stately/utils": "^3.0.0-nightly-426bff12a-241106",
62
- "@react-stately/virtualizer": "^3.0.0-nightly-426bff12a-241106",
63
- "@react-types/color": "^3.0.0-nightly-426bff12a-241106",
64
- "@react-types/form": "^3.0.0-nightly-426bff12a-241106",
65
- "@react-types/grid": "^3.0.0-nightly-426bff12a-241106",
66
- "@react-types/shared": "^3.0.0-nightly-426bff12a-241106",
67
- "@react-types/table": "^3.0.0-nightly-426bff12a-241106",
40
+ "@internationalized/date": "^3.0.0-nightly-09ccc53e7-241107",
41
+ "@internationalized/string": "^3.0.0-nightly-09ccc53e7-241107",
42
+ "@react-aria/accordion": "3.0.0-nightly-09ccc53e7-241107",
43
+ "@react-aria/collections": "3.0.0-nightly-09ccc53e7-241107",
44
+ "@react-aria/color": "^3.0.0-nightly-09ccc53e7-241107",
45
+ "@react-aria/disclosure": "3.0.0-nightly-09ccc53e7-241107",
46
+ "@react-aria/dnd": "^3.0.0-nightly-09ccc53e7-241107",
47
+ "@react-aria/focus": "^3.0.0-nightly-09ccc53e7-241107",
48
+ "@react-aria/interactions": "^3.0.0-nightly-09ccc53e7-241107",
49
+ "@react-aria/live-announcer": "^3.0.0-nightly-09ccc53e7-241107",
50
+ "@react-aria/menu": "^3.0.0-nightly-09ccc53e7-241107",
51
+ "@react-aria/toolbar": "3.0.0-nightly-09ccc53e7-241107",
52
+ "@react-aria/tree": "3.0.0-nightly-09ccc53e7-241107",
53
+ "@react-aria/utils": "^3.0.0-nightly-09ccc53e7-241107",
54
+ "@react-aria/virtualizer": "^3.0.0-nightly-09ccc53e7-241107",
55
+ "@react-stately/color": "^3.0.0-nightly-09ccc53e7-241107",
56
+ "@react-stately/disclosure": "3.0.0-nightly-09ccc53e7-241107",
57
+ "@react-stately/layout": "^3.0.0-nightly-09ccc53e7-241107",
58
+ "@react-stately/menu": "^3.0.0-nightly-09ccc53e7-241107",
59
+ "@react-stately/selection": "^3.0.0-nightly-09ccc53e7-241107",
60
+ "@react-stately/table": "^3.0.0-nightly-09ccc53e7-241107",
61
+ "@react-stately/utils": "^3.0.0-nightly-09ccc53e7-241107",
62
+ "@react-stately/virtualizer": "^3.0.0-nightly-09ccc53e7-241107",
63
+ "@react-types/color": "^3.0.0-nightly-09ccc53e7-241107",
64
+ "@react-types/form": "^3.0.0-nightly-09ccc53e7-241107",
65
+ "@react-types/grid": "^3.0.0-nightly-09ccc53e7-241107",
66
+ "@react-types/shared": "^3.0.0-nightly-09ccc53e7-241107",
67
+ "@react-types/table": "^3.0.0-nightly-09ccc53e7-241107",
68
68
  "@swc/helpers": "^0.5.0",
69
69
  "client-only": "^0.0.1",
70
- "react-aria": "^3.0.0-nightly-426bff12a-241106",
71
- "react-stately": "^3.0.0-nightly-426bff12a-241106",
70
+ "react-aria": "^3.0.0-nightly-09ccc53e7-241107",
71
+ "react-stately": "^3.0.0-nightly-09ccc53e7-241107",
72
72
  "use-sync-external-store": "^1.2.0"
73
73
  },
74
74
  "peerDependencies": {
@@ -10,11 +10,12 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {AriaToggleButtonProps, HoverEvents, mergeProps, useFocusRing, useHover, useToggleButton} from 'react-aria';
13
+ import {AriaToggleButtonProps, HoverEvents, mergeProps, useFocusRing, useHover, useToggleButton, useToggleButtonGroupItem} from 'react-aria';
14
14
  import {ButtonRenderProps} from './Button';
15
15
  import {ContextValue, RenderProps, SlotProps, useContextProps, useRenderProps} from './utils';
16
- import {forwardRefType} from '@react-types/shared';
17
- import React, {createContext, ForwardedRef, forwardRef} from 'react';
16
+ import {forwardRefType, Key} from '@react-types/shared';
17
+ import React, {createContext, ForwardedRef, forwardRef, useContext} from 'react';
18
+ import {ToggleGroupStateContext} from './ToggleButtonGroup';
18
19
  import {ToggleState, useToggleState} from 'react-stately';
19
20
 
20
21
  export interface ToggleButtonRenderProps extends Omit<ButtonRenderProps, 'isPending'> {
@@ -29,19 +30,35 @@ export interface ToggleButtonRenderProps extends Omit<ButtonRenderProps, 'isPend
29
30
  state: ToggleState
30
31
  }
31
32
 
32
- export interface ToggleButtonProps extends Omit<AriaToggleButtonProps, 'children' | 'elementType'>, HoverEvents, SlotProps, RenderProps<ToggleButtonRenderProps> {}
33
+ export interface ToggleButtonProps extends Omit<AriaToggleButtonProps, 'children' | 'elementType' | 'id'>, HoverEvents, SlotProps, RenderProps<ToggleButtonRenderProps> {
34
+ /** When used in a ToggleButtonGroup, an identifier for the item in `selectedKeys`. When used standalone, a DOM id. */
35
+ id?: Key
36
+ }
33
37
 
34
38
  export const ToggleButtonContext = createContext<ContextValue<ToggleButtonProps, HTMLButtonElement>>({});
35
39
 
36
40
  function ToggleButton(props: ToggleButtonProps, ref: ForwardedRef<HTMLButtonElement>) {
37
41
  [props, ref] = useContextProps(props, ref, ToggleButtonContext);
38
- let state = useToggleState(props);
39
- let {buttonProps, isPressed} = useToggleButton(props, state, ref);
42
+ let groupState = useContext(ToggleGroupStateContext);
43
+ let state = useToggleState(groupState && props.id != null ? {
44
+ isSelected: groupState.selectedKeys.has(props.id),
45
+ onChange(isSelected) {
46
+ groupState.setSelected(props.id!, isSelected);
47
+ }
48
+ } : props);
49
+
50
+ let {buttonProps, isPressed, isSelected, isDisabled} = groupState && props.id != null
51
+ // eslint-disable-next-line react-hooks/rules-of-hooks
52
+ ? useToggleButtonGroupItem({...props, id: props.id}, groupState, ref)
53
+ // eslint-disable-next-line react-hooks/rules-of-hooks
54
+ : useToggleButton({...props, id: props.id != null ? String(props.id) : undefined}, state, ref);
55
+
40
56
  let {focusProps, isFocused, isFocusVisible} = useFocusRing(props);
41
57
  let {hoverProps, isHovered} = useHover(props);
42
58
  let renderProps = useRenderProps({
43
59
  ...props,
44
- values: {isHovered, isPressed, isFocused, isSelected: state.isSelected, isFocusVisible, isDisabled: props.isDisabled || false, state},
60
+ id: undefined,
61
+ values: {isHovered, isPressed, isFocused, isSelected: state.isSelected, isFocusVisible, isDisabled, state},
45
62
  defaultClassName: 'react-aria-ToggleButton'
46
63
  });
47
64
 
@@ -52,9 +69,9 @@ function ToggleButton(props: ToggleButtonProps, ref: ForwardedRef<HTMLButtonElem
52
69
  ref={ref}
53
70
  slot={props.slot || undefined}
54
71
  data-focused={isFocused || undefined}
55
- data-disabled={props.isDisabled || undefined}
72
+ data-disabled={isDisabled || undefined}
56
73
  data-pressed={isPressed || undefined}
57
- data-selected={state.isSelected || undefined}
74
+ data-selected={isSelected || undefined}
58
75
  data-hovered={isHovered || undefined}
59
76
  data-focus-visible={isFocusVisible || undefined} />
60
77
  );
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Copyright 2024 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import {AriaToggleButtonGroupProps, useToggleButtonGroup} from 'react-aria';
13
+ import {ContextValue, RenderProps, SlotProps, useContextProps, useRenderProps} from './utils';
14
+ import {forwardRefType} from '@react-types/shared';
15
+ import React, {createContext, ForwardedRef, forwardRef} from 'react';
16
+ import {ToggleGroupState, useToggleGroupState} from 'react-stately';
17
+
18
+ export interface ToggleButtonGroupRenderProps {
19
+ /**
20
+ * Whether the toggle button group is disabled.
21
+ * @selector [data-disabled]
22
+ */
23
+ isDisabled: boolean,
24
+ /**
25
+ * State of the toggle button group.
26
+ */
27
+ state: ToggleGroupState
28
+ }
29
+
30
+ export interface ToggleButtonGroupProps extends AriaToggleButtonGroupProps, RenderProps<ToggleButtonGroupRenderProps>, SlotProps {}
31
+
32
+ export const ToggleButtonGroupContext = createContext<ContextValue<ToggleButtonGroupProps, HTMLDivElement>>({});
33
+ export const ToggleGroupStateContext = createContext<ToggleGroupState | null>(null);
34
+
35
+ function ToggleButtonGroup(props: ToggleButtonGroupProps, ref: ForwardedRef<HTMLDivElement>) {
36
+ [props, ref] = useContextProps(props, ref, ToggleButtonGroupContext);
37
+ let state = useToggleGroupState(props);
38
+ let {groupProps} = useToggleButtonGroup(props, state, ref);
39
+
40
+ let renderProps = useRenderProps({
41
+ ...props,
42
+ values: {
43
+ isDisabled: state.isDisabled,
44
+ state
45
+ },
46
+ defaultClassName: 'react-aria-ToggleButtonGroup'
47
+ });
48
+
49
+ return (
50
+ <div
51
+ {...groupProps}
52
+ {...renderProps}
53
+ ref={ref}
54
+ slot={props.slot || undefined}
55
+ data-orientation={props.orientation || 'horizontal'}
56
+ data-disabled={props.isDisabled || undefined}>
57
+ <ToggleGroupStateContext.Provider value={state}>
58
+ {renderProps.children}
59
+ </ToggleGroupStateContext.Provider>
60
+ </div>
61
+ );
62
+ }
63
+
64
+ /**
65
+ * A toggle button group allows a user to toggle multiple options, with single or multiple selection.
66
+ */
67
+ const _ToggleButtonGroup = /*#__PURE__*/ (forwardRef as forwardRefType)(ToggleButtonGroup);
68
+ export {_ToggleButtonGroup as ToggleButtonGroup};
package/src/index.ts CHANGED
@@ -70,6 +70,7 @@ export {Text, TextContext} from './Text';
70
70
  export {TextArea, TextAreaContext} from './TextArea';
71
71
  export {TextField, TextFieldContext} from './TextField';
72
72
  export {ToggleButton, ToggleButtonContext} from './ToggleButton';
73
+ export {ToggleButtonGroup, ToggleButtonGroupContext, ToggleGroupStateContext} from './ToggleButtonGroup';
73
74
  export {Toolbar, ToolbarContext} from './Toolbar';
74
75
  export {TooltipTrigger, Tooltip, TooltipTriggerStateContext, TooltipContext} from './Tooltip';
75
76
  export {UNSTABLE_TreeLoadingIndicator, UNSTABLE_Tree, UNSTABLE_TreeItem, UNSTABLE_TreeContext, UNSTABLE_TreeItemContent, UNSTABLE_TreeStateContext} from './Tree';
@@ -131,6 +132,7 @@ export type {TextAreaProps} from './TextArea';
131
132
  export type {TextFieldProps, TextFieldRenderProps} from './TextField';
132
133
  export type {TextProps} from './Text';
133
134
  export type {ToggleButtonProps, ToggleButtonRenderProps} from './ToggleButton';
135
+ export type {ToggleButtonGroupProps, ToggleButtonGroupRenderProps} from './ToggleButtonGroup';
134
136
  export type {ToolbarProps, ToolbarRenderProps} from './Toolbar';
135
137
  export type {TooltipProps, TooltipRenderProps, TooltipTriggerComponentProps} from './Tooltip';
136
138
  export type {TreeProps, TreeRenderProps, TreeItemProps, TreeItemRenderProps, TreeItemContentProps, TreeItemContentRenderProps} from './Tree';