From 344bbb251c61f7e3f26db27c544f27ad044f91ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Fern=C3=A1ndez?= Date: Thu, 13 Apr 2023 10:18:45 +0200 Subject: [PATCH] GLDS: Create AutoSaveField component (#61316) --- .../AutoSaveField/AutoSaveField.mdx | 283 ++++++++++ .../AutoSaveField/AutoSaveField.story.tsx | 207 +++++++ .../AutoSaveField/AutoSaveField.test.tsx | 518 ++++++++++++++++++ .../AutoSaveField/AutoSaveField.tsx | 126 +++++ .../grafana-ui/src/components/Forms/Field.tsx | 99 ++-- .../components/InlineToast/InlineToast.tsx | 47 +- packages/grafana-ui/src/components/index.ts | 1 + 7 files changed, 1232 insertions(+), 49 deletions(-) create mode 100644 packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.mdx create mode 100644 packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.story.tsx create mode 100644 packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.test.tsx create mode 100644 packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.tsx diff --git a/packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.mdx b/packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.mdx new file mode 100644 index 00000000000..11b660493e0 --- /dev/null +++ b/packages/grafana-ui/src/components/AutoSaveField/AutoSaveField.mdx @@ -0,0 +1,283 @@ +import { Props, Preview, ArgsTable } from '@storybook/addon-docs/blocks'; +import { AutoSaveField } from './AutoSaveField'; +import { Basic } from './AutoSaveField.story.tsx'; + +# AutoSaveField + +Used for form inputs that should save its content automatically. + +--- + +In this documentation you can find: + +1. [Usage](#usage) +1. [Variants](#variants) +1. [Accessibility](#accessibility) +1. [Content](#content) +1. [Formatting](#formatting) +1. [Behaviours](#behaviours) +1. [Props table](#propstable) +1. [Related](#related) + +
+
+ +## Usage + +
+ +### **Do's** + +- Use in **low-impact** areas within Grafana (examples: team name, display name) +- Include helper text to tell users of the new behaviour for recently modified elements + +
+ +### **Dont's** + +- Do not use if high-impact situations (e.g. saving/changing passwords) +
+
+ +##
Variants + +### 1. Text: + +- The `Input` component allows saving the value of a string. +- This is the main component thought to work as an `AutoSaveField` child. + +```jsx + + {(onChange) => ( + { + onChange(e.currentTarget.value); + //Complete code if needed + }} + /> + )} + +``` + +### 2. TextArea: + +The `TextArea` component allows saving a multi-line text. + +```jsx + + {(onChange) => ( +