diff --git a/.eslintrc.json b/.eslintrc.json index a6dcec8..b910b7d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -84,7 +84,6 @@ ], "no-unused-labels": "error", "no-var": "error", - "object-shorthand": "error", "one-var": ["error", "never"], "prefer-const": "error", "radix": ["error", "as-needed"], diff --git a/packages/module/patternfly-docs/content/examples/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIcon.md b/packages/module/patternfly-docs/content/examples/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIcon.md new file mode 100644 index 0000000..65aa3ea --- /dev/null +++ b/packages/module/patternfly-docs/content/examples/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIcon.md @@ -0,0 +1,26 @@ +--- +# Sidenav top-level section +# should be the same for all markdown files +section: AI-infra-ui-components +# Sidenav secondary level section +# should be the same for all markdown files +id: FieldGroupHelpLabelIcon +# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) +source: react +# If you use typescript, the name of the interface to display props for +# These are found through the sourceProps function provided in patternfly-docs.source.js +propComponents: ['FieldGroupHelpLabelIcon'] +--- + +import { FieldGroupHelpLabelIcon } from "@patternfly/ai-infra-ui-components"; + +Note: this component documents the API and enhances the [existing FieldGroupHelpLabelIcon](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/components/FieldGroupHelpLabelIcon.tsx) component from odh-dashboard. It can be imported from [@patternfly/ai-infra-ui-components](https://www.npmjs.com/package/@patternfly/AI-infra-ui-components). Alternatively, it can be used within the odh-dashboard via the import: `~/components/FieldGroupHelpLabelIcon` + +This AI-infra-ui-components version of `FieldGroupHelpLabelIcon` uses internally a new PatternFly's `FormGroupLabelHelp` component instead of odh-dasboard's `DashboardPopupIconButton`. +**We recommend** replacing occurences of `} aria-label="More info"/>` with ``. + +### Example + +```js file="./FieldGroupHelpLabelIconBasic.tsx" + +``` diff --git a/packages/module/patternfly-docs/content/examples/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIconBasic.tsx b/packages/module/patternfly-docs/content/examples/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIconBasic.tsx new file mode 100644 index 0000000..cc68d4f --- /dev/null +++ b/packages/module/patternfly-docs/content/examples/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIconBasic.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import { FieldGroupHelpLabelIcon } from '@patternfly/ai-infra-ui-components'; +import { Form, FormGroup, TextInput } from '@patternfly/react-core'; + +export const FieldGroupHelpLabelIconBasic: React.FunctionComponent = () => { + const [name, setName] = React.useState(''); + + const handleNameChange = (_event, name: string) => { + setName(name); + }; + + return ( +
+ } + isRequired + fieldId="simple-form-name" + > + + +
+ ); +}; diff --git a/packages/module/patternfly-docs/content/examples/K8sNameDescriptionField/K8sNameDescriptionField.md b/packages/module/patternfly-docs/content/examples/K8sNameDescriptionField/K8sNameDescriptionField.md new file mode 100644 index 0000000..264fad9 --- /dev/null +++ b/packages/module/patternfly-docs/content/examples/K8sNameDescriptionField/K8sNameDescriptionField.md @@ -0,0 +1,25 @@ +--- +# Sidenav top-level section +# should be the same for all markdown files +section: AI-infra-ui-components +# Sidenav secondary level section +# should be the same for all markdown files +id: K8sNameDescriptionField +# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) +source: react +# If you use typescript, the name of the interface to display props for +# These are found through the sourceProps function provided in patternfly-docs.source.js +propComponents: ['K8sNameDescriptionField'] +--- + +import { K8sNameDescriptionField } from "@patternfly/ai-infra-ui-components"; + +Note: this component documents the API and enhances the [existing K8sNameDescriptionField](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/concepts/k8s/K8sNameDescriptionField/K8sNameDescriptionField.tsx) component from odh-dashboard. It can be imported from [@patternfly/ai-infra-ui-components](https://www.npmjs.com/package/@patternfly/AI-infra-ui-components). Alternatively, it can be used within the odh-dashboard via the import: `~/concepts/k8s/K8sNameDescriptionField/K8sNameDescriptionField` + +In the following examples, sample `data` and `onDataChange` props are provided. To obtain these props properly, you should use the [useK8sNameDescriptionFieldData hook](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/concepts/k8s/K8sNameDescriptionField/K8sNameDescriptionField.tsx#L23). + +### Example + +```js file="./K8sNameDescriptionFieldBasic.tsx" + +``` diff --git a/packages/module/patternfly-docs/content/examples/K8sNameDescriptionField/K8sNameDescriptionFieldBasic.tsx b/packages/module/patternfly-docs/content/examples/K8sNameDescriptionField/K8sNameDescriptionFieldBasic.tsx new file mode 100644 index 0000000..c7df4d2 --- /dev/null +++ b/packages/module/patternfly-docs/content/examples/K8sNameDescriptionField/K8sNameDescriptionFieldBasic.tsx @@ -0,0 +1,62 @@ +import React from 'react'; +import { + K8sNameDescriptionField, + K8sNameDescriptionFieldData, + UseK8sNameDescriptionFieldData +} from '@patternfly/ai-infra-ui-components'; +import { Checkbox, Form } from '@patternfly/react-core'; + +export const K8sNameDescriptionFieldBasic: React.FunctionComponent = () => { + const [name, setName] = React.useState(''); + const [resourceName, setResourceName] = React.useState(null); + const [description, setDescription] = React.useState(''); + const [showDescription, setShowDescription] = React.useState(true); + + const createResourceName = (name: string) => name.toLowerCase().replaceAll(' ', '-'); + const RESOURCE_NAME_MAX_LENGTH = 30; + + const data: K8sNameDescriptionFieldData = { + name: name, + description: description, + k8sName: { + value: resourceName ?? createResourceName(name), + state: { + immutable: false, + invalidCharacters: resourceName !== null && resourceName.includes(' '), + invalidLength: resourceName !== null && resourceName.length > RESOURCE_NAME_MAX_LENGTH, + safePrefix: undefined, + maxLength: RESOURCE_NAME_MAX_LENGTH, + touched: false + } + } + }; + + const onDataChange: UseK8sNameDescriptionFieldData['onDataChange'] = (key, value) => { + if (key === 'name') { + setName(value); + } else if (key === 'k8sName') { + setResourceName(value); + } else if (key === 'description') { + setDescription(value); + } + }; + + return ( + <> + setShowDescription((checked) => !checked)} + checked={showDescription} + label="Show description" + /> +
+ + + + ); +}; diff --git a/packages/module/src/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIcon.tsx b/packages/module/src/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIcon.tsx new file mode 100644 index 0000000..2a9bc23 --- /dev/null +++ b/packages/module/src/FieldGroupHelpLabelIcon/FieldGroupHelpLabelIcon.tsx @@ -0,0 +1,19 @@ +import * as React from 'react'; +import { Popover, FormGroupLabelHelp } from '@patternfly/react-core'; + +export type FieldGroupHelpLabelIconProps = { + /** Body content of the popover. Should provide additional context for a form field. + * If you want to close the popover after an action within the body content, you can provide a function which will receive a callback as an argument to hide the popover, i.e. bodyContent={hide => {' '} + + + + + )} + + + {showDescription && ( + +