Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/descendants-exports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/descendants': minor
---

Exports `Position` enum. Removes type annotation from `Direction` export
5 changes: 5 additions & 0 deletions .changeset/form-footer-interfaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/form-footer': minor
---

Exports button prop interfaces
5 changes: 5 additions & 0 deletions .changeset/form-footer-lgids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/form-footer': patch
---

Passes `data-lgid` to the root `footer` element
5 changes: 5 additions & 0 deletions .changeset/lib-find-children.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/lib': minor
---

Adds `findChildren` utility to `lib`. Also adds `unwrapRootFragment` and `isChildWithProperty` helpers
7 changes: 7 additions & 0 deletions .changeset/wizard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@leafygreen-ui/wizard': minor
---

Initial Wizard package release.

See [README.md](./README.md) for usage guidelines
13 changes: 7 additions & 6 deletions packages/descendants/src/Highlight/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export type {
export {
Direction,
HighlightChangeHandler,
HighlightContextProps,
HighlightHookReturnType,
Index,
UseHighlightOptions,
type HighlightChangeHandler,
type HighlightContextProps,
type HighlightHookReturnType,
type Index,
Position,
type UseHighlightOptions,
} from './highlight.types';
export {
createHighlightContext,
Expand Down
3 changes: 2 additions & 1 deletion packages/descendants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ export {
// Highlight
export {
createHighlightContext,
type Direction,
Direction,
type HighlightChangeHandler,
type HighlightContextProps,
type HighlightContextType,
type HighlightHookReturnType,
HighlightProvider,
type Index,
Position,
useHighlight,
useHighlightContext,
type UseHighlightOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/form-footer/src/FormFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function FormFooter({
<LeafyGreenProvider darkMode={darkMode}>
<footer
data-testid={lgIds.root}
data-lgid={lgIds.root}
className={getFormFooterStyles({ theme, className })}
{...rest}
>
Expand Down
22 changes: 13 additions & 9 deletions packages/form-footer/src/FormFooter.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ type OmittedSplitButtonProps = Omit<
'children' | 'variant'
>;

type BackStandardButtonProps = ButtonPropsOmittingVariant & {
export type BackStandardButtonProps = ButtonPropsOmittingVariant & {
variant?: Extract<ButtonVariant, 'default' | 'dangerOutline'>;
};
type BackSplitButtonProps = OmittedSplitButtonProps & {
export type BackSplitButtonProps = OmittedSplitButtonProps & {
variant?: Extract<SplitButtonVariant, 'default' | 'danger'>;
};
type BackButtonProps = BackStandardButtonProps | BackSplitButtonProps;
export type BackButtonProps = BackStandardButtonProps | BackSplitButtonProps;

type CancelStandardButtonProps = ButtonPropsOmittingVariant;
type CancelSplitButtonProps = OmittedSplitButtonProps;
type CancelButtonProps = CancelStandardButtonProps | CancelSplitButtonProps;
export type CancelStandardButtonProps = ButtonPropsOmittingVariant;
export type CancelSplitButtonProps = OmittedSplitButtonProps;
export type CancelButtonProps =
| CancelStandardButtonProps
| CancelSplitButtonProps;

type PrimaryStandardButtonProps = ButtonPropsOmittingVariant &
export type PrimaryStandardButtonProps = ButtonPropsOmittingVariant &
ButtonPropsWithRequiredChildren & {
variant?: Extract<ButtonVariant, 'primary' | 'danger'>;
};
type PrimarySplitButtonProps = OmittedSplitButtonProps & {
export type PrimarySplitButtonProps = OmittedSplitButtonProps & {
variant?: Extract<SplitButtonVariant, 'primary' | 'danger'>;
};
type PrimaryButtonProps = PrimaryStandardButtonProps | PrimarySplitButtonProps;
export type PrimaryButtonProps =
| PrimaryStandardButtonProps
| PrimarySplitButtonProps;

export interface FormFooterProps
extends React.ComponentProps<'footer'>,
Expand Down
13 changes: 12 additions & 1 deletion packages/form-footer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,16 @@ export {
default,
default as FormFooter,
} from './FormFooter';
export { type FormFooterProps } from './FormFooter.types';
export {
type BackButtonProps,
type BackSplitButtonProps,
type BackStandardButtonProps,
type CancelButtonProps,
type CancelSplitButtonProps,
type CancelStandardButtonProps,
type FormFooterProps,
type PrimaryButtonProps,
type PrimarySplitButtonProps,
type PrimaryStandardButtonProps,
} from './FormFooter.types';
export { getLgIds } from './utils';
26 changes: 25 additions & 1 deletion packages/lib/src/childQueries/findChild/findChild.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Baz.displayName = 'Baz';
(Bar as any).isBar = true;
(Baz as any).isBaz = true;

describe('packages/lib/findChild', () => {
describe('packages/compound-component/findChild', () => {
test('should find a child component with matching static property', () => {
// Create an iterable to test different iteration scenarios
const children = [<Foo text="Foo" />, <Bar text="Bar" />];
Expand Down Expand Up @@ -77,6 +77,30 @@ describe('packages/lib/findChild', () => {
expect((found as React.ReactElement).props.text).toBe('also-in-fragment');
});

test('should find mapped children', () => {
const COUNT = 5;
const children = new Array(COUNT).fill(null).map((_, i) => {
return <Foo text={`Foo number ${i}`} />;
});

const found = findChild(children, 'isFoo');
expect((found as React.ReactElement).props.text).toBe('Foo number 0');
});

test('should find deeply mapped children', () => {
const COUNT = 5;
const children = (
<>
{new Array(COUNT).fill(null).map((_, i) => {
return <Foo text={`Foo number ${i}`} />;
})}
</>
);

const found = findChild(children, 'isFoo');
expect((found as React.ReactElement).props.text).toBe('Foo number 0');
});

test('should NOT find components in deeply nested fragments (search depth limitation)', () => {
const children = (
<React.Fragment>
Expand Down
7 changes: 4 additions & 3 deletions packages/lib/src/childQueries/findChild/findChild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export const findChild = (
}

const allChildren = unwrapRootFragment(children);
if (!allChildren) return;

return allChildren?.find(child =>
isChildWithProperty(child, staticProperty),
) as ReactElement | undefined;
return allChildren
.flat()
.find(child => isChildWithProperty(child, staticProperty)) as ReactElement;
};
Loading
Loading