diff --git a/packages/react-core/src/components/Button/examples/Button.md b/packages/react-core/src/components/Button/examples/Button.md index 337b7b04914..07463ecab26 100644 --- a/packages/react-core/src/components/Button/examples/Button.md +++ b/packages/react-core/src/components/Button/examples/Button.md @@ -17,350 +17,65 @@ import { Link } from '@reach/router'; ### Variations -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; -import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon'; -import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; -import ExternalLinkSquareAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-square-alt-icon'; -import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon'; - - - {' '} - {' '} - {' '} - {' '} - {' '} - -
-
- {' '} - {' '} - {' '} - -
-
- -
-
- {' '} - -
; +```ts file="./ButtonVariations.tsx" ``` ### Disabled -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; -import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon'; -import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; - - - {' '} - {' '} - {' '} - {' '} - {' '} - -
-
- {' '} - {' '} - {' '} - {' '} - -
; +```ts file="./ButtonDisabled.tsx" ``` ### Aria disabled -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; -import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon'; -import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; - - - {' '} - {' '} - {' '} - {' '} - {' '} - -
-
- {' '} - {' '} - {' '} - {' '} - -
; +```ts file="./ButtonAriaDisabled.tsx" ``` ### Aria disabled button with tooltip -```js -import React from 'react'; -import { Button, Tooltip } from '@patternfly/react-core'; - - - -; +```ts file="./ButtonAriaDisabledTooltip.tsx" ``` ### Aria disabled link as button with tooltip -```js -import React from 'react'; -import { Button, Tooltip } from '@patternfly/react-core'; - - - -; +```ts file="./ButtonAriaDisabledLinkTooltip.tsx" ``` ### Links as buttons -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; - - - {' '} - {' '} - {' '} - -; +```ts file="./ButtonLinks.tsx" ``` ### Inline link as span -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; - -InlineLinkAsSpan = () => { - const handleKeydown = evt => { - const { keyCode } = evt; - const isEnterOrSpaceKey = keyCode === 13 || keyCode === 32; - - if (isEnterOrSpaceKey) { - evt.preventDefault(); - alert(`${keyCode === 13 ? 'Enter' : 'Space'} key default behavior stopped by onKeyDown`); - } - }; - - return ( - <> -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Sed hendrerit nisi in cursus maximus. Ut malesuada nisi turpis, in condimentum velit elementum non. -

- -
- -

- Note that using a span as a button does not fire the onclick event for Enter or Space keys. - Pressing the Enter or Space keys on the inline link as span above demonstrates this by triggering an alert. -

- - ); -}; +```ts file="./ButtonInlineSpanLink.tsx" ``` ### Block level -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; - -; +```ts file="./ButtonBlock.tsx" ``` ### Types -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; - - - -; +```ts file="./ButtonTypes.tsx" ``` ### Small -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; - - - {' '} - {' '} - {' '} - {' '} - -
-
-
; +```ts file="./ButtonSmall.tsx" ``` ### Call to action -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; -import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon'; - - - {' '} - {' '} - {' '} - -
-
-
; +```ts file="./ButtonCallToAction.tsx" ``` ### Progress -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; - -ButtonProgressVariants = () => { - const [isPrimaryLoading, setIsPrimaryLoading] = React.useState(true); - const [isSecondaryLoading, setIsSecondaryLoading] = React.useState(true); - const extraPrimaryProps = {}; - if (isPrimaryLoading) { - extraPrimaryProps.spinnerAriaValueText = 'Loading'; - } - const extraSecondaryProps = {}; - if (isSecondaryLoading) { - extraSecondaryProps.spinnerAriaValueText = 'Loading'; - } - - return ( - - {' '} - -
-
-
- ); -}; +```ts file="./ButtonProgress.tsx" ``` ### Router link -```js -import React from 'react'; -import { Button } from '@patternfly/react-core'; -import { Link } from '@reach/router'; - +```ts file="./ButtonRouterLink.tsx" ``` - diff --git a/packages/react-core/src/components/Button/examples/ButtonAriaDisabled.tsx b/packages/react-core/src/components/Button/examples/ButtonAriaDisabled.tsx new file mode 100644 index 00000000000..43bce4e68f8 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonAriaDisabled.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; +import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon'; +import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; + +export const ButtonAriaDisabled: React.FunctionComponent = () => ( + + + + + + + + + + + + + + + + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonAriaDisabledLinkTooltip.tsx b/packages/react-core/src/components/Button/examples/ButtonAriaDisabledLinkTooltip.tsx new file mode 100644 index 00000000000..68acdfe15ec --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonAriaDisabledLinkTooltip.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { Button, Tooltip } from '@patternfly/react-core'; + +export const ButtonAriaDisabledLinkTooltip: React.FunctionComponent = () => ( + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonAriaDisabledTooltip.tsx b/packages/react-core/src/components/Button/examples/ButtonAriaDisabledTooltip.tsx new file mode 100644 index 00000000000..24c35bb1965 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonAriaDisabledTooltip.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { Button, Tooltip } from '@patternfly/react-core'; + +export const ButtonAriaDisabledTooltip: React.FunctionComponent = () => ( + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonBlock.tsx b/packages/react-core/src/components/Button/examples/ButtonBlock.tsx new file mode 100644 index 00000000000..69d484378df --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonBlock.tsx @@ -0,0 +1,4 @@ +import React from 'react'; +import { Button } from '@patternfly/react-core'; + +export const ButtonBlock: React.FunctionComponent = () => ; diff --git a/packages/react-core/src/components/Button/examples/ButtonCallToAction.tsx b/packages/react-core/src/components/Button/examples/ButtonCallToAction.tsx new file mode 100644 index 00000000000..efdf1ffcd35 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonCallToAction.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; +import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-icon'; + +export const ButtonCallToAction: React.FunctionComponent = () => ( + + + + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonDisabled.tsx b/packages/react-core/src/components/Button/examples/ButtonDisabled.tsx new file mode 100644 index 00000000000..b9d421240c1 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonDisabled.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; +import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon'; +import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; + +export const ButtonDisabled: React.FunctionComponent = () => ( + + + + + + + + + + + + + + + + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonInlineSpanLink.tsx b/packages/react-core/src/components/Button/examples/ButtonInlineSpanLink.tsx new file mode 100644 index 00000000000..25ac07115bc --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonInlineSpanLink.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { Button } from '@patternfly/react-core'; + +const handleKeydown = (event: React.KeyboardEvent) => { + const { key } = event; + const isEnterKey: boolean = key === 'Enter'; + const isEnterOrSpaceKey: boolean = isEnterKey || key === 'Space'; + + if (isEnterOrSpaceKey) { + event.preventDefault(); + alert(`${isEnterKey ? 'Enter' : 'Space'} key default behavior stopped by onKeyDown`); + } +}; + +export const ButtonInlineSpanLink: React.FunctionComponent = () => ( + <> +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. + + Sed hendrerit nisi in cursus maximus. Ut malesuada nisi turpis, in condimentum velit elementum non. +

