Skip to content

Commit

Permalink
Merge branch 'main' into spinner-css-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
randall-krauskopf authored Oct 30, 2024
2 parents 2824783 + 461ae57 commit 46f9dcb
Show file tree
Hide file tree
Showing 26 changed files with 285 additions and 151 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-plums-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

fix(DataTable): export datatable utility types
5 changes: 5 additions & 0 deletions .changeset/slow-snails-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

SelectPanel: Allow using SelectPanel in FormControl
2 changes: 2 additions & 0 deletions contributor-docs/adrs/adr-002-behavior-isolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,7 @@ Some behaviors can be implemented as vanilla JavaScript without introducing addi
In general, _portions of behaviors_ that affect or rely on **user interactions and events**, **shared state**, or **CSS styles** should be kept in React Hooks. Parts of the behavior that can be implemented in isolation of these concepts should be built with no dependency on React or other libraries.

[^1]: https://codesandbox.io/s/demo-styling-custom-element-g973d?file=/src/index.tsx

[^2]: https://github.com/github/details-dialog-element/blob/main/src/index.ts#L195

[^3]: https://github.com/github/details-dialog-element#details-dialog-close
85 changes: 14 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"npm": ">=7"
},
"devDependencies": {
"@babel/eslint-parser": "7.23.3",
"@babel/eslint-parser": "7.25.9",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@github/axe-github": "0.6.1",
Expand Down Expand Up @@ -72,7 +72,7 @@
"jest-watch-typeahead": "2.2.2",
"markdownlint-cli2": "^0.11.0",
"markdownlint-cli2-formatter-pretty": "0.0.3",
"prettier": "3.0.3",
"prettier": "3.3.3",
"rimraf": "5.0.5",
"size-limit": "11.1.5",
"stylelint": "16.9.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ActionList/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const Group: React.FC<React.PropsWithChildren<ActionListGroupProps>> = ({
// because the heading is hidden from the accessibility tree and only used for presentation role.
// We will instead use aria-label to label the list. See a line below.
aria-labelledby={listRole ? undefined : groupHeadingId}
aria-label={listRole ? title ?? (slots.groupHeading?.props.children as string) : undefined}
aria-label={listRole ? (title ?? (slots.groupHeading?.props.children as string)) : undefined}
role={role || (listRole && 'group')}
>
{slots.groupHeading ? childrenWithoutSlots : props.children}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ActionList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const List = React.forwardRef<HTMLUListElement, ActionListProps>(
enableFocusZone: enableFocusZoneFromContainer,
} = React.useContext(ActionListContainerContext)

const ariaLabelledBy = slots.heading ? slots.heading.props.id ?? headingId : listLabelledBy
const ariaLabelledBy = slots.heading ? (slots.heading.props.id ?? headingId) : listLabelledBy
const listRole = role || listRoleFromContainer
const listRef = useProvidedRefOrCreate(forwardedRef as React.RefObject<HTMLUListElement>)

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/AvatarStack/AvatarStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ const AvatarStack = ({
tabIndex={!hasInteractiveChildren && !disableExpand ? 0 : undefined}
ref={stackContainer}
>
{' '}
{transformChildren(children)}
</Box>
</AvatarStackWrapper>
Expand Down
27 changes: 16 additions & 11 deletions packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ const ButtonBase = forwardRef(
true,
)
: TrailingVisual
? renderModuleVisual(
TrailingVisual,
Boolean(loading) && !LeadingVisual,
'trailingVisual',
false,
)
: null
? renderModuleVisual(
TrailingVisual,
Boolean(loading) && !LeadingVisual,
'trailingVisual',
false,
)
: null
}
</Box>
{
Expand Down Expand Up @@ -314,8 +314,13 @@ const ButtonBase = forwardRef(
true,
)
: TrailingVisual
? renderModuleVisual(TrailingVisual, Boolean(loading) && !LeadingVisual, 'trailingVisual', false)
: null
? renderModuleVisual(
TrailingVisual,
Boolean(loading) && !LeadingVisual,
'trailingVisual',
false,
)
: null
}
</span>
{
Expand Down Expand Up @@ -420,8 +425,8 @@ const ButtonBase = forwardRef(
'trailingVisual',
)
: TrailingVisual
? renderVisual(TrailingVisual, Boolean(loading) && !LeadingVisual, 'trailingVisual')
: null
? renderVisual(TrailingVisual, Boolean(loading) && !LeadingVisual, 'trailingVisual')
: null
}
</Box>
{
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/DataTable/DataTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export const Playground = (args: DataTableProps<UniqueRow> & ColWidthArgTypes) =
return args[`colWidth${colIndex}`] !== 'explicit width'
? args[`colWidth${colIndex}`]
: args[`explicitColWidth${colIndex}`]
? args[`explicitColWidth${colIndex}`]
: 'grow'
? args[`explicitColWidth${colIndex}`]
: 'grow'
}

const align = args.align as CellAlignment
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/DataTable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ export type {
TableSkeletonProps,
} from './Table'
export {createColumnHelper} from './column'
export type {Column} from './column'
export type {Column, CellAlignment, ColumnWidth} from './column'
export type {UniqueRow} from './row'
export type {ObjectPaths} from './utils'
4 changes: 2 additions & 2 deletions packages/react/src/DataTable/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export function useTable<Data extends UniqueRow>({
header.column.sortBy === true
? strategies.basic
: typeof header.column.sortBy === 'string'
? strategies[header.column.sortBy]
: header.column.sortBy
? strategies[header.column.sortBy]
: header.column.sortBy

setRowOrder(rowOrder => {
return rowOrder.slice().sort((a, b) => {
Expand Down
44 changes: 22 additions & 22 deletions packages/react/src/DataTable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type MaxLength = ArrayOfLength<10>[number]
type ArrayIndex<A extends ReadonlyArray<any>, Keys extends number = never> = A extends readonly []
? Keys
: // eslint-disable-next-line @typescript-eslint/no-unused-vars
A extends readonly [infer _, ...infer Tail]
? ArrayIndex<Tail, Keys | Tail['length']>
: Keys
A extends readonly [infer _, ...infer Tail]
? ArrayIndex<Tail, Keys | Tail['length']>
: Keys

// Check if the given type is within the bounds set by `MaxLength`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -30,25 +30,25 @@ type ArrayWithinBounds<T> = T extends ReadonlyArray<any> & {length: infer Length
export type ObjectPaths<T> = T extends readonly any[] & ArrayWithinBounds<T>
? `${ArrayIndex<T>}` | PrefixPath<T, ArrayIndex<T>>
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends any[]
? never & 'Unable to determine keys of potentially boundless array'
: T extends Date
? never
: T extends object
? Extract<keyof T, string | number> | PrefixPath<T, Extract<keyof T, string | number>>
: never
T extends any[]
? never & 'Unable to determine keys of potentially boundless array'
: T extends Date
? never
: T extends object
? Extract<keyof T, string | number> | PrefixPath<T, Extract<keyof T, string | number>>
: never

type PrefixPath<T, Prefix> = Prefix extends Extract<keyof T, number | string>
? `${Prefix}.${ObjectPaths<T[Prefix]>}`
: never
type PrefixPath<T, Prefix> =
Prefix extends Extract<keyof T, number | string> ? `${Prefix}.${ObjectPaths<T[Prefix]>}` : never

// Get the value of a given path within an object
export type ObjectPathValue<ObjectType extends object, Path extends string | number> = ObjectType extends Record<
string | number,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
any
>
? Path extends `${infer Key}.${infer NestedPath}`
? ObjectPathValue<ObjectType[Key], NestedPath>
: ObjectType[Path]
: never
export type ObjectPathValue<ObjectType extends object, Path extends string | number> =
ObjectType extends Record<
string | number,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
any
>
? Path extends `${infer Key}.${infer NestedPath}`
? ObjectPathValue<ObjectType[Key], NestedPath>
: ObjectType[Path]
: never
Loading

0 comments on commit 46f9dcb

Please sign in to comment.