-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
@uiw/react-only-when/if
.
- Loading branch information
1 parent
c315024
commit a052b5d
Showing
5 changed files
with
70 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
declare module '@uiw/react-only-when/if' { | ||
import { ReactElement } from "react"; | ||
import { FC, PropsWithChildren } from "react"; | ||
export interface IfProps { | ||
readonly condition?: boolean; | ||
readonly render?: () => ReactElement; | ||
} | ||
export const If: FC<PropsWithChildren<IfProps>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-disable jest/no-conditional-expect */ | ||
import TestRenderer from 'react-test-renderer'; | ||
import { If } from '../'; | ||
|
||
describe('<If />', () => { | ||
|
||
it('Not rendering children', () => { | ||
const component = TestRenderer.create( | ||
<If condition={false}> | ||
<span id="child" /> | ||
</If>, | ||
); | ||
let only = component.toJSON(); | ||
expect(only).toBeNull(); | ||
}); | ||
|
||
it('rendering children', () => { | ||
const component = TestRenderer.create( | ||
<If condition={true}> | ||
<span id="child" /> | ||
</If>, | ||
); | ||
let only = component.toJSON(); | ||
|
||
if (only && !Array.isArray(only)) { | ||
expect(only.type).toEqual('span'); | ||
expect(only.props.id).toEqual('child'); | ||
} | ||
}); | ||
|
||
it('render props', () => { | ||
const component = TestRenderer.create( | ||
<If condition={true} render={() => <span id="child" />} />, | ||
); | ||
let only = component.toJSON(); | ||
|
||
if (only && !Array.isArray(only)) { | ||
expect(only.type).toEqual('span'); | ||
expect(only.props.id).toEqual('child'); | ||
} | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters