-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EuiProvider] Set up componentDefaults
prop, context, & documentation
#6923
Merged
cee-chen
merged 4 commits into
elastic:feature/provider/component-defaults
from
cee-chen:feature/provider/component-defaults
Jul 12, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 18 additions & 5 deletions
23
src-docs/src/components/guide_section/guide_section_parts/guide_section_text.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
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
22 changes: 22 additions & 0 deletions
22
src-docs/src/views/provider/provider_component_defaults.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,22 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
|
||
import { EuiComponentDefaults } from '../../../../src/components/provider/component_defaults'; | ||
|
||
// Used to generate a "component" that is parsed for its types | ||
// and used to generate a prop table | ||
export const EuiComponentDefaultsProps: FunctionComponent< | ||
EuiComponentDefaults | ||
> = () => <></>; | ||
|
||
// Used by both getting started and EuiProvider component documentation pages | ||
// Exported in one place for DRYness | ||
export const euiProviderComponentDefaultsSnippet = `<EuiProvider | ||
componentDefaults={{ | ||
EuiTablePagination: { itemsPerPage: 20, }, | ||
EuiFocusTrap: { crossFrame: true }, | ||
EuiPortal: { insert }, | ||
}} | ||
> | ||
<App /> | ||
</EuiProvider> | ||
`; |
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
50 changes: 50 additions & 0 deletions
50
src/components/provider/component_defaults/component_defaults.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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { PropsWithChildren } from 'react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { | ||
EuiComponentDefaultsProvider, | ||
useEuiComponentDefaults, | ||
} from './component_defaults'; | ||
|
||
describe('EuiComponentDefaultsProvider', () => { | ||
it('sets up context that allows accessing the passed `componentDefaults` from anywhere', () => { | ||
const wrapper = ({ children }: PropsWithChildren<{}>) => ( | ||
<EuiComponentDefaultsProvider | ||
componentDefaults={{ | ||
EuiPortal: { | ||
insert: { | ||
sibling: document.createElement('div'), | ||
position: 'before', | ||
}, | ||
}, | ||
}} | ||
> | ||
{children} | ||
</EuiComponentDefaultsProvider> | ||
); | ||
const { result } = renderHook(useEuiComponentDefaults, { wrapper }); | ||
|
||
expect(result.current).toMatchInlineSnapshot(` | ||
Object { | ||
"EuiPortal": Object { | ||
"insert": Object { | ||
"position": "before", | ||
"sibling": <div />, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
// NOTE: Components are in charge of their own testing to ensure that the props | ||
// coming from `useEuiComponentDefaults()` were properly applied. This file | ||
// is simply a very light wrapper that carries prop data. | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to note that I know this new beta/new badge logic for subsections (de3cfc2) is not terribly clean and is pretty repetitive with the existing beta/new badge logic, but I'm not bothering to get super DRY or fancy with it since we're migrating all our docs to EUI+ at some point in the future.