-
Notifications
You must be signed in to change notification settings - Fork 863
[Emotion] Convert euiFocusRing() mixin
#5855
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cbf13cb
WIP: Initial setup of euiFocustRing mixin
c8fe913
Added `color` configuration for focus ring and docs
c7da030
Commented out some unused (yet) properties and updated the Focus docs…
20e41ae
Make `focus` global token required
5b83b06
[EuiSplitPanel] Fix border-radius of nested split panels
4ccba04
Return static string not literal, added tests
35d18cc
Added a note about `-webkit-` only for `color`
7b806b9
Update src/global_styling/variables/states.ts
cchaos 10e85d9
Manually adding prop types
9eb5de0
Cleanup code comments
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 hidden or 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 hidden or 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,97 @@ | ||
| import { css } from '@emotion/react'; | ||
| import React from 'react'; | ||
|
|
||
| import { | ||
| EuiCode, | ||
| euiScreenReaderOnlyStyles, | ||
| EuiText, | ||
| useEuiFocusRing, | ||
| } from '../../../../src'; | ||
| import { useEuiTheme } from '../../../../src/services'; | ||
| import { ThemeExample } from '../theme/_components/_theme_example'; | ||
|
|
||
| export default () => { | ||
| const { euiTheme } = useEuiTheme(); | ||
|
|
||
| return ( | ||
| <> | ||
| <ThemeExample | ||
| title={<code>.euiScreenReaderOnly</code>} | ||
| description={ | ||
| <p> | ||
| This utility class allows you to apply the screen reader only CSS | ||
| styles directly to your component. | ||
| </p> | ||
| } | ||
| example={ | ||
| <EuiText size="s"> | ||
| <p>The next paragraph is hidden except for screen readers.</p> | ||
| <p className="euiScreenReaderOnly"> | ||
| I am hidden except for screen readers | ||
| </p> | ||
| </EuiText> | ||
| } | ||
| snippet={'<p className="euiScreenReaderOnly" />'} | ||
| /> | ||
| <ThemeExample | ||
| title={<code>euiScreenReaderOnlyStyles()</code>} | ||
| description={ | ||
| <p> | ||
| This function allows you to apply the screen reader only CSS styles | ||
| directly to your component. | ||
| </p> | ||
| } | ||
| example={ | ||
| <EuiText size="s"> | ||
| <p>The next paragraph is hidden except for screen readers.</p> | ||
| <p css={css(euiScreenReaderOnlyStyles())}> | ||
| I am hidden except for screen readers | ||
| </p> | ||
| </EuiText> | ||
| } | ||
| snippet={'<p css={css(euiScreenReaderOnlyStyles())} />'} | ||
| /> | ||
| <ThemeExample | ||
| title={<code>useEuiFocusRing(offset?, color?)</code>} | ||
| description={ | ||
| <p> | ||
| By default, all interactable elements will inherit the{' '} | ||
| <EuiCode>outline</EuiCode> property from the reset file. However, | ||
| some instances require adjustment to the <EuiCode>offset</EuiCode>{' '} | ||
| and <EuiCode>color</EuiCode> of this outline. This helper function | ||
| allows that customization of the focus outline. | ||
| </p> | ||
| } | ||
| props={`offset: 'inset' | 'outset' | 'center' | CSSProperties['outlineOffset']; | ||
|
|
||
| color: CSSProperties['outlineColor'];`} | ||
| example={ | ||
| <EuiText size="s"> | ||
| <p> | ||
| <button> | ||
| I am an unstyled <EuiCode>button</EuiCode> with inherited | ||
| outline | ||
| </button> | ||
| </p> | ||
| <p> | ||
| <button | ||
| css={css` | ||
| &:focus { | ||
| ${useEuiFocusRing('outset', euiTheme.colors.primary)} | ||
| } | ||
| `} | ||
| > | ||
| I am an unstyled <EuiCode>button</EuiCode> with an{' '} | ||
| <EuiCode>outset, primary</EuiCode> outline | ||
| </button> | ||
| </p> | ||
| </EuiText> | ||
| } | ||
| snippetLanguage="emotion" | ||
| snippet={`&:focus { | ||
| \${useEuiFocusRing('outset', euiTheme.colors.primary)} | ||
| }`} | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ export type ThemeExample = { | |
| examplePanel?: _EuiSplitPanelInnerProps; | ||
| snippet?: GuideSectionExample['tabContent']; | ||
| snippetLanguage?: EuiCodeBlockProps['language']; | ||
| props?: ReactNode; | ||
| provider?: { | ||
| property?: string; | ||
| type?: string; | ||
|
|
@@ -39,6 +40,7 @@ export const ThemeExample: FunctionComponent<ThemeExample> = ({ | |
| examplePanel, | ||
| snippet, | ||
| snippetLanguage = 'jsx', | ||
| props, | ||
| }) => { | ||
| const { euiTheme } = useEuiTheme(); | ||
| const finalSnippet = | ||
|
|
@@ -71,25 +73,38 @@ export const ThemeExample: FunctionComponent<ThemeExample> = ({ | |
| <EuiText size="s" grow={false}> | ||
| {description} | ||
| </EuiText> | ||
| {props && ( | ||
| <> | ||
| <EuiSpacer /> | ||
| <EuiCodeBlock | ||
| transparentBackground | ||
| paddingSize="none" | ||
| language="ts" | ||
| > | ||
| {props} | ||
| </EuiCodeBlock> | ||
| </> | ||
| )} | ||
| </EuiSplitPanel.Inner> | ||
|
|
||
| {(example || snippet) && ( | ||
| <EuiSplitPanel.Inner> | ||
| <EuiSplitPanel.Inner style={{ overflow: 'hidden' }}> | ||
| <EuiSplitPanel.Outer | ||
| direction="column" | ||
| hasBorder={true} | ||
| hasShadow={false} | ||
| style={{ overflow: 'hidden' }} | ||
| > | ||
| {example && ( | ||
| <EuiSplitPanel.Inner {...examplePanel}> | ||
| {example} | ||
| </EuiSplitPanel.Inner> | ||
| )} | ||
| <EuiSplitPanel.Inner color="subdued"> | ||
| <EuiSplitPanel.Inner paddingSize="none" color="subdued"> | ||
| {finalSnippet && ( | ||
| <EuiCodeBlock | ||
| whiteSpace="pre" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm now forcing these snippets to scroll horizontally because the wrapping causes weird line-breaks making it hard to read. |
||
| isCopyable={true} | ||
| paddingSize="none" | ||
| paddingSize="m" | ||
| transparentBackground={true} | ||
| language={ | ||
| snippetLanguage === 'emotion' ? 'jsx' : snippetLanguage | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,95 +1,73 @@ | ||
| import React from 'react'; | ||
| import { css } from '@emotion/react'; | ||
|
|
||
| import { | ||
| useEuiTheme, | ||
| EuiTitle, | ||
| EuiSpacer, | ||
| EuiColorPickerSwatch, | ||
| EuiFlexItem, | ||
| EuiCodeBlock, | ||
| EuiText, | ||
| EuiPanel, | ||
| } from '../../../../../src'; | ||
|
|
||
| import { ThemeSection } from '../_theme_section'; | ||
| import { getPropsFromComponent } from '../../../services/props/get_props'; | ||
| import { useDebouncedUpdate } from '../hooks'; | ||
|
|
||
| import { ThemeValue } from './_values'; | ||
|
|
||
| import { getPropsFromComponent, EuiThemeFocus } from '../_props'; | ||
| import { EuiThemeFocus } from '../_props'; | ||
|
|
||
| export default ({ onThemeUpdate }) => { | ||
| const { euiTheme } = useEuiTheme(); | ||
| const focus = euiTheme.focus; | ||
| const focusProps = getPropsFromComponent(EuiThemeFocus); | ||
|
|
||
| const updateFocus = (property, value) => { | ||
| onThemeUpdate({ | ||
| focus: { | ||
| [property]: value, | ||
| }, | ||
| }); | ||
| }; | ||
| const [focusClone, updateFocus] = useDebouncedUpdate({ | ||
| property: 'focus', | ||
| value: focus, | ||
| onUpdate: onThemeUpdate, | ||
| }); | ||
|
|
||
| const style = css` | ||
| width: ${euiTheme.size.xl}; | ||
| height: ${euiTheme.size.xl}; | ||
| border-radius: ${euiTheme.border.radius.small}; | ||
| `; | ||
| const focusProps = getPropsFromComponent(EuiThemeFocus); | ||
|
|
||
| return ( | ||
| <div> | ||
| <EuiTitle> | ||
| <EuiText> | ||
| <h2>Focus</h2> | ||
| </EuiTitle> | ||
|
|
||
| <EuiSpacer /> | ||
|
|
||
| <ThemeSection | ||
| code="_EuiThemeFocus" | ||
| description={ | ||
| </EuiText> | ||
| <EuiSpacer size="xl" /> | ||
| <EuiPanel color="subdued"> | ||
| <EuiTitle size="xs"> | ||
| <h3> | ||
| <code>_EuiThemeFocus</code> | ||
| </h3> | ||
| </EuiTitle> | ||
| <EuiSpacer size="s" /> | ||
| <EuiText size="s" grow={false}> | ||
| <p> | ||
| These are general properties that apply to the focus state of | ||
| interactable components. Some components have their own specific | ||
| implementation, but most use these variables. | ||
| </p> | ||
| } | ||
| themeValues={Object.keys(focus).map((prop) => { | ||
| const isColor = prop.toLowerCase().includes('color'); | ||
| if (prop === 'outline') { | ||
| return ( | ||
| <EuiFlexItem key={prop}> | ||
| <ThemeValue | ||
| property="focus" | ||
| type={focusProps[prop]} | ||
| name={prop} | ||
| buttonStyle={[style, focus[prop]]} | ||
| /> | ||
| <EuiSpacer size="xs" /> | ||
| <EuiCodeBlock paddingSize="s" language="css">{`${JSON.stringify( | ||
| focus[prop] | ||
| ).replace(/[{}"]/g, '')};`}</EuiCodeBlock> | ||
| </EuiFlexItem> | ||
| ); | ||
| } | ||
| </EuiText> | ||
|
|
||
| <EuiSpacer /> | ||
|
|
||
| {Object.keys(focusProps).map((prop) => { | ||
| return ( | ||
| <EuiFlexItem key={prop}> | ||
| <ThemeValue | ||
| property="focus" | ||
| name={prop} | ||
| type={focusProps[prop]} | ||
| value={focus[prop]} | ||
| onUpdate={(value) => updateFocus(prop, value)} | ||
| example={ | ||
| isColor ? ( | ||
| <EuiColorPickerSwatch color={focus[prop]} /> | ||
| ) : undefined | ||
| } | ||
| colorProps={ | ||
| isColor ? { showAlpha: true, format: 'rgba' } : undefined | ||
| } | ||
| /> | ||
| </EuiFlexItem> | ||
| <ThemeValue | ||
| key={prop} | ||
| property="focus" | ||
| type={focusProps[prop]} | ||
| name={prop} | ||
| value={focusClone[prop]} | ||
| onUpdate={(value) => updateFocus(prop, value)} | ||
| forceUpdateType="string" | ||
| example={null} | ||
| numberProps={{ | ||
| style: { width: 140 }, | ||
| }} | ||
| /> | ||
| ); | ||
| })} | ||
| /> | ||
| </EuiPanel> | ||
| </div> | ||
| ); | ||
| }; |
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.
Maybe you should list what are the available offset options:
'inset' | 'outset' | 'center' | CSSProperties['outlineOffset']. I'm just thinking what if I'm using this hook without TS?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.
Yeah it starts getting into the territory of having to duplicate prop types. I wonder if there's a way we can do this programmatically instead.
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.
I went ahead and added this one in manually, making space for it in the re-used component
ThemeExample. I'm hoping someone smarter than me will be able to create a re-usable service 😸