Skip to content

Commit f235c3c

Browse files
authored
v35: Remove type aliases for ActionList (#1937)
* Replace aliases for ActionList types * export types for LinkItem * update selection types
1 parent 33da6a0 commit f235c3c

File tree

9 files changed

+41
-39
lines changed

9 files changed

+41
-39
lines changed

src/ActionList/Description.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {SxProp, merge} from '../sx'
44
import Truncate from '../Truncate'
55
import {Slot, ItemContext} from './Item'
66

7-
export type DescriptionProps = {
7+
export type ActionListDescriptionProps = {
88
/**
99
* Secondary text style variations.
1010
*
@@ -14,7 +14,7 @@ export type DescriptionProps = {
1414
variant?: 'inline' | 'block'
1515
} & SxProp
1616

17-
export const Description: React.FC<DescriptionProps> = ({variant = 'inline', sx = {}, ...props}) => {
17+
export const Description: React.FC<ActionListDescriptionProps> = ({variant = 'inline', sx = {}, ...props}) => {
1818
const styles = {
1919
fontSize: 0,
2020
lineHeight: '16px',

src/ActionList/Group.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React from 'react'
22
import {useSSRSafeId} from '@react-aria/ssr'
33
import Box from '../Box'
44
import {SxProp} from '../sx'
5-
import {ListContext, ListProps} from './List'
5+
import {ListContext, ActionListProps} from './List'
66
import {AriaRole} from '../utils/types'
77

8-
export type GroupProps = {
8+
export type ActionListGroupProps = {
99
/**
1010
* Style variations. Usage is discretionary.
1111
*
@@ -29,13 +29,13 @@ export type GroupProps = {
2929
/**
3030
* Whether multiple Items or a single Item can be selected in the Group. Overrides value on ActionList root.
3131
*/
32-
selectionVariant?: ListProps['selectionVariant'] | false
32+
selectionVariant?: ActionListProps['selectionVariant'] | false
3333
}
3434

35-
type ContextProps = Pick<GroupProps, 'selectionVariant'>
35+
type ContextProps = Pick<ActionListGroupProps, 'selectionVariant'>
3636
export const GroupContext = React.createContext<ContextProps>({})
3737

38-
export const Group: React.FC<GroupProps> = ({
38+
export const Group: React.FC<ActionListGroupProps> = ({
3939
title,
4040
variant = 'subtle',
4141
auxiliaryText,
@@ -73,7 +73,7 @@ export const Group: React.FC<GroupProps> = ({
7373
)
7474
}
7575

76-
export type HeaderProps = Pick<GroupProps, 'variant' | 'title' | 'auxiliaryText'> & {
76+
export type HeaderProps = Pick<ActionListGroupProps, 'variant' | 'title' | 'auxiliaryText'> & {
7777
labelId: string
7878
}
7979

src/ActionList/Item.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import Box, {BoxProps} from '../Box'
77
import sx, {SxProp, merge} from '../sx'
88
import createSlots from '../utils/create-slots'
99
import {AriaRole} from '../utils/types'
10-
import {ListContext, ListProps} from './List'
11-
import {GroupContext, GroupProps} from './Group'
10+
import {ListContext, ActionListProps} from './List'
11+
import {GroupContext, ActionListGroupProps} from './Group'
1212
import {ActionListContainerContext} from './ActionListContainerContext'
1313
import {Selection} from './Selection'
1414

15-
export const getVariantStyles = (variant: ItemProps['variant'], disabled: ItemProps['disabled']) => {
15+
export const getVariantStyles = (
16+
variant: ActionListItemProps['variant'],
17+
disabled: ActionListItemProps['disabled']
18+
) => {
1619
if (disabled) {
1720
return {
1821
color: 'primer.fg.disabled',
@@ -39,7 +42,7 @@ export const getVariantStyles = (variant: ItemProps['variant'], disabled: ItemPr
3942
}
4043
}
4144

42-
export type ItemProps = {
45+
export type ActionListItemProps = {
4346
/**
4447
* Primary content for an Item
4548
*/
@@ -79,15 +82,15 @@ export type ItemProps = {
7982

8083
const {Slots, Slot} = createSlots(['LeadingVisual', 'InlineDescription', 'BlockDescription', 'TrailingVisual'])
8184
export {Slot}
82-
export type ItemContext = Pick<ItemProps, 'variant' | 'disabled'> & {
85+
export type ItemContext = Pick<ActionListItemProps, 'variant' | 'disabled'> & {
8386
inlineDescriptionId: string
8487
blockDescriptionId: string
8588
}
8689

8790
const LiBox = styled.li<SxProp>(sx)
8891
export const TEXT_ROW_HEIGHT = '20px' // custom value off the scale
8992

90-
export const Item = React.forwardRef<HTMLLIElement, ItemProps>(
93+
export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
9194
(
9295
{
9396
variant = 'default',
@@ -106,12 +109,12 @@ export const Item = React.forwardRef<HTMLLIElement, ItemProps>(
106109
const {selectionVariant: groupSelectionVariant} = React.useContext(GroupContext)
107110
const {container, afterSelect, selectionAttribute} = React.useContext(ActionListContainerContext)
108111

109-
let selectionVariant: ListProps['selectionVariant'] | GroupProps['selectionVariant']
112+
let selectionVariant: ActionListProps['selectionVariant'] | ActionListGroupProps['selectionVariant']
110113
if (typeof groupSelectionVariant !== 'undefined') selectionVariant = groupSelectionVariant
111114
else selectionVariant = listSelectionVariant
112115

113116
/** Infer item role based on the container */
114-
let itemRole: ItemProps['role']
117+
let itemRole: ActionListItemProps['role']
115118
if (container === 'ActionMenu' || container === 'DropdownMenu') {
116119
if (selectionVariant === 'single') itemRole = 'menuitemradio'
117120
else if (selectionVariant === 'multiple') itemRole = 'menuitemcheckbox'
@@ -257,7 +260,7 @@ export const Item = React.forwardRef<HTMLLIElement, ItemProps>(
257260
</Slots>
258261
)
259262
}
260-
) as PolymorphicForwardRefComponent<'li', ItemProps>
263+
) as PolymorphicForwardRefComponent<'li', ActionListItemProps>
261264

262265
Item.displayName = 'ActionList.Item'
263266

src/ActionList/LinkItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '@radix-ui/react-polymorphic'
33
import Link from '../Link'
44
import {SxProp, merge} from '../sx'
5-
import {Item, ItemProps} from './Item'
5+
import {Item, ActionListItemProps} from './Item'
66

77
// adopted from React.AnchorHTMLAttributes
88
type LinkProps = {
@@ -18,7 +18,7 @@ type LinkProps = {
1818
}
1919

2020
// LinkItem does not support selected, variants, etc.
21-
type LinkItemProps = Pick<ItemProps, 'children' | 'sx'> & LinkProps
21+
export type ActionListLinkItemProps = Pick<ActionListItemProps, 'children' | 'sx'> & LinkProps
2222

2323
export const LinkItem = React.forwardRef(({sx = {}, as: Component, ...props}, forwardedRef) => {
2424
const styles = {
@@ -46,4 +46,4 @@ export const LinkItem = React.forwardRef(({sx = {}, as: Component, ...props}, fo
4646
{props.children}
4747
</Item>
4848
)
49-
}) as PolymorphicForwardRefComponent<'a', LinkItemProps>
49+
}) as PolymorphicForwardRefComponent<'a', ActionListLinkItemProps>

src/ActionList/List.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import sx, {SxProp, merge} from '../sx'
55
import {AriaRole} from '../utils/types'
66
import {ActionListContainerContext} from './ActionListContainerContext'
77

8-
export type ListProps = {
8+
export type ActionListProps = {
99
/**
1010
* `inset` children are offset (vertically and horizontally) from `List`’s edges, `full` children are flush (vertically and horizontally) with `List` edges
1111
*/
@@ -24,12 +24,12 @@ export type ListProps = {
2424
role?: AriaRole
2525
} & SxProp
2626

27-
type ContextProps = Pick<ListProps, 'variant' | 'selectionVariant' | 'showDividers' | 'role'>
27+
type ContextProps = Pick<ActionListProps, 'variant' | 'selectionVariant' | 'showDividers' | 'role'>
2828
export const ListContext = React.createContext<ContextProps>({})
2929

3030
const ListBox = styled.ul<SxProp>(sx)
3131

32-
export const List = React.forwardRef<HTMLUListElement, ListProps>(
32+
export const List = React.forwardRef<HTMLUListElement, ActionListProps>(
3333
(
3434
{variant = 'inset', selectionVariant, showDividers = false, role, sx: sxProp = {}, ...props},
3535
forwardedRef
@@ -68,6 +68,6 @@ export const List = React.forwardRef<HTMLUListElement, ListProps>(
6868
</ListBox>
6969
)
7070
}
71-
) as PolymorphicForwardRefComponent<'ul', ListProps>
71+
) as PolymorphicForwardRefComponent<'ul', ActionListProps>
7272

7373
List.displayName = 'ActionList'

src/ActionList/Selection.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React from 'react'
22
import {CheckIcon} from '@primer/octicons-react'
3-
import {ListContext, ListProps} from './List'
4-
import {GroupContext, GroupProps} from './Group'
5-
import {ItemProps} from './Item'
3+
import {ListContext, ActionListProps} from './List'
4+
import {GroupContext, ActionListGroupProps} from './Group'
5+
import {ActionListItemProps} from './Item'
66
import {LeadingVisualContainer} from './Visuals'
77

8-
type SelectionProps = Pick<ItemProps, 'selected'>
8+
type SelectionProps = Pick<ActionListItemProps, 'selected'>
99
export const Selection: React.FC<SelectionProps> = ({selected}) => {
1010
const {selectionVariant: listSelectionVariant} = React.useContext(ListContext)
1111
const {selectionVariant: groupSelectionVariant} = React.useContext(GroupContext)
1212

1313
/** selectionVariant in Group can override the selectionVariant in List root */
1414
/** fallback to selectionVariant from container menu if any (ActionMenu, SelectPanel ) */
15-
let selectionVariant: ListProps['selectionVariant'] | GroupProps['selectionVariant']
15+
let selectionVariant: ActionListProps['selectionVariant'] | ActionListGroupProps['selectionVariant']
1616
if (typeof groupSelectionVariant !== 'undefined') selectionVariant = groupSelectionVariant
1717
else selectionVariant = listSelectionVariant
1818

src/ActionList/Visuals.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const LeadingVisualContainer: React.FC<VisualProps> = ({sx = {}, ...props
2828
)
2929
}
3030

31-
export type LeadingVisualProps = VisualProps
31+
export type ActionListLeadingVisualProps = VisualProps
3232
export const LeadingVisual: React.FC<VisualProps> = ({sx = {}, ...props}) => {
3333
return (
3434
<Slot name="LeadingVisual">
@@ -50,7 +50,7 @@ export const LeadingVisual: React.FC<VisualProps> = ({sx = {}, ...props}) => {
5050
)
5151
}
5252

53-
export type TrailingVisualProps = VisualProps
53+
export type ActionListTrailingVisualProps = VisualProps
5454
export const TrailingVisual: React.FC<VisualProps> = ({sx = {}, ...props}) => {
5555
return (
5656
<Slot name="TrailingVisual">

src/ActionList/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import {Divider} from './Divider'
66
import {Description} from './Description'
77
import {LeadingVisual, TrailingVisual} from './Visuals'
88

9-
export type {ListProps as ActionListProps} from './List'
10-
export type {GroupProps as ActionListGroupProps} from './Group'
11-
export type {ItemProps as ActionListItemProps} from './Item'
12-
export type {DescriptionProps as ActionListDescriptionProps} from './Description'
13-
export type {
14-
LeadingVisualProps as ActionListLeadingVisualProps,
15-
TrailingVisualProps as ActionListTrailingVisualProps
16-
} from './Visuals'
9+
export type {ActionListProps} from './List'
10+
export type {ActionListGroupProps} from './Group'
11+
export type {ActionListItemProps} from './Item'
12+
export type {ActionListLinkItemProps} from './LinkItem'
13+
export type {ActionListDescriptionProps} from './Description'
14+
export type {ActionListLeadingVisualProps, ActionListTrailingVisualProps} from './Visuals'
1715

1816
/**
1917
* Collection of list-related components.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type {
3939
ActionListProps,
4040
ActionListGroupProps,
4141
ActionListItemProps,
42+
ActionListLinkItemProps,
4243
ActionListDescriptionProps,
4344
ActionListLeadingVisualProps,
4445
ActionListTrailingVisualProps

0 commit comments

Comments
 (0)