Skip to content

Commit 0c7e3fb

Browse files
committed
Enhancement: Support for numbers (int) in Snippets
Fixes #973
1 parent a6188b0 commit 0c7e3fb

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { XCircleIcon } from '@heroicons/react/24/solid';
2+
import * as React from 'react';
3+
4+
export interface INumberFieldProps {
5+
name: string;
6+
value?: string;
7+
placeholder?: string;
8+
description?: string;
9+
icon?: JSX.Element;
10+
disabled?: boolean;
11+
autoFocus?: boolean;
12+
onChange?: (value: string) => void;
13+
onReset?: () => void;
14+
}
15+
16+
export const NumberField: React.FunctionComponent<INumberFieldProps> = ({
17+
name,
18+
value,
19+
placeholder,
20+
description,
21+
icon,
22+
autoFocus,
23+
disabled,
24+
onChange,
25+
onReset
26+
}: React.PropsWithChildren<INumberFieldProps>) => {
27+
return (
28+
<>
29+
<div className="relative flex justify-center">
30+
{
31+
icon && (
32+
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
33+
{icon}
34+
</div>
35+
)
36+
}
37+
38+
<input
39+
type="number"
40+
name={name}
41+
className={`block w-full py-2 ${icon ? "pl-10" : "pl-2"} pr-2 sm:text-sm appearance-none disabled:opacity-50 rounded bg-[var(--vscode-input-background)] text-[var(--vscode-input-foreground)] placeholder-[var(--vscode-input-placeholderForeground)] border-[var(--frontmatter-border)] focus:border-[var(--vscode-focusBorder)] focus:outline-0`}
42+
style={{
43+
boxShadow: "none"
44+
}}
45+
placeholder={placeholder || ""}
46+
value={value}
47+
autoFocus={!!autoFocus}
48+
onChange={(e) => onChange && onChange(e.target.value)}
49+
disabled={!!disabled}
50+
/>
51+
52+
{(value && onReset) && (
53+
<button onClick={onReset} className="absolute inset-y-0 right-0 pr-3 flex items-center text-[var(--vscode-input-foreground)] hover:text-[var(--vscode-textLink-activeForeground)]">
54+
<XCircleIcon className={`h-5 w-5`} aria-hidden="true" />
55+
</button>
56+
)}
57+
</div>
58+
59+
{
60+
description && (
61+
<p className="text-xs text-[var(--vscode--settings-headerForeground)] opacity-75 mt-2 mx-2">
62+
{description}
63+
</p>
64+
)
65+
}
66+
</>
67+
);
68+
};

src/dashboardWebView/components/SnippetsView/SnippetInputField.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ChevronDownIcon } from '@heroicons/react/24/outline';
33
import { Choice, SnippetField, SnippetInfoField } from '../../../models';
44
import { useEffect } from 'react';
55
import { TextField } from '../Common/TextField';
6+
import { NumberField } from '../Common/NumberField';
67

78
export interface ISnippetInputFieldProps {
89
field: SnippetField;
@@ -78,6 +79,17 @@ export const SnippetInputField: React.FunctionComponent<ISnippetInputFieldProps>
7879
);
7980
}
8081

82+
if (field.type === 'number') {
83+
return (
84+
<NumberField
85+
name={field.name}
86+
value={field.value as string || ''}
87+
description={field.description}
88+
onChange={(e) => onValueChange(field, e)}
89+
/>
90+
);
91+
}
92+
8193
return (
8294
<TextField
8395
name={field.name}

src/dashboardWebView/components/SnippetsView/Snippets.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import { DEFAULT_DASHBOARD_FEATURE_FLAGS } from '../../../constants/DefaultFeatu
2121

2222
export interface ISnippetsProps { }
2323

24-
export const Snippets: React.FunctionComponent<ISnippetsProps> = (
25-
_: React.PropsWithChildren<ISnippetsProps>
26-
) => {
24+
export const Snippets: React.FunctionComponent<ISnippetsProps> = () => {
2725
const settings = useRecoilValue(SettingsSelector);
2826
const viewData = useRecoilValue(ViewDataSelector);
2927
const mode = useRecoilValue(ModeAtom);

0 commit comments

Comments
 (0)