Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit 7b36edc

Browse files
csabageisztFlorian-Schoenherr
authored andcommitted
feat(types): add form field type definitions
Add type definitions for Checkbox, Radio, Select, Slider, Switch, and Textarea. Change single line comments to block comments and add missing props in TextField definition.
1 parent 31e1ae2 commit 7b36edc

File tree

8 files changed

+293
-32
lines changed

8 files changed

+293
-32
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { SvelteComponent } from './shared';
2+
3+
export interface CheckboxProps<T extends string | number | string[] = string[]> {
4+
/** Classes to add to checkbox wrapper. */
5+
class?: string;
6+
/** Color class of the checkbox when checked or indeterminate. */
7+
color?: string;
8+
/** Whether the checkbox is selected. */
9+
checked?: boolean;
10+
/** Whether checkbox is indeterminate. */
11+
indeterminate?: boolean;
12+
/** Whether checkbox is disabled. */
13+
disabled?: boolean;
14+
/** Value of the checkbox. */
15+
value?: T;
16+
/** Bind checkbox to a group. */
17+
group?: T;
18+
/** Id of the checkbox. Defaults to a random uid. */
19+
id?: string;
20+
/** Styles to add to checkbox wrapper. */
21+
style?: string;
22+
/** Reference to checkbox input element in the DOM. */
23+
inputElement?: Element;
24+
}
25+
26+
declare class Checkbox extends SvelteComponent<CheckboxProps> {}
27+
28+
export default Checkbox;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { SvelteComponent } from './shared';
2+
3+
export interface RadioProps<T extends string | number | string[] = string[]> {
4+
/** Classes to add to radio wrapper. */
5+
class?: string;
6+
/** Color of the radio when active. */
7+
color?: string;
8+
/** Disables the radio. */
9+
disabled?: boolean;
10+
/** Bind radio to a group. */
11+
group?: T;
12+
/** Value of the radio. */
13+
value?: T;
14+
/** Id of the radio. */
15+
id?: string;
16+
/** Styles to add to radio wrapper. */
17+
style?: string;
18+
/** DOM reference to radio input element. */
19+
inputElement?: Element;
20+
}
21+
22+
declare class Radio extends SvelteComponent<RadioProps> {}
23+
24+
export default Radio;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { SvelteComponent } from './shared';
2+
3+
interface SelectProps<T extends number[] | string[] = string[]> {
4+
/** Classes to add to select wrapper. */
5+
class?: string;
6+
/** Whether select is opened. */
7+
active?: string;
8+
/** Value of the select. */
9+
value?: T;
10+
/** List of items to select from. */
11+
items?: { name: string | number, value: string | number }[];
12+
/** Whether select is the `filled` material design variant. */
13+
filled?: boolean;
14+
/** Whether select is the `outlined` material design variant. */
15+
outlined?: boolean;
16+
/** Whether select is outlined by elevation. */
17+
solo?: boolean;
18+
/** Whether select's height is reduced. */
19+
dense?: boolean;
20+
/** Placeholder content for select. */
21+
placeholder?: string;
22+
/** Hint text. */
23+
hint?: string;
24+
/** Whether at least one item must be selected. */
25+
mandatory?: boolean;
26+
/** Whether you can select multiple options. */
27+
multiple?: boolean;
28+
/** Maximum number of selectable options. Defaults to unlimited. */
29+
max?: number;
30+
/** Whether selected options appear as chips. */
31+
chips?: boolean;
32+
/** Whether select is disabled. */
33+
disabled?: boolean;
34+
/**
35+
* Whether select closes on selection. Defaults to `true` on single select and `false`
36+
* on multiple select.
37+
*/
38+
closeOnClick?: boolean;
39+
/** Convert the selected value for the underlying text field. */
40+
format?: (value: string | number | string[] | number[]) => string | number;
41+
}
42+
43+
declare class Select extends SvelteComponent<SelectProps> { }
44+
45+
export default Select;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { SvelteComponent } from './shared';
2+
3+
interface SliderProps {
4+
/** Minimum allowed value. */
5+
min?: number;
6+
/** Maximum allowed value. */
7+
max?: number;
8+
/** Value of the slider. */
9+
value?: number | number[];
10+
/** Display colored bars between handles. */
11+
connect?: boolean | boolean[] | 'lower' | 'upper' ;
12+
/** Color class of the slider when active. */
13+
color?: string;
14+
/** Slider jump interval. By default, the slider slides fluently. */
15+
step?: number;
16+
/** The minimum distance between the handles. Defaults to zero. */
17+
margin?: number;
18+
/** The maximum distance between two handles. Defaults to unlimited. */
19+
limit?: number;
20+
/** Limits how close to the slider edges handles can be. */
21+
padding?: number | [number] | [number, number];
22+
/**
23+
* Whether to display thumb tooltips. Can be set individually for each handle with an
24+
* array. Default formatter can be replaced by passing in a formatter function in place
25+
* of the boolean. Defaults to `false`.
26+
*/
27+
thumb?: boolean | ((value: number) => string) | (boolean | ((value: number) => string))[];
28+
/**
29+
* Whether handle tooltips are always visible. Defaults to `false` (Only active
30+
* handle's tooltip is visible.).
31+
*/
32+
persistentThumb?: boolean;
33+
/** Custom tooltip class. Defaults to `primary-color`. */
34+
thumbClass?: string;
35+
/**
36+
* Whether slider's orientation is vertical. Defaults to `false`.
37+
* Vertical sliders don't assume a default `height`, so a height needs to be set.
38+
*/
39+
vertical?: boolean;
40+
/** Whether to display the label at the end of the slider. */
41+
inverseLabel?: boolean;
42+
/** Whether slider is read-only. */
43+
readonly?: boolean;
44+
/** Whether slider is disabled. */
45+
disabled?: boolean;
46+
/** Hint text. */
47+
hint?: string;
48+
/** Styles to add to slider element. */
49+
style?: string;
50+
}
51+
52+
declare class Slider extends SvelteComponent<SliderProps> { }
53+
54+
export default Slider;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SvelteComponent } from './shared';
2+
3+
export interface SwitchProps {
4+
/** Classes to add to switch wrapper. */
5+
class?: string;
6+
/** Color class of the switch when active. */
7+
color?: string;
8+
/** Value of the switch. */
9+
value?: string | number;
10+
/** Bind switch to a group. */
11+
group?: string[] | number[];
12+
/** Whether the switch is on. */
13+
checked?: boolean;
14+
/** Whether switch thumb is inside the switch track. */
15+
inset?: boolean;
16+
/** Whether switch height is reduced. */
17+
dense?: boolean;
18+
/** Whether switch is disabled. */
19+
disabled?: boolean;
20+
/** Id of the switch. Defaults to a random uid. */
21+
id?: string;
22+
/** Styles to add to switch wrapper. */
23+
style?: string;
24+
/** Reference to switch input element in the DOM. */
25+
inputElement?: Element;
26+
}
27+
28+
declare class Switch extends SvelteComponent<SwitchProps> { }
29+
30+
export default Switch;

