Skip to content

Commit f83b3ab

Browse files
authored
fix: Release audit fixes (#9291)
* update content elements to point to mdn * update Accordion props to copy disclosure props directly * make linearGradient/edgeToText internal only * fix lint * ide import fix doesnt move the ts ignore
1 parent f0d808e commit f83b3ab

24 files changed

+134
-44
lines changed

packages/@react-spectrum/s2/src/Accordion.tsx

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,23 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {ContextValue, DisclosureGroup, DisclosureGroupProps, SlotProps} from 'react-aria-components';
13+
import {AriaLabelingProps, DOMProps, DOMRef, DOMRefValue, Key} from '@react-types/shared';
14+
import {ContextValue, DisclosureGroup, RenderProps, SlotProps} from 'react-aria-components';
1415
import {
1516
Disclosure,
1617
DisclosureContext,
1718
DisclosureHeader,
1819
DisclosurePanel,
19-
DisclosurePanelProps,
20-
DisclosureProps,
21-
DisclosureTitle,
22-
DisclosureTitleProps
20+
DisclosureTitle
2321
} from './Disclosure';
24-
import {DOMProps, DOMRef, DOMRefValue, GlobalDOMAttributes} from '@react-types/shared';
25-
import {getAllowedOverrides, StylesPropWithHeight, UnsafeStyles} from './style-utils' with { type: 'macro' };
22+
import {getAllowedOverrides, StyleProps, StylesPropWithHeight, UnsafeStyles} from './style-utils' with { type: 'macro' };
2623
import React, {createContext, forwardRef, ReactNode} from 'react';
2724
import {style} from '../style' with { type: 'macro' };
2825
import {useDOMRef} from '@react-spectrum/utils';
2926
import {useSpectrumContextProps} from './useSpectrumContextProps';
3027

31-
export interface AccordionProps extends Omit<DisclosureGroupProps, 'className' | 'style' | 'children' | keyof GlobalDOMAttributes>, UnsafeStyles, DOMProps, SlotProps {
32-
/** The disclosure elements in the accordion. */
28+
export interface AccordionProps extends UnsafeStyles, DOMProps, SlotProps {
29+
/** The accordion item elements in the accordion. */
3330
children: React.ReactNode,
3431
/** Spectrum-defined styles, returned by the `style()` macro. */
3532
styles?: StylesPropWithHeight,
@@ -39,12 +36,22 @@ export interface AccordionProps extends Omit<DisclosureGroupProps, 'className' |
3936
*/
4037
size?: 'S' | 'M' | 'L' | 'XL',
4138
/**
42-
* The amount of space between the disclosure items.
39+
* The amount of space between the accordion items.
4340
* @default 'regular'
4441
*/
4542
density?: 'compact' | 'regular' | 'spacious',
4643
/** Whether the accordion should be displayed with a quiet style. */
47-
isQuiet?: boolean
44+
isQuiet?: boolean,
45+
/** Whether multiple accordion items can be expanded at the same time. */
46+
allowsMultipleExpanded?: boolean,
47+
/** Whether all accordion items are disabled. */
48+
isDisabled?: boolean,
49+
/** The currently expanded keys in the accordion (controlled). */
50+
expandedKeys?: Iterable<Key>,
51+
/** The initial expanded keys in the accordion (uncontrolled). */
52+
defaultExpandedKeys?: Iterable<Key>,
53+
/** Handler that is called when accordion items are expanded or collapsed. */
54+
onExpandedChange?: (keys: Set<Key>) => any
4855
}
4956

5057
const accordion = style({
@@ -80,18 +87,85 @@ export const Accordion = forwardRef(function Accordion(props: AccordionProps, re
8087
);
8188
});
8289

83-
export interface AccordionItemProps extends DisclosureProps {
84-
/** The contents of the accordion, consisting of a AccordionItemTitle and AccordionItemPanel. */
85-
children: ReactNode
90+
export interface AccordionItemState {
91+
/** Whether the accordion item is currently expanded. */
92+
readonly isExpanded: boolean,
93+
/** Sets whether the accordion item is expanded. */
94+
setExpanded(isExpanded: boolean): void,
95+
/** Expand the accordion item. */
96+
expand(): void,
97+
/** Collapse the accordion item. */
98+
collapse(): void,
99+
/** Toggles the accordion item's visibility. */
100+
toggle(): void
86101
}
102+
103+
export interface AccordionItemRenderProps {
104+
/**
105+
* Whether the accordion item is expanded.
106+
* @selector [data-expanded]
107+
*/
108+
isExpanded: boolean,
109+
/**
110+
* Whether the accordion item has keyboard focus.
111+
* @selector [data-focus-visible-within]
112+
*/
113+
isFocusVisibleWithin: boolean,
114+
/**
115+
* Whether the accordion item is disabled.
116+
* @selector [data-disabled]
117+
*/
118+
isDisabled: boolean,
119+
/**
120+
* State of the accordion item.
121+
*/
122+
state: AccordionItemState
123+
}
124+
125+
export interface AccordionItemProps extends Omit<RenderProps<AccordionItemRenderProps>, 'className' | 'style'>, SlotProps, StyleProps {
126+
/**
127+
* The size of the accordion item.
128+
* @default 'M'
129+
*/
130+
size?: 'S' | 'M' | 'L' | 'XL',
131+
/**
132+
* The amount of space between the accordion item.
133+
* @default 'regular'
134+
*/
135+
density?: 'compact' | 'regular' | 'spacious',
136+
/** Whether the accordion item should be displayed with a quiet style. */
137+
isQuiet?: boolean,
138+
/** The contents of the accordion item, consisting of a accordion item title and accordion item panel. */
139+
children: ReactNode,
140+
/** An id for the accordion item, matching the id used in `expandedKeys`. */
141+
id?: Key,
142+
/** Whether the accordion item is disabled. */
143+
isDisabled?: boolean,
144+
/** Handler that is called when the accordion item's expanded state changes. */
145+
onExpandedChange?: (isExpanded: boolean) => void,
146+
/** Whether the accordion item is expanded (controlled). */
147+
isExpanded?: boolean,
148+
/** Whether the accordion item is expanded by default (uncontrolled). */
149+
defaultExpanded?: boolean
150+
}
151+
87152
/**
88153
* A accordion item is a collapsible section of content. It is composed of a header with a heading and trigger button, and a panel that contains the content.
89154
*/
90155
export const AccordionItem = forwardRef(function AccordionItem(props: AccordionItemProps, ref: DOMRef<HTMLDivElement>) {
91156
return <Disclosure {...props} ref={ref} />;
92157
});
93158

94-
export interface AccordionItemTitleProps extends DisclosureTitleProps {}
159+
export interface AccordionItemTitleProps extends UnsafeStyles, DOMProps {
160+
/** The heading level of the accordion item title.
161+
*
162+
* @default 3
163+
*/
164+
level?: number,
165+
/** The contents of the accordion item title. */
166+
children: React.ReactNode
167+
}
168+
95169
/**
96170
* An accordion item title consisting of a heading and a trigger button to expand/collapse the panel.
97171
*/
@@ -100,16 +174,27 @@ export const AccordionItemTitle = forwardRef(function AccordionItemTitle(props:
100174
});
101175

102176
export interface AccordionItemHeaderProps extends UnsafeStyles, DOMProps {
177+
/** The contents of the accordion item header. */
103178
children: React.ReactNode
104179
}
180+
105181
/**
106182
* A wrapper element for the accordion item title that can contain other elements not part of the trigger.
107183
*/
108184
export const AccordionItemHeader = forwardRef(function AccordionItemHeader(props: AccordionItemHeaderProps, ref: DOMRef<HTMLDivElement>) {
109185
return <DisclosureHeader {...props} ref={ref} />;
110186
});
111187

112-
export interface AccordionItemPanelProps extends DisclosurePanelProps {}
188+
export interface AccordionItemPanelProps extends UnsafeStyles, DOMProps, AriaLabelingProps {
189+
/** The contents of the accordion item panel. */
190+
children: React.ReactNode,
191+
/**
192+
* The accessibility role for the accordion item panel.
193+
* @default 'group'
194+
*/
195+
role?: 'group' | 'region'
196+
}
197+
113198
/**
114199
* An accordion item panel is a collapsible section of content that is hidden until the accordion item is expanded.
115200
*/

packages/@react-spectrum/s2/src/Button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {baseColor, focusRing, fontRelative, lightDark, linearGradient, style} from '../style' with {type: 'macro'};
13+
import {baseColor, focusRing, fontRelative, lightDark, style} from '../style' with {type: 'macro'};
1414
import {ButtonRenderProps, ContextValue, Link, LinkProps, OverlayTriggerStateContext, Provider, Button as RACButton, ButtonProps as RACButtonProps} from 'react-aria-components';
1515
import {centerBaseline} from './CenterBaseline';
1616
import {control, getAllowedOverrides, staticColor, StyleProps} from './style-utils' with {type: 'macro'};
@@ -19,6 +19,7 @@ import {FocusableRef, FocusableRefValue, GlobalDOMAttributes} from '@react-types
1919
import {IconContext} from './Icon';
2020
// @ts-ignore
2121
import intlMessages from '../intl/*.json';
22+
import {linearGradient} from '../style/spectrum-theme' with {type: 'macro'};
2223
import {pressScale} from './pressScale';
2324
import {ProgressCircle} from './ProgressCircle';
2425
import {SkeletonContext} from './Skeleton';

packages/@react-spectrum/s2/src/ComboBox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
import {AsyncLoadable, GlobalDOMAttributes, HelpTextProps, LoadingState, SpectrumLabelableProps} from '@react-types/shared';
3737
import {AvatarContext} from './Avatar';
3838
import {BaseCollection, CollectionNode, createLeafComponent} from '@react-aria/collections';
39-
import {baseColor, edgeToText, focusRing, space, style} from '../style' with {type: 'macro'};
39+
import {baseColor, focusRing, space, style} from '../style' with {type: 'macro'};
4040
import {centerBaseline} from './CenterBaseline';
4141
import {centerPadding, control, controlBorderRadius, controlFont, controlSize, field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
4242
import {
@@ -51,6 +51,7 @@ import CheckmarkIcon from '../ui-icons/Checkmark';
5151
import ChevronIcon from '../ui-icons/Chevron';
5252
import {createContext, CSSProperties, ForwardedRef, forwardRef, ReactNode, Ref, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
5353
import {createFocusableRef} from '@react-spectrum/utils';
54+
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
5455
import {FieldErrorIcon, FieldGroup, FieldLabel, HelpText, Input} from './Field';
5556
import {FormContext, useFormProps} from './Form';
5657
import {forwardRefType} from './types';

packages/@react-spectrum/s2/src/Menu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
Separator,
2929
SeparatorProps
3030
} from 'react-aria-components';
31-
import {baseColor, edgeToText, focusRing, fontRelative, size, space, style} from '../style' with {type: 'macro'};
31+
import {baseColor, focusRing, fontRelative, size, space, style} from '../style' with {type: 'macro'};
3232
import {box, iconStyles} from './Checkbox';
3333
import {centerBaseline} from './CenterBaseline';
3434
import {centerPadding, control, controlFont, controlSize, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
@@ -37,6 +37,7 @@ import ChevronRightIcon from '../ui-icons/Chevron';
3737
import {createContext, forwardRef, JSX, ReactNode, useContext, useRef, useState} from 'react';
3838
import {divider} from './Divider';
3939
import {DOMRef, DOMRefValue, GlobalDOMAttributes, PressEvent} from '@react-types/shared';
40+
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
4041
import {forwardRefType} from './types';
4142
import {HeaderContext, HeadingContext, KeyboardContext, Text, TextContext} from './Content';
4243
import {IconContext} from './Icon'; // chevron right removed??

packages/@react-spectrum/s2/src/Picker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
} from 'react-aria-components';
3535
import {AsyncLoadable, FocusableRef, FocusableRefValue, GlobalDOMAttributes, HelpTextProps, LoadingState, PressEvent, RefObject, SpectrumLabelableProps} from '@react-types/shared';
3636
import {AvatarContext} from './Avatar';
37-
import {baseColor, edgeToText, focusRing, style} from '../style' with {type: 'macro'};
37+
import {baseColor, focusRing, style} from '../style' with {type: 'macro'};
3838
import {box, iconStyles as checkboxIconStyles} from './Checkbox';
3939
import {centerBaseline} from './CenterBaseline';
4040
import {
@@ -57,6 +57,7 @@ import {
5757
listboxItem,
5858
LOADER_ROW_HEIGHTS
5959
} from './ComboBox';
60+
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
6061
import {
6162
FieldErrorIcon,
6263
FieldLabel,

packages/@react-spectrum/s2/src/TabsPicker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
Provider,
2424
SelectValue
2525
} from 'react-aria-components';
26-
import {baseColor, edgeToText, focusRing, size, style} from '../style' with {type: 'macro'};
26+
import {baseColor, focusRing, size, style} from '../style' with {type: 'macro'};
2727
import {centerBaseline} from './CenterBaseline';
2828
import {
2929
checkmark,
@@ -37,6 +37,7 @@ import {
3737
import CheckmarkIcon from '../ui-icons/Checkmark';
3838
import ChevronIcon from '../ui-icons/Chevron';
3939
import {controlFont, fieldInput, StyleProps} from './style-utils' with {type: 'macro'};
40+
import {edgeToText} from '../style/spectrum-theme' with {type: 'macro'};
4041
import {
4142
FieldLabel
4243
} from './Field';

packages/@react-spectrum/s2/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export {pressScale} from './pressScale';
9494
export {Autocomplete, Collection, FileTrigger, parseColor, useLocale} from 'react-aria-components';
9595
export {useListData, useTreeData, useAsyncList} from 'react-stately';
9696

97-
export type {AccordionProps, AccordionItemProps, AccordionItemHeaderProps, AccordionItemTitleProps, AccordionItemPanelProps} from './Accordion';
97+
export type {AccordionProps, AccordionItemProps, AccordionItemHeaderProps, AccordionItemTitleProps, AccordionItemPanelProps, AccordionItemState, AccordionItemRenderProps} from './Accordion';
9898
export type {ActionBarProps} from './ActionBar';
9999
export type {ActionButtonProps} from './ActionButton';
100100
export type {ActionButtonGroupProps} from './ActionButtonGroup';

packages/@react-spectrum/s2/style/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {Inset, fontRelative as internalFontRelative, space as internalSpace, Spa
1515
import type {MacroContext} from '@parcel/macros';
1616
import {StyleString} from './types';
1717

18-
export {baseColor, color, edgeToText, lightDark, linearGradient, colorMix, size, style} from './spectrum-theme';
18+
export {baseColor, color, lightDark, colorMix, size, style} from './spectrum-theme';
1919
export type {StyleString} from './types';
2020

2121
// Wrap these functions in arbitrary value syntax when called from the outside.

packages/dev/s2-docs/pages/s2/ActionButton.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function PendingButton() {
7474

7575
## API
7676

77-
```tsx links={{ActionButton: '#actionbutton', Avatar: 'Avatar', Icon: 'icons'}}
77+
```tsx links={{ActionButton: '#actionbutton', Avatar: 'Avatar', Icon: 'icons', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span'}}
7878
<ActionButton>
7979
<Icon /> or <Avatar />
8080
<Text />

packages/dev/s2-docs/pages/s2/Button.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function PendingButton() {
7474

7575
## API
7676

77-
```tsx links={{Button: '#button', Icon: 'icons'}}
77+
```tsx links={{Button: '#button', Icon: 'icons', Text: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span'}}
7878
<Button>
7979
<Icon />
8080
<Text />

0 commit comments

Comments
 (0)