-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: boolean visual state attributes (#3407)
- Loading branch information
1 parent
4bf4d89
commit 132a177
Showing
16 changed files
with
84 additions
and
35 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
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
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
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
33 changes: 33 additions & 0 deletions
33
packages/react-ui/internal/CommonWrapper/__tests__/CommonWrapper-test.tsx
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,33 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { CommonWrapper } from '../CommonWrapper'; | ||
|
||
describe('CommonWrapper', () => { | ||
it('common cases', () => { | ||
render( | ||
<CommonWrapper | ||
data-tid="CommonWrapper" | ||
data-selected | ||
disabled | ||
warning | ||
error | ||
hover={false} | ||
className="className" | ||
style={{ padding: 10 }} | ||
> | ||
<div>Children</div> | ||
</CommonWrapper>, | ||
); | ||
|
||
const element = screen.getByText('Children'); | ||
expect(element).toHaveClass('className'); | ||
expect(element).toHaveStyle('padding: 10px;'); | ||
expect(element).toHaveAttribute('data-tid', 'CommonWrapper'); | ||
expect(element).toHaveAttribute('data-selected', 'true'); | ||
expect(element).toHaveAttribute('data-visual-state-error'); | ||
expect(element).toHaveAttribute('data-visual-state-warning'); | ||
expect(element).not.toHaveAttribute('data-visual-state-disabled'); | ||
expect(element).not.toHaveAttribute('data-visual-state-hover'); | ||
}); | ||
}); |
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
17 changes: 17 additions & 0 deletions
17
packages/react-ui/internal/CommonWrapper/__tests__/tryGetBoolean.test.ts
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,17 @@ | ||
import { tryGetBoolean } from '../utils/tryGetBoolean'; | ||
|
||
describe('tryGetBoolean', () => { | ||
it('should return true when passed true', () => { | ||
expect(tryGetBoolean(true)).toBe(true); | ||
}); | ||
|
||
it('should return false when passed false', () => { | ||
expect(tryGetBoolean(false)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('tryGetBoolean with invalid input', () => { | ||
it.each([null, undefined, 42, 'hello', {}, []])('should return undefined when passed `%s`', (value) => { | ||
expect(tryGetBoolean(value)).toBeUndefined(); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
...ernal/CommonWrapper/extractCommonProps.ts → ...CommonWrapper/utils/extractCommonProps.ts
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
3 changes: 1 addition & 2 deletions
3
...per/getCommonVisualStateDataAttributes.ts → ...ils/getCommonVisualStateDataAttributes.ts
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
10 changes: 5 additions & 5 deletions
10
...onWrapper/getVisualStateDataAttributes.ts → ...per/utils/getVisualStateDataAttributes.ts
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
1 change: 1 addition & 0 deletions
1
packages/react-ui/internal/CommonWrapper/utils/tryGetBoolean.ts
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 @@ | ||
export const tryGetBoolean = (value: unknown): boolean | undefined => (typeof value === 'boolean' ? value : undefined); |