-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiProvider] Set up
componentDefaults
prop, context, & documentati…
…on (#6923) * Set up `EuiComponentDefaultsProvider` + light tests - actual defaults/override tests should be written per-component * Add documentation * Add support for beta/new badges to subitems in nav and subheadings * changelog
- Loading branch information
Showing
12 changed files
with
287 additions
and
24 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
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.