+ +
+ +

+ Note that using a span as a button does not fire the onclick event for Enter or Space keys. + + Pressing the Enter or Space keys on the inline link as span above demonstrates this by triggering an alert. +

+ +); diff --git a/packages/react-core/src/components/Button/examples/ButtonLinks.tsx b/packages/react-core/src/components/Button/examples/ButtonLinks.tsx new file mode 100644 index 00000000000..c6f7334e31f --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonLinks.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; + +export const ButtonLinks: React.FunctionComponent = () => ( + + + + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonProgress.tsx b/packages/react-core/src/components/Button/examples/ButtonProgress.tsx new file mode 100644 index 00000000000..a0243494431 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonProgress.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; + +export const ButtonProgress: React.FunctionComponent = () => { + const [isPrimaryLoading, setIsPrimaryLoading] = React.useState(true); + const [isSecondaryLoading, setIsSecondaryLoading] = React.useState(true); + + return ( + + + + + + ); +}; diff --git a/packages/react-core/src/components/Button/examples/ButtonRouterLink.tsx b/packages/react-core/src/components/Button/examples/ButtonRouterLink.tsx new file mode 100644 index 00000000000..20f4246de17 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonRouterLink.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { Button } from '@patternfly/react-core'; +import { Link } from '@reach/router'; + +export const ButtonRouterLink: React.FunctionComponent = () => ( + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonSmall.tsx b/packages/react-core/src/components/Button/examples/ButtonSmall.tsx new file mode 100644 index 00000000000..26e21960fe5 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonSmall.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; + +export const ButtonSmall: React.FunctionComponent = () => ( + + + + + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonTypes.tsx b/packages/react-core/src/components/Button/examples/ButtonTypes.tsx new file mode 100644 index 00000000000..51cb5ae3f9d --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonTypes.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; + +export const ButtonTypes: React.FunctionComponent = () => ( + + + + + +); diff --git a/packages/react-core/src/components/Button/examples/ButtonVariations.tsx b/packages/react-core/src/components/Button/examples/ButtonVariations.tsx new file mode 100644 index 00000000000..2bcba2abca3 --- /dev/null +++ b/packages/react-core/src/components/Button/examples/ButtonVariations.tsx @@ -0,0 +1,47 @@ +import React from 'react'; +import { Button, Flex } from '@patternfly/react-core'; +import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon'; +import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; +import ExternalLinkSquareAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-square-alt-icon'; +import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon'; + +export const ButtonVariations: React.FunctionComponent = () => ( + + + + + + + + + + + + + + + + + + + + + + + + +);