diff --git a/packages/react-core/src/components/TextInput/examples/TextInput.md b/packages/react-core/src/components/TextInput/examples/TextInput.md index 8618439b399..6702d09ce38 100644 --- a/packages/react-core/src/components/TextInput/examples/TextInput.md +++ b/packages/react-core/src/components/TextInput/examples/TextInput.md @@ -9,265 +9,42 @@ propComponents: ['TextInput'] ### Basic -```js -import React from 'react'; -import { TextInput } from '@patternfly/react-core'; - -class SimpleTextInput extends React.Component { - constructor(props) { - super(props); - this.state = { - value: '' - }; - this.handleTextInputChange = value => { - this.setState({ value }); - }; - } - - render() { - const { value } = this.state; - - return ( - - ); - } -} +```ts file="./TextInputBasic.tsx" ``` ### Disabled -```js -import React from 'react'; -import { TextInput } from '@patternfly/react-core'; - -; +```ts file="./TextInputDisabled.tsx" ``` ### Truncated on Left -```js -import React from 'react'; -import { TextInput } from '@patternfly/react-core'; - -class LeftTruncatedTextInput extends React.Component { - -constructor(props) { - super(props); - this.state = { - value: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' - }; - this.handleTextInputChange = value => { - this.setState({ value }); - }; - } - - render() { - const { value } = this.state; - return ( - - ); - } -} +```ts file="./TextInputLeftTruncated.tsx" ``` ### Read only -```js -import React from 'react'; -import { Checkbox, TextInput } from '@patternfly/react-core'; - -const ReadOnlyTextArea = () => { - const [isPlainChecked, setIsPlainChecked] = React.useState(false); - - return ( - -
- setIsPlainChecked(checked)} - /> -
- -
- ); -}; +```ts file="./TextInputReadOnly.tsx" ``` ### Invalid -```js -import React from 'react'; -import { TextInput, ValidatedOptions } from '@patternfly/react-core'; - -class InvalidTextInput extends React.Component { - constructor(props) { - super(props); - this.state = { - value: '' - }; - this.handleInvalidTextInputChange = value => { - this.setState({ value }); - }; - } - - render() { - const { value } = this.state; - - return ( - - ); - } -} +```ts file="./TextInputInvalid.tsx" ``` ### Select text using ref -```js -import React from 'react'; -import { TextInput } from '@patternfly/react-core'; - -TextInputSelectAll = () => { - const [value, setValue] = React.useState('select all on click'); - const ref = React.useRef(null); - return ( - ref && ref.current && ref.current.select()} - onChange={value => setValue(value)} - aria-label="select-all" - /> - ); -}; +```ts file="./TextInputSelectUsingRef.tsx" ``` ### Icon variants -```js -import React from 'react'; -import { TextInput } from '@patternfly/react-core'; - -SimpleTextInput = () => { - const [calendar, setCalendar] = React.useState(''); - const [clock, setClock] = React.useState(''); - const [custom, setCustom] = React.useState(''); - - return ( - <> - setCalendar(value)} - aria-label="text input example" - /> -
-
- setClock(value)} - aria-label="text input example" - /> -
-
- setCustom(value)} - aria-label="text input example" - /> - - ); -}; +```ts file="./TextInputIcon.tsx" ``` ### Icon sprite variants **Note:** The icons for the success, invalid, calendar, etc. variations in form control elements are applied as background images to the form element. By default, the image URLs for these icons are data URIs. However, there may be cases where data URIs are not ideal, such as in an application with a content security policy that disallows data URIs for security reasons. The `isIconSprite` variation changes the icon source to an external SVG file that serves as a sprite for all of the supported icons. -```js isBeta -import React from 'react'; -import { TextInput } from '@patternfly/react-core'; - -IconSpriteTextInputs = () => { - const [success, setSuccess] = React.useState(''); - const [warning, setWarning] = React.useState(''); - const [error, setError] = React.useState(''); - const [calendar, setCalendar] = React.useState(''); - const [clock, setClock] = React.useState(''); - - return ( - <> - setSuccess(value)} - aria-label="success icon sprite text input example" - /> -
-
- setWarning(value)} - aria-label="warning icon sprite text input example" - /> -
-
- setError(value)} - aria-label="error icon sprite text input example" - /> -
-
- setCalendar(value)} - aria-label="calendar icon sprite text input example" - /> -
-
- setClock(value)} - aria-label="clock icon sprite text input example" - /> - - ); -}; +```ts isBeta file="./TextInputIconSprite.tsx" ``` diff --git a/packages/react-core/src/components/TextInput/examples/TextInputBasic.tsx b/packages/react-core/src/components/TextInput/examples/TextInputBasic.tsx new file mode 100644 index 00000000000..5fdefea7b9d --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputBasic.tsx @@ -0,0 +1,7 @@ +import React from 'react'; +import { TextInput } from '@patternfly/react-core'; + +export const TextInputBasic: React.FunctionComponent = () => { + const [value, setValue] = React.useState(''); + return setValue(value)} aria-label="text input example" />; +}; diff --git a/packages/react-core/src/components/TextInput/examples/TextInputDisabled.tsx b/packages/react-core/src/components/TextInput/examples/TextInputDisabled.tsx new file mode 100644 index 00000000000..52580a22062 --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputDisabled.tsx @@ -0,0 +1,6 @@ +import React from 'react'; +import { TextInput } from '@patternfly/react-core'; + +export const TextInputBasic: React.FunctionComponent = () => ( + +); diff --git a/packages/react-core/src/components/TextInput/examples/TextInputIcon.tsx b/packages/react-core/src/components/TextInput/examples/TextInputIcon.tsx new file mode 100644 index 00000000000..4ac710553fe --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputIcon.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { TextInput } from '@patternfly/react-core'; + +export const TextInputIcon: React.FunctionComponent = () => { + const [calendar, setCalendar] = React.useState(''); + const [clock, setClock] = React.useState(''); + const [custom, setCustom] = React.useState(''); + + return ( + <> + setCalendar(value)} + aria-label="text input example" + /> +
+
+ setClock(value)} + aria-label="text input example" + /> +
+
+ setCustom(value)} + aria-label="text input example" + /> + + ); +}; diff --git a/packages/react-core/src/components/TextInput/examples/TextInputIconSprite.tsx b/packages/react-core/src/components/TextInput/examples/TextInputIconSprite.tsx new file mode 100644 index 00000000000..89b39fc6406 --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputIconSprite.tsx @@ -0,0 +1,63 @@ +import React from 'react'; +import { TextInput } from '@patternfly/react-core'; + +export const TextInputIconSprite: React.FunctionComponent = () => { + const [calendar, setCalendar] = React.useState(''); + const [clock, setClock] = React.useState(''); + const [success, setSuccess] = React.useState(''); + const [warning, setWarning] = React.useState(''); + const [error, setError] = React.useState(''); + + return ( + <> + setSuccess(value)} + aria-label="success icon sprite text input example" + /> +
+
+ setWarning(value)} + aria-label="warning icon sprite text input example" + /> +
+
+ setError(value)} + aria-label="error icon sprite text input example" + /> +
+
+ setCalendar(value)} + aria-label="calendar icon sprite text input example" + /> +
+
+ setClock(value)} + aria-label="clock icon sprite text input example" + /> + + ); +}; diff --git a/packages/react-core/src/components/TextInput/examples/TextInputInvalid.tsx b/packages/react-core/src/components/TextInput/examples/TextInputInvalid.tsx new file mode 100644 index 00000000000..b76a0e78463 --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputInvalid.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { TextInput, ValidatedOptions } from '@patternfly/react-core'; + +export const TextInputInvalid: React.FunctionComponent = () => { + const [value, setValue] = React.useState(''); + return ( + setValue(value)} + isRequired + validated={ValidatedOptions.error} + type="text" + aria-label="invalid text input example" + /> + ); +}; diff --git a/packages/react-core/src/components/TextInput/examples/TextInputLeftTruncated.tsx b/packages/react-core/src/components/TextInput/examples/TextInputLeftTruncated.tsx new file mode 100644 index 00000000000..e1c9ab72b99 --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputLeftTruncated.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { TextInput } from '@patternfly/react-core'; + +export const LeftTruncatedTextInput: React.FunctionComponent = () => { + const [value, setValue] = React.useState( + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' + ); + return ( + setValue(value)} + aria-label="left-truncated text input example" + /> + ); +}; diff --git a/packages/react-core/src/components/TextInput/examples/TextInputReadOnly.tsx b/packages/react-core/src/components/TextInput/examples/TextInputReadOnly.tsx new file mode 100644 index 00000000000..f951f984214 --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputReadOnly.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { Checkbox, TextInput } from '@patternfly/react-core'; + +export const TextInputReadOnly: React.FunctionComponent = () => { + const [isPlainChecked, setIsPlainChecked] = React.useState(false); + return ( + <> +
+ setIsPlainChecked(checked)} + /> +
+ + + ); +}; diff --git a/packages/react-core/src/components/TextInput/examples/TextInputSelectUsingRef.tsx b/packages/react-core/src/components/TextInput/examples/TextInputSelectUsingRef.tsx new file mode 100644 index 00000000000..b5bf30d7aa3 --- /dev/null +++ b/packages/react-core/src/components/TextInput/examples/TextInputSelectUsingRef.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { TextInput } from '@patternfly/react-core'; + +export const TextInputSelectUsingRef: React.FunctionComponent = () => { + const [value, setValue] = React.useState('select all on click'); + const ref = React.useRef(null); + return ( + ref?.current?.select()} + onChange={value => setValue(value)} + aria-label="select-all" + /> + ); +};