-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathButton.ts
More file actions
53 lines (48 loc) · 1.85 KB
/
Button.ts
File metadata and controls
53 lines (48 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { SnapsChildren, StringElement } from '../../component';
import { createSnapComponent } from '../../component';
import type { IconElement } from '../Icon';
import type { ImageElement } from '../Image';
// TODO: Add the `onClick` prop to the `ButtonProps` type.
/**
* The props of the {@link Button} component.
*
* @property children - The text to display on the button.
* @property name - The name of the button. This is used to identify the button
* in the event handler.
* @property type - The type of the button, i.e., `'button'` or `'submit'`.
* Defaults to `'button'`.
* @property variant - The variant of the button, i.e., `'primary'` or
* `'destructive'`. Defaults to `'primary'`.
* @property size - The size of the button. Defaults to `md`.
* @property disabled - Whether the button is disabled. Defaults to `false`.
* @property loading - Whether the button is loading. Defaults to `false`.
* @property form - The name of the form component to associate the button with.
*/
export type ButtonProps = {
children: SnapsChildren<StringElement | IconElement | ImageElement>;
name?: string | undefined;
type?: 'button' | 'submit' | undefined;
variant?: 'primary' | 'destructive' | undefined;
size?: 'sm' | 'md' | undefined;
disabled?: boolean | undefined;
loading?: boolean | undefined;
form?: string | undefined;
};
const TYPE = 'Button';
/**
* A button component, which is used to create a clickable button.
*
* @param props - The props of the component.
* @param props.children - The text to display on the button. This should be a
* string or an array of strings.
* @returns A button element.
* @example
* <Button name="my-button">Click me</Button>
*/
export const Button = createSnapComponent<ButtonProps, typeof TYPE>(TYPE);
/**
* A button element.
*
* @see Button
*/
export type ButtonElement = ReturnType<typeof Button>;