setup form
This commit is contained in:
3010
8.1.4/button-with-textfield/package-lock.json
generated
Normal file
3010
8.1.4/button-with-textfield/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -21,4 +21,4 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,35 +2,62 @@ import React from 'react';
|
|||||||
import { PanelProps } from '@grafana/data';
|
import { PanelProps } from '@grafana/data';
|
||||||
import { SimpleOptions } from 'types';
|
import { SimpleOptions } from 'types';
|
||||||
import { css, cx } from 'emotion';
|
import { css, cx } from 'emotion';
|
||||||
import { stylesFactory } from '@grafana/ui';
|
import { stylesFactory, Field, Input, Form, Button } from '@grafana/ui';
|
||||||
|
|
||||||
interface Props extends PanelProps<SimpleOptions> {}
|
interface Props extends PanelProps<SimpleOptions> {}
|
||||||
|
|
||||||
export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) => {
|
export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) => {
|
||||||
const styles = getStyles();
|
const styles = getStyles();
|
||||||
let form;
|
let form;
|
||||||
|
|
||||||
|
interface numberInput {
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
let sendValue: numberInput = { value: options.default };
|
||||||
function FormWithInput() {
|
function FormWithInput() {
|
||||||
return (
|
return (
|
||||||
<form onSubmit={sendRequest} className={styles.form}>
|
<Form
|
||||||
<label>
|
defaultValues={sendValue}
|
||||||
{options.text}:
|
onSubmit={(userinput: numberInput) => {
|
||||||
<input type="number" name="testinput" />
|
console.log(userinput.value);
|
||||||
</label>
|
sendRequest(userinput.value);
|
||||||
<input type="submit" value="Send" />
|
}}
|
||||||
</form>
|
>
|
||||||
|
{({ register, errors }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Field label={options.text}>
|
||||||
|
<Input css={undefined} id="test" type="number" step={0.01} {...register('value')} />
|
||||||
|
</Field>
|
||||||
|
<Button type="submit">Test Button</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function FormWithoutInput() {
|
function FormWithoutInput() {
|
||||||
return (
|
return (
|
||||||
<form>
|
<Form
|
||||||
<input type="submit" value="Send" />
|
defaultValues={sendValue}
|
||||||
</form>
|
onSubmit={(userinput: numberInput) => {
|
||||||
|
console.log(userinput.value);
|
||||||
|
sendRequest(userinput.value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{({ register, errors }) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button type="submit">Test Button</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendRequest(event: any) {
|
function sendRequest(event: number) {
|
||||||
fetch(options.url + { event }).then(() => alert('It worked'));
|
//console.log(event);
|
||||||
|
fetch(options.url + event).then(response => console.log(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.showInputField) {
|
if (options.showInputField) {
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ export const plugin = new PanelPlugin<SimpleOptions>(SimplePanel).setPanelOption
|
|||||||
name: 'Destination URL',
|
name: 'Destination URL',
|
||||||
description: 'The destination URL for the request'
|
description: 'The destination URL for the request'
|
||||||
})
|
})
|
||||||
|
.addNumberInput({
|
||||||
|
path: 'default',
|
||||||
|
name: 'default number',
|
||||||
|
description: 'a default number for the input'
|
||||||
|
})
|
||||||
/* .addRadio({
|
/* .addRadio({
|
||||||
path: 'seriesCountSize',
|
path: 'seriesCountSize',
|
||||||
defaultValue: 'sm',
|
defaultValue: 'sm',
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ export interface SimpleOptions {
|
|||||||
text: string;
|
text: string;
|
||||||
showInputField: boolean;
|
showInputField: boolean;
|
||||||
url: string;
|
url: string;
|
||||||
|
default: number;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user