packages/svelte-materialify/@types/TextField.d.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
11
import { SvelteComponent } from './shared';
22

33
interface TextFieldProps {
4-
// Value of the text input.
4+
/** Classes to add to text field wrapper. */
5+
class?: string;
6+
/** Value of the text field. */
57
value?: string;
6-
// The color of the input when active.
8+
/** Color class of the text field when active. */
79
color?: string;
8-
// Changes the variant of the input to filled.
10+
/** Whether text field is the `filled` material design variant. */
911
filled?: boolean;
10-
// Changes the variant of the input to solo.
12+
/** Whether text field is outlined by elevation. */
1113
solo?: boolean;
12-
// Changes the variant of the input to outlined.
14+
/** Whether text field is the `outlined` material design variant. */
1315
outlined?: boolean;
14-
// Removes any shadow from the input.
16+
/** Whether text field do not have elevation. */
1517
flat?: boolean;
16-
// Reduces the input height.
18+
/** Whether text field height is reduced. */
1719
dense?: boolean;
18-
// Adds a border radius to the input.
20+
/** Whether text field has rounded corners. */
1921
rounded?: boolean;
20-
// Add input clear functionality.
22+
/** Whether text field has a clear button. */
2123
clearable?: boolean;
22-
// Puts input in readonly state.
24+
/** Whether text field is read-only. */
2325
readonly?: boolean;
24-
// Disable the input.
26+
/** Whether text field is disabled. */
2527
disabled?: boolean;
26-
// The input placeholder content.
28+
/** Placeholder content for text field. */
2729
placeholder?: string;
28-
// Hint text.
30+
/** Hint text. */
2931
hint?: string;
30-
// Creates counter for input length.
32+
/** Display a counter set to a desired input length. */
3133
counter?: number;
32-
// An array of functions which take input value as arguement and return error message.
33-
rules?: ((value) => string | true)[];
34-
// Delays validation till blur.
34+
/** Error messages to display. */
35+
messages?: string[];
36+
/**
37+
* A list of validator functions that take the textarea value and return an error
38+
* message, or `true` otherwise.
39+
*/
40+
rules?: ((value: string) => string | true)[];
41+
/** Number of error messages to display. Defaults to one. */
42+
errorCount?: number;
43+
/** Whether to delay validation until blur. */
3544
validateOnBlur?: boolean;
36-
// Error state of the input.
45+
/** Whether text field has error. */
3746
error?: boolean;
38-
// Id of the text input.
47+
/** Id of the text field. Defaults to a random uid. */
3948
id?: string;
49+
/** Styles to add to textarea wrapper. */
50+
style?: string;
51+
/** Reference to textarea element in the DOM. */
52+
inputElement?: Element;
4053
}
4154

