Skip to content

Commit 75065f3

Browse files
authored
Merge pull request #3230 from github/koesie10/suggest-box
Create `SuggestBox` component
2 parents 2b6ec73 + 6ec727a commit 75065f3

File tree

8 files changed

+748
-21
lines changed

8 files changed

+748
-21
lines changed

extensions/ql-vscode/package-lock.json

Lines changed: 36 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@
19281928
"prepare": "cd ../.. && husky install"
19291929
},
19301930
"dependencies": {
1931+
"@floating-ui/react": "^0.26.5",
19311932
"@octokit/plugin-retry": "^6.0.1",
19321933
"@octokit/rest": "^20.0.2",
19331934
"@vscode/codicons": "^0.0.35",
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import type { Meta, StoryFn } from "@storybook/react";
2+
3+
import { styled } from "styled-components";
4+
5+
import { Codicon } from "../../view/common";
6+
import { SuggestBox as SuggestBoxComponent } from "../../view/common/SuggestBox/SuggestBox";
7+
import { useCallback, useState } from "react";
8+
9+
export default {
10+
title: "Suggest Box",
11+
component: SuggestBoxComponent,
12+
} as Meta<typeof SuggestBoxComponent>;
13+
14+
type StoryOption = {
15+
label: string;
16+
icon: string;
17+
details?: string;
18+
value: string;
19+
followup?: StoryOption[];
20+
};
21+
22+
const Template: StoryFn<typeof SuggestBoxComponent<StoryOption>> = (args) => {
23+
const [value, setValue] = useState("");
24+
25+
const handleChange = useCallback(
26+
(value: string) => {
27+
args.onChange(value);
28+
setValue(value);
29+
},
30+
[args],
31+
);
32+
33+
return (
34+
<SuggestBoxComponent<StoryOption>
35+
{...args}
36+
value={value}
37+
onChange={handleChange}
38+
/>
39+
);
40+
};
41+
42+
const Icon = styled(Codicon)`
43+
margin-right: 4px;
44+
color: var(--vscode-symbolIcon-fieldForeground);
45+
font-size: 16px;
46+
`;
47+
48+
const suggestedOptions: StoryOption[] = [
49+
{
50+
label: "Argument[self]",
51+
icon: "symbol-class",
52+
details: "sqlite3.SQLite3::Database",
53+
value: "Argument[self]",
54+
},
55+
{
56+
label: "Argument[0]",
57+
icon: "symbol-parameter",
58+
details: "name",
59+
value: "Argument[0]",
60+
followup: [
61+
{
62+
label: "Element[0]",
63+
icon: "symbol-field",
64+
value: "Argument[0].Element[0]",
65+
details: "first character",
66+
},
67+
{
68+
label: "Element[1]",
69+
icon: "symbol-field",
70+
value: "Argument[0].Element[1]",
71+
details: "second character",
72+
},
73+
{
74+
label: "Element[any]",
75+
icon: "symbol-field",
76+
value: "Argument[0].Element[any]",
77+
details: "any character",
78+
},
79+
],
80+
},
81+
{
82+
label: "Argument[1]",
83+
icon: "symbol-parameter",
84+
details: "arity",
85+
value: "Argument[1]",
86+
},
87+
{
88+
label: "Argument[text_rep:]",
89+
icon: "symbol-parameter",
90+
details: "text_rep:",
91+
value: "Argument[text_rep:]",
92+
},
93+
{
94+
label: "Argument[block]",
95+
icon: "symbol-parameter",
96+
details: "&block",
97+
value: "Argument[block]",
98+
followup: [
99+
{
100+
label: "Parameter[0]",
101+
icon: "symbol-parameter",
102+
value: "Argument[block].Parameter[0]",
103+
details: "val",
104+
followup: [
105+
{
106+
label: "Element[:query]",
107+
icon: "symbol-key",
108+
value: "Argument[block].Parameter[0].Element[:query]",
109+
},
110+
{
111+
label: "Element[:parameters]",
112+
icon: "symbol-key",
113+
value: "Argument[block].Parameter[0].Element[:parameters]",
114+
},
115+
],
116+
},
117+
{
118+
label: "Parameter[1]",
119+
icon: "symbol-parameter",
120+
value: "Argument[block].Parameter[1]",
121+
details: "context",
122+
followup: [
123+
{
124+
label: "Field[@query]",
125+
icon: "symbol-field",
126+
value: "Argument[block].Parameter[1].Field[@query]",
127+
},
128+
],
129+
},
130+
],
131+
},
132+
{
133+
label: "ReturnValue",
134+
icon: "symbol-variable",
135+
details: undefined,
136+
value: "ReturnValue",
137+
},
138+
];
139+
140+
export const AccessPath = Template.bind({});
141+
AccessPath.args = {
142+
options: suggestedOptions,
143+
parseValueToTokens: (value: string) => value.split("."),
144+
getIcon: (option: StoryOption) => <Icon name={option.icon} />,
145+
getDetails: (option: StoryOption) => option.details,
146+
};

0 commit comments

Comments
 (0)