Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src-docs/src/views/inline_edit/inline_edit_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,72 @@ import {
EuiInlineEditTitle,
} from '../../../../src';

import { inlineEditTextConfig, inlineEditTitleConfig } from './playground';

import InlineEditText from './inline_edit_text';
const inlineEditTextSource = require('!!raw-loader!./inline_edit_text');
const inlineEditTextSnippet = `<EuiInlineEditText
inputAriaLabel="Edit text inline"
defaultValue="Hello World!"
/>`;

import InlineEditTitle from './inline_edit_title';
const inlineEditTitleSource = require('!!raw-loader!./inline_edit_title');
const inlineEditTitleSnippet = `<EuiInlineEditTitle
inputAriaLabel="Edit title inline"
defaultValue="Hello World (but as a title)!"
heading="h3"
/>`;

import InlineEditModeProps from './inline_edit_mode_props';
const inlineEditModePropsSource = require('!!raw-loader!./inline_edit_mode_props');
const inlineEditModePropsSnippet = `<EuiInlineEditText
inputAriaLabel="Edit text inline for readMode and editMode props"
defaultValue="This inline edit component has been customized!"
size="m"
readModeProps={{
color: 'primary',
iconSide: 'left',
}}
editModeProps={{
inputProps: {
prepend: 'Prepend example',
},
formRowProps: {
helpText: 'Example help text',
},
saveButtonProps: {
color: 'primary',
},
cancelButtonProps: {
display: 'empty',
},
}}
/>`;

import InlineEditSave from './inline_edit_save';
const inlineEditSaveSource = require('!!raw-loader!././inline_edit_save');
const inlineEditModeSaveSnippet = `<EuiInlineEditText
inputAriaLabel="Edit text inline"
defaultValue={defaultInlineEditValue}
onSave={(newInlineEditValue: string) => {
localStorage.setItem('inlineEditValue', newInlineEditValue);
}}
/>`;

import InlineEditValidation from './inline_edit_validation';
const inlineEditValidationSource = require('!!raw-loader!././inline_edit_validation');
const inlineEditValidationSnippet = `<EuiInlineEditText
inputAriaLabel="This input will validate on save"
defaultValue={defaultInlineEditValue}
editModeProps={{
formRowProps: { error: errors },
cancelButtonProps: { onClick: () => setErrors([]) },
}}
isInvalid={isInvalid}
isLoading={isLoading}
onSave={onSave}
/>`;

export const InlineEditExample = {
title: 'Inline edit',
Expand Down Expand Up @@ -60,6 +112,8 @@ export const InlineEditExample = {
],
demo: <InlineEditText />,
props: { EuiInlineEditText },
snippet: inlineEditTextSnippet,
playground: inlineEditTextConfig,
},
{
title: 'Display and edit headings and titles',
Expand All @@ -80,6 +134,8 @@ export const InlineEditExample = {
],
demo: <InlineEditTitle />,
props: { EuiInlineEditTitle },
snippet: inlineEditTitleSnippet,
playground: inlineEditTitleConfig,
},
{
title: 'Saving edited text',
Expand All @@ -98,6 +154,7 @@ export const InlineEditExample = {
},
],
demo: <InlineEditSave />,
snippet: inlineEditModeSaveSnippet,
},
{
title: 'Validating edited text',
Expand Down Expand Up @@ -129,6 +186,7 @@ export const InlineEditExample = {
},
],
demo: <InlineEditValidation />,
snippet: inlineEditValidationSnippet,
},
{
title: 'Customizing read and edit modes',
Expand Down Expand Up @@ -187,6 +245,7 @@ export const InlineEditExample = {
},
],
demo: <InlineEditModeProps />,
snippet: inlineEditModePropsSnippet,
},
],
};
105 changes: 105 additions & 0 deletions src-docs/src/views/inline_edit/playground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { PropTypes } from 'react-view';
import {
EuiInlineEditText,
EuiInlineEditTitle,
} from '../../../../src/components';
import {
propUtilityForPlayground,
dummyFunction,
simulateFunction,
} from '../../services/playground';

const commonPropsToUse = (propsToUse) => {
propsToUse.inputAriaLabel = {
...propsToUse.inputAriaLabel,
value: 'Edit text inline',
type: PropTypes.String,
};

propsToUse.isLoading = {
type: PropTypes.Boolean,
};

propsToUse.isInvalid = {
type: PropTypes.Boolean,
};

propsToUse.startWithEditOpen = {
type: PropTypes.Boolean,
};

propsToUse.onSave = simulateFunction(propsToUse.onSave);

return propsToUse;
};

export const inlineEditTextConfig = () => {
const docgenInfo = Array.isArray(EuiInlineEditText.__docgenInfo)
? EuiInlineEditText.__docgenInfo[0]
: EuiInlineEditText.__docgenInfo;
let propsToUse = propUtilityForPlayground(docgenInfo.props);

propsToUse.defaultValue = {
...propsToUse.defaultValue,
value: 'Hello! You are editing text content!',
type: PropTypes.String,
};

propsToUse = commonPropsToUse(propsToUse);

return {
config: {
componentName: 'EuiInlineEditText',
props: propsToUse,
scope: {
EuiInlineEditText,
},
imports: {
'@elastic/eui': {
named: ['EuiInlineEditText'],
},
},
customProps: {
onSave: dummyFunction,
},
},
};
};

export const inlineEditTitleConfig = () => {
const docgenInfo = Array.isArray(EuiInlineEditTitle.__docgenInfo)
? EuiInlineEditTitle.__docgenInfo[0]
: EuiInlineEditTitle.__docgenInfo;
let propsToUse = propUtilityForPlayground(docgenInfo.props);

propsToUse.defaultValue = {
...propsToUse.defaultValue,
value: 'Hello! You are editing a title!',
type: PropTypes.String,
};

propsToUse.heading = {
...propsToUse.heading,
value: 'h2',
Copy link
Contributor

@cee-chen cee-chen May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the playground flyout is using a h3 so for its title, so to be semantically 'correct' within the context of the playground, let's use h4:

Suggested change
value: 'h2',
value: 'h4',

Although, this also makes me wonder if we should allow setting a span enum for text that should look like a title but aren't actually semantic headings. Thoughts, @1Copenut?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call. Having a generic span would be helpful. Consumers will have more choice to select the right semantic (or not) container for their use case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Trevor! @breehall let's go ahead and add a span option to the source component as part of this PR. We can change the playground example to a h4 or span, up to you.

};

propsToUse = commonPropsToUse(propsToUse);

return {
config: {
componentName: 'EuiInlineEditTitle',
props: propsToUse,
scope: {
EuiInlineEditTitle,
},
imports: {
'@elastic/eui': {
named: ['EuiInlineEditTitle'],
},
},
customProps: {
onSave: dummyFunction,
},
},
};
};