4255
declare class TextField extends SvelteComponent<TextFieldProps> {}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { SvelteComponent } from './shared';
2+
3+
interface TextareaProps<T extends string | number | string[] = string[]> {
4+
/** Value of the textarea. */
5+
value?: T;
6+
/** Color class of the textarea when active. */
7+
color?: string;
8+
/** Whether textarea is the `filled` material design variant. */
9+
filled?: boolean;
10+
/** Whether textarea is outlined by elevation. */
11+
solo?: boolean;
12+
/** Whether textarea is the `outlined` material design variant. */
13+
outlined?: boolean;
14+
/** Whether textarea do not have elevation. */
15+
flat?: boolean;
16+
/** Whether textarea has rounded corners. */
17+
rounded?: boolean;
18+
/** Whether textarea has a clear button. */
19+
clearable?: boolean;
20+
/** Whether textarea is read-only. */
21+
readonly?: boolean;
22+
/** Number of initial textarea lines. Defaults to 5. */
23+
rows?: number;
24+
/** Whether textarea is allowed to grow with the text. */
25+
autogrow?: boolean;
26+
/** Whether textarea is not allowed to grow with the text. */
27+
noResize?: boolean;
28+
/** Whether textarea is disabled. */
29+
disabled?: boolean;
30+
/** Placeholder content for textarea. */
31+
placeholder?: string;
32+
/** Hint text. */
33+
hint?: string;
34+
/** Display a counter set to a desired input length. */
35+
counter?: number;
36+
/**
37+
* A list of validator functions that take the textarea value and return an error
38+
* message, or `true` otherwise.
39+
*/
40+
rules?: ((value: T) => string | true)[];
41+
/** Number of error messages to display. Defaults to one. */
42+
errorCount?: number;
43+
/** Error messages to display. */
44+
messages?: string[];
45+
/** Whether to delay validation until blur. */
46+
validateOnBlur?: boolean;
47+
/** Whether textarea has error. */
48+
error?: boolean;
49+
/** Whether textarea wrapper has `success` class. */
50+
success?: boolean;
51+
/** Id of the textarea. Defaults to a random uid. */
52+
id?: string;
53+
/** Styles to add to textarea wrapper. */
54+
style?: string;
55+
/** Reference to textarea element in the DOM. */
56+
textarea?: Element;
57+
}
58+
59+
declare class Textarea extends SvelteComponent<TextareaProps> { }
60+
61+
export default Textarea;
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
1-
export { default as Ripple } from './Ripple';
21
export { default as ClickOutside } from './ClickOutside';
32
export { default as Intersect } from './Intersect';
43
export { default as Jump } from './Jump';
4+
export { default as Ripple } from './Ripple';
55
export { default as Touch } from './Touch';
66

77
export { default as Alert } from './Alert';
8-
export { default as Avatar } from './Avatar';
98
export { default as AppBar } from './AppBar';
9+
export { default as Avatar } from './Avatar';
1010
export { default as Badge } from './Badge';
11-
export { default as Button } from './Button';
1211
export { default as Breadcrumbs } from './Breadcrumbs';
12+
export { default as Button } from './Button';
1313
export { default as Card } from './Card';
14-
export { default as CardTitle } from './CardTitle';
14+
export { default as CardActions } from './CardActions';
1515
export { default as CardSubtitle } from './CardSubtitle';
1616
export { default as CardText } from './CardText';
17-
export { default as CardActions } from './CardActions';
18-
export { default as Container } from './Container';
17+
export { default as CardTitle } from './CardTitle';
18+
export { default as Checkbox } from './Checkbox';
1919
export { default as Col } from './Col';
20+
export { default as Container } from './Container';
21+
export { default as Dialog } from './Dialog';
2022
export { default as Divider } from './Divider';
21-
export { default as ItemGroup } from './ItemGroup';
23+
export { default as ExpansionPanel } from './ExpansionPanel';
24+
export { default as ExpansionPanels } from './ExpansionPanels';
2225
export { default as Icon } from './Icon';
2326
export { default as Input } from './Input';
27+
export { default as ItemGroup } from './ItemGroup';
2428
export { default as List } from './List';
2529
export { default as ListGroup } from './ListGroup';
26-
export { default as ListItemGroup } from './ListItemGroup';
2730
export { default as ListItem } from './ListItem';
31+
export { default as ListItemGroup } from './ListItemGroup';
2832
export { default as MaterialApp } from './MaterialApp';
2933
export { default as Menu } from './Menu';
3034
export { default as NavigationDrawer } from './NavigationDrawer';
31-
export { default as Dialog } from './Dialog';
3235
export { default as Overlay } from './Overlay';
36+
export { default as ProgressCircular } from './ProgressCircular';
37+
export { default as ProgressLinear } from './ProgressLinear';
38+
export { default as Radio } from './Radio';
3339
export { default as Row } from './Row';
40+
export { default as Select } from './Select';
41+
export { default as Slider } from './Slider';
3442
export { default as Snackbar } from './Snackbar';
43+
export { default as Switch } from './Switch';
44+
export { default as Textarea } from './Textarea';
3545
export { default as TextField } from './TextField';
36-
export { default as ProgressLinear } from './ProgressLinear';
37-
export { default as ProgressCircular } from './ProgressCircular';
38-
export { default as ExpansionPanel } from './ExpansionPanel';
39-
export { default as ExpansionPanels } from './ExpansionPanels';
4046
export { default as Tooltip } from './Tooltip';

0 commit comments

Comments
 